import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:guru_ui/widget/alerts/dialog_label_alert_design_model.dart';

import 'dialog_buttons_alert_design_model.dart';
import 'dialog_standard_container.dart';

class DialogButtonsAlertSpaceConfig {
  final double? contentTextTopSpace;
  final double? buttonTopSpace;
  final double? buttonBottomSpace;
  DialogButtonsAlertSpaceConfig({
    this.contentTextTopSpace,
    this.buttonTopSpace,
    this.buttonBottomSpace,
  });
}

class DialogButtonsAlertWidget extends StatelessWidget {
  final Color? backgroundColor;
  final String contentText;
  final TextStyle? contentTextStyle;
  final Color? contentTextColor;
  final double? contentTextFontSize;
  final double? contentTextHeight;

  final String leftButtonText;
  final TextStyle? leftButtonTextStyle;
  final Color? leftButtonTextColor;
  final double? leftButtonTextFontSize;
  final Color? leftButtonBackgroundColor;
  final bool? leftButtonShowBorder;
  final Color? leftButtonBorderColor;
  final double? leftButtonBorderWidth;
  final VoidCallback? leftButtonCallBack;

  final String rightButtonText;
  final TextStyle? rightButtonTextStyle;
  final Color? rightButtonTextColor;
  final double? rightButtonTextFontSize;
  final Color? rightButtonBackgroundColor;
  final bool? rightButtonShowBorder;
  final Color? rightButtonBorderColor;
  final double? rightButtonBorderWidth;
  final VoidCallback? rightButtonCallBack;
  final DialogButtonsAlertSpaceConfig? spaceConfig;
  const DialogButtonsAlertWidget({
    Key? key,
    required this.contentText,
    required this.leftButtonText,
    required this.rightButtonText,
    this.backgroundColor = Colors.white,
    this.contentTextStyle,
    this.contentTextColor,
    this.contentTextFontSize,
    this.contentTextHeight,
    this.leftButtonTextStyle,
    this.leftButtonTextColor,
    this.leftButtonTextFontSize,
    this.leftButtonBackgroundColor,
    this.leftButtonShowBorder = true,
    this.leftButtonBorderColor,
    this.leftButtonCallBack,
    this.rightButtonTextStyle,
    this.rightButtonTextColor,
    this.rightButtonTextFontSize,
    this.rightButtonCallBack,
    this.rightButtonBackgroundColor,
    this.rightButtonShowBorder = false,
    this.rightButtonBorderColor,
    this.leftButtonBorderWidth,
    this.rightButtonBorderWidth,
    this.spaceConfig,
  }) : super(key: key);

  DialogButtonsAlertDesignSpec get designSpec => DialogButtonsAlertDesignSpec.get();
  DialogButtonsAlertContentDesignSpec get contentSpec => designSpec.contentSpec;

  @override
  Widget build(BuildContext context) {
    return DialogStandardContainer(
      backgroundColor: backgroundColor,
      showCloseImage: false,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: spaceConfig?.contentTextTopSpace != null
                ? EdgeInsets.only(
                    top: spaceConfig!.contentTextTopSpace!, left: contentSpec.contentInsets.left, right: contentSpec.contentInsets.right)
                : contentSpec.contentInsets,
            child: Text(
              contentText,
              style: contentTextStyle ??
                  TextStyle(
                      color: contentTextColor ?? const Color(0xff191b34),
                      fontSize: contentTextFontSize ?? contentSpec.contentFontSize,
                      fontWeight: FontWeight.w500,
                      height: contentTextHeight ?? 1.5),
              textAlign: TextAlign.center,
            ),
          ),
          SizedBox(height: spaceConfig?.buttonTopSpace ?? contentSpec.buttonTopSpace),
          SizedBox(
            height: contentSpec.buttonHeight,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  width: contentSpec.buttonLeftSpace,
                ),
                Expanded(
                    child: GestureDetector(
                  onTap: () {
                    leftButtonCallBack?.call();
                  },
                  child: Container(
                    height: contentSpec.buttonHeight,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: leftButtonBackgroundColor ?? Colors.white,
                        borderRadius: contentSpec.buttonRadius,
                        border: leftButtonShowBorder != null
                            ? leftButtonShowBorder!
                                ? Border.all(color: leftButtonBorderColor ?? const Color(0xff008B54), width: leftButtonBorderWidth ?? 1)
                                : null
                            : null),
                    child: AutoSizeText(
                      leftButtonText,
                      style: leftButtonTextStyle ??
                          TextStyle(
                              color: leftButtonTextColor ?? const Color(0xff008B54),
                              fontSize: leftButtonTextFontSize ?? contentSpec.buttonFontSize,
                              fontWeight: FontWeight.w600),
                      textAlign: TextAlign.center,
                    ),
                  ),
                )),
                SizedBox(
                  width: contentSpec.buttonSpace,
                ),
                Expanded(
                    child: GestureDetector(
                  onTap: () {
                    rightButtonCallBack?.call();
                  },
                  child: Container(
                    height: contentSpec.buttonHeight,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: rightButtonBackgroundColor ?? const Color(0xff008B54),
                        borderRadius: contentSpec.buttonRadius,
                        border: rightButtonShowBorder != null
                            ? rightButtonShowBorder!
                                ? Border.all(color: rightButtonBorderColor ?? Colors.white, width: rightButtonBorderWidth ?? 1)
                                : null
                            : null),
                    child: AutoSizeText(
                      rightButtonText,
                      style: rightButtonTextStyle ??
                          TextStyle(
                              color: rightButtonTextColor ?? Colors.white,
                              fontSize: rightButtonTextFontSize ?? contentSpec.buttonFontSize,
                              fontWeight: FontWeight.w600),
                      textAlign: TextAlign.center,
                    ),
                  ),
                )),
                SizedBox(
                  width: contentSpec.buttonRightSpace,
                ),
              ],
            ),
          ),
          SizedBox(height: contentSpec.buttonBottomSpace)
        ],
      ),
    );
  }
}
