import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';

void showCommonBottomSheet(BuildContext context,
    {required Widget child, required VoidCallback callBackFunc, String? title, required double height, bool isCloseButtonVisible = true, bool isFullScreen = true, bool isDismissible = true}) {
  showModalBottomSheet<String>(
      sheetAnimationStyle: AnimationStyle(
        duration: Duration(milliseconds: 500), // Custom animation duration
        reverseDuration: Duration(milliseconds: 300), // Custom reverse animation duration
      ),
      context: context,
      isScrollControlled: true,
      showDragHandle: false,
      isDismissible: isDismissible,
      backgroundColor: AppColors.scaffoldBgColor,
      builder: (BuildContext context) {
        return Container(
          height: height,
          decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.scaffoldBgColor, borderRadius: 24.h),
          child: ButtonSheetContent(
            title: title!,
            isCloseButtonVisible: isCloseButtonVisible,
            isFullScreen: isFullScreen,
            child: child,
          ),
        );
      }).then((value) {
    callBackFunc();
  });
}

class ButtonSheetContent extends StatelessWidget {
  final Widget child;
  final String title;
  final bool isCloseButtonVisible;
  final bool isFullScreen;

  const ButtonSheetContent({super.key, required this.child, required this.isCloseButtonVisible, required this.title, required this.isFullScreen});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // SizedBox(
        //   height: 20.h,
        // ),
        // Center(
        //   child: Container(
        //     margin: const EdgeInsets.only(top: 18, bottom: 12),
        //     height: 4,
        //     width: 40.h,
        //     decoration: BoxDecoration(
        //       color: Colors.grey[400],
        //       borderRadius: BorderRadius.circular(2),
        //     ),
        //   ),
        // ),

        // Close button
        isCloseButtonVisible && isFullScreen
            ? Padding(
                padding: EdgeInsets.symmetric(horizontal: 16),
                child: Utils.buildSvgWithAssets(icon: AppAssets.closeBottomNav, width: 32, height: 32).onPress(() {
                  Navigator.of(context).pop();
                }),
              )
            : SizedBox(),

        isFullScreen
            ? Column(
                children: [
                  SizedBox(height: 20.h),
                  Padding(padding: EdgeInsets.symmetric(horizontal: 16.h), child: title.toText24(isBold: true)),
                  SizedBox(height: 16.h),
                ],
              )
            : SizedBox(),

        Expanded(child: child)
      ],
    );
  }
}
