import 'package:flutter/material.dart';
import 'package:marco/helpers/widgets/my_spacing.dart';
import 'package:marco/helpers/widgets/my_text.dart';

class BaseBottomSheet extends StatelessWidget {
  final String title;
  final Widget child;
  final VoidCallback onCancel;
  final VoidCallback onSubmit;
  final bool isSubmitting;
  final String submitText;
  final Color submitColor;
  final IconData submitIcon;
  final bool showButtons;
  final Widget? bottomContent;

  const BaseBottomSheet({
    super.key,
    required this.title,
    required this.child,
    required this.onCancel,
    required this.onSubmit,
    this.isSubmitting = false,
    this.submitText = 'Submit',
    this.submitColor = Colors.indigo,
    this.submitIcon = Icons.check_circle_outline,
    this.showButtons = true,
    this.bottomContent,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final mediaQuery = MediaQuery.of(context);

    return SingleChildScrollView(
      padding: mediaQuery.viewInsets,
      child: Padding(
        padding: const EdgeInsets.only(top: 60),
        child: Container(
          decoration: BoxDecoration(
            color: theme.cardColor,
            borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
            boxShadow: const [
              BoxShadow(
                color: Colors.black12,
                blurRadius: 12,
                offset: Offset(0, -2),
              ),
            ],
          ),
          child: Padding(
            padding: const EdgeInsets.fromLTRB(20, 16, 20, 32),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                MySpacing.height(5),
                Container(
                  width: 40,
                  height: 5,
                  decoration: BoxDecoration(
                    color: Colors.grey.shade300,
                    borderRadius: BorderRadius.circular(10),
                  ),
                ),
                MySpacing.height(12),
                MyText.titleLarge(title, fontWeight: 700),
                MySpacing.height(12),
                child,

                MySpacing.height(12),

                // 👇 Buttons (if enabled)
                if (showButtons) ...[
                  Row(
                    children: [
                      Expanded(
                        child: ElevatedButton.icon(
                          onPressed: onCancel,
                          icon: const Icon(Icons.close, color: Colors.white),
                          label: MyText.bodyMedium(
                            "Cancel",
                            color: Colors.white,
                            fontWeight: 600,
                          ),
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.grey,
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(12),
                            ),
                            padding: const EdgeInsets.symmetric(vertical: 8),
                          ),
                        ),
                      ),
                      const SizedBox(width: 12),
                      Expanded(
                        child: ElevatedButton.icon(
                          onPressed: isSubmitting ? null : onSubmit,
                          icon: Icon(submitIcon, color: Colors.white),
                          label: MyText.bodyMedium(
                            isSubmitting ? "Submitting..." : submitText,
                            color: Colors.white,
                            fontWeight: 600,
                          ),
                          style: ElevatedButton.styleFrom(
                            backgroundColor: submitColor,
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(12),
                            ),
                            padding: const EdgeInsets.symmetric(vertical: 8),
                          ),
                        ),
                      ),
                    ],
                  ),
                  // 👇 Optional Bottom Content
                  if (bottomContent != null) ...[
                    MySpacing.height(12),
                    bottomContent!,
                  ],
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}
