import 'package:flutter/material.dart';
import 'package:sendtrain/database/database.dart';
import 'package:sendtrain/widgets/media/media_details.dart';

showMediaDetailWidget(BuildContext context, MediaItem media) {
  showEditorSheet(context, MediaDetails(media: media));
}

showGenericSheet(BuildContext context, Widget widget,
    [Color? backgroundColor]) {
  backgroundColor ??= Theme.of(context).colorScheme.surfaceBright;

  showModalBottomSheet<void>(
      backgroundColor: backgroundColor,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0)),
      ),
      context: context,
      showDragHandle: true,
      isScrollControlled: true,
      useSafeArea: true,
      builder: (BuildContext context) {
        return widget;
      });
}

showEditorSheet(BuildContext context, Widget widget) {
  showGenericSheet(context, widget);
}

String jsonToDescription(List text) {
  String content = '';

  for (int i = 0; i < text.length; i++) {
    if (content.isEmpty) {
      content = text[i];
    } else {
      content = "$content\n\n${text[i]}";
    }
  }

  return content;
}

Widget formItemWrapper(Widget content,
    [EdgeInsets padding = const EdgeInsets.fromLTRB(0, 0, 0, 0)]) {
  return Expanded(child: Padding(padding: padding, child: content));
}

List<DropdownMenuEntry> numericDropDownItems(String type, int itemLimit) {
  final List<DropdownMenuEntry> items = [];

  // String entryName = type;

  for (int i = 0; i < itemLimit; i++) {
    // if (i != 0) entryName = "${type}s";
    items.add(DropdownMenuEntry(value: i + 1, label: "${i + 1}"));
  }

  return items;
}
