
import 'package:flutter/material.dart';
import 'package:cs_resources/generated/l10n.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/no_shadow_scroll_behavior.dart';
import 'package:widgets/widget_export.dart';

class BottomDialog extends StatelessWidget {
  String? title;
  String? message;
  Widget? Function(BuildContext)? messageBuilder;
  VoidCallback confirmAction;
  VoidCallback? cancelAction;
  bool isShowCancelBtn;
  String? confirmTxt;
  String? cancelTxt;
  final double? minHeight;
  final double? maxHeight;

  BottomDialog({
    this.title,
    this.message,
    Widget Function(BuildContext)? this.messageBuilder,
    required this.confirmAction,
    this.cancelAction,
    this.isShowCancelBtn = true,
    this.confirmTxt,
    this.cancelTxt,
    minHeight,
    maxHeight,
    Key? key,
  }): minHeight = minHeight?? 0,
      maxHeight = maxHeight?? 300,
        super(key:key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(top: 30),
      constraints: BoxConstraints(
        minHeight: minHeight!,
        maxHeight: maxHeight!,
      ),
      decoration: BoxDecoration(
        color: context.appColors.whiteSecondBG,
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(0),
          topRight: Radius.circular(0),
        ),
      ),
      child: Column(
        children: [
          Scrollbar(
            child: ScrollConfiguration(
              behavior: NoShadowScrollBehavior(),
              child: SingleChildScrollView(
                child: messageBuilder?.call(context) ??
                  MyTextView(
                    message!,
                    fontSize: 18,
                    textColor: context.appColors.textBlack,
                    isFontRegular: true,
                    textAlign: TextAlign.center,
                    paddingLeft: 30,
                    paddingRight: 30,
                  ),
              ),
            ),
          ).constrained(maxHeight: maxHeight! - 60),
          Row(
            children: [
              const SizedBox(width: 18),
              Visibility(
                visible: isShowCancelBtn,
                child: Expanded(
                    flex: 1,
                    child: InkWell(
                      onTap: () {
                        onCancel();
                        cancelAction?.call();
                      },
                      child: MyTextView(
                        cancelTxt ?? S.current.no,
                        fontSize: 16,
                        isFontMedium: true,
                        paddingTop: 13,
                        marginRight: 15,
                        paddingBottom: 13,
                        textAlign: TextAlign.center,
                        textColor: Colors.white,
                        backgroundColor: context.appColors.orangeBG,
                        cornerRadius: 7,
                      ),
                    )),
              ),
              Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () async {
                      onCancel();
                      confirmAction();
                    },
                    child: MyTextView(
                      confirmTxt ?? S.current.yes,
                      fontSize: 16,
                      paddingTop: 13,
                      paddingBottom: 13,
                      isFontMedium: true,
                      textAlign: TextAlign.center,
                      textColor: Colors.white,
                      backgroundColor: context.appColors.btnBgDefault,
                      cornerRadius: 7,
                    ),
                  )),
              const SizedBox(width: 18),
            ],
          ).marginOnly(bottom: 30, top: 28),
        ],
      ),
    );
  }

  //取消弹框
  void onCancel() async {
    SmartDialog.dismiss();
  }
}
