import 'package:flutter/material.dart';

import '../../../../extensions/date_time.dart';
import '../../../../state/app/modules/marianum_dates/bloc/marianum_dates_state.dart';
import '../../../../widget/animated_time.dart';
import '../../../../widget/centered_leading.dart';
import '../../../../widget/debug/debug_tile.dart';
import '../../../../widget/details_bottom_sheet.dart';
import '../data/event_formatter.dart';

void showEventDetailsSheet(BuildContext context, MarianumDate event) {
  final isUpcoming = !event.start.difference(DateTime.now()).isNegative;
  showDetailsBottomSheet(
    context,
    header: ListTile(
      leading: const Icon(Icons.event_outlined, size: 32),
      title: Text(
        event.title.isEmpty ? '(ohne Titel)' : event.title,
        style: const TextStyle(fontWeight: FontWeight.bold),
      ),
    ),
    children: (sheetContext) => [
      ListTile(
        leading: const CenteredLeading(Icon(Icons.date_range_outlined)),
        title: Text(EventFormatter.longRange(event)),
      ),
      if (event.description != null && event.description!.trim().isNotEmpty)
        ListTile(
          leading: const CenteredLeading(Icon(Icons.notes_outlined)),
          title: Text(event.description!.trim()),
        ),
      if (isUpcoming)
        ListTile(
          leading: const CenteredLeading(Icon(Icons.timer_outlined)),
          title: AnimatedTime(
            callback: () => event.start.difference(DateTime.now()),
          ),
          subtitle: Text(event.start.formatRelative()),
        )
      else
        ListTile(
          leading: const CenteredLeading(
            Icon(Icons.content_paste_search_outlined),
          ),
          title: Text(event.start.formatRelative()),
        ),
      DebugTile(sheetContext).jsonData(event.toJson()),
    ],
  );
}
