import 'package:flutter/material.dart';

/// Shows a modal bottom sheet for a detail view (appointment, file, lesson,
/// custom event, etc.). All detail sheets in the app share this layout: drag
/// handle on top, default theme background, optional ListTile-style header
/// followed by a divider, scrollable body below.
Future<void> showDetailsBottomSheet(
  BuildContext context, {
  Widget? header,
  required List<Widget> Function(BuildContext sheetContext) children,
}) {
  return showModalBottomSheet<void>(
    context: context,
    isScrollControlled: true,
    showDragHandle: true,
    useSafeArea: true,
    builder: (sheetContext) => SafeArea(
      child: SingleChildScrollView(
        // Sheets können TextFields enthalten (z.B. Endpoint-Picker); ohne den
        // viewInsets-Offset schiebt sich das Eingabefeld bei aktiver Tastatur
        // unter die Tastatur statt darüber zu bleiben.
        padding: EdgeInsets.only(
          bottom: 16 + MediaQuery.viewInsetsOf(sheetContext).bottom,
        ),
        // Ohne dieses innere Material malt ListTile-Ink aufs Sheet-Material
        // außerhalb des Scrollbereichs und stretcht beim Overscroll nicht mit.
        child: Material(
          type: MaterialType.transparency,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              if (header != null) ...[header, const Divider(height: 1)],
              ...children(sheetContext),
            ],
          ),
        ),
      ),
    ),
  );
}
