import 'package:flutter/material.dart';
import 'dialog_image_single_button_alert_design_model.dart';
import 'dialog_standard_container.dart';

class DialogImageSingleButtonAlertSpaceConfig {
  final double? mainTitleTopSpace;
  final double? subTitleTopSpace;
  final double? imageTopSpace;
  final double? descriptionTopSpace;
  final double? buttonTopSpace;
  final double? buttonBottomSpace;
  DialogImageSingleButtonAlertSpaceConfig({
    this.mainTitleTopSpace,
    this.subTitleTopSpace,
    this.imageTopSpace,
    this.descriptionTopSpace,
    this.buttonTopSpace,
    this.buttonBottomSpace,
  });
}

class DialogImageSingleButtonAlertWidget extends StatelessWidget {
  final Color? backgroundColor;
  final String mainTitle;
  final TextStyle? mainTitleTextStyle;
  final Color? mainTitleColor;
  final double? mainTitleFontSize;

  final String subTitle;
  final TextStyle? subTitleTextStyle;
  final Color? subTitleColor;
  final double? subTitleFontSize;

  final Image image;
  final String descriptionText;
  final TextStyle? descriptionTextStyle;
  final Color? descriptionColor;
  final double? descriptionFontSize;
  final double? descriptionTextHeight;

  final Color? buttonBackgroundColor;
  final Image? buttonImage;
  final String buttonText;
  final TextStyle? buttonTextStyle;
  final Color? buttonTextColor;
  final double? buttonFontSize;
  final VoidCallback? buttonCallback;

  final Image? closeImage;
  final VoidCallback? closeCallback;
  final DialogImageSingleButtonAlertSpaceConfig? spaceConfig;
  const DialogImageSingleButtonAlertWidget({
    Key? key,
    required this.mainTitle,
    this.mainTitleTextStyle,
    this.mainTitleColor,
    this.mainTitleFontSize,
    required this.subTitle,
    this.subTitleTextStyle,
    this.subTitleFontSize,
    this.subTitleColor,
    required this.image,
    required this.descriptionText,
    this.descriptionTextStyle,
    this.descriptionColor,
    this.descriptionFontSize,
    this.descriptionTextHeight,
    this.buttonBackgroundColor,
    this.buttonImage,
    required this.buttonText,
    this.buttonTextStyle,
    this.buttonFontSize,
    this.buttonTextColor,
    this.backgroundColor,
    this.buttonCallback,
    this.closeImage,
    this.closeCallback,
    this.spaceConfig,
  }) : super(key: key);

  DialogImageSingleButtonAlertDesignSpec get designSpec => DialogImageSingleButtonAlertDesignSpec.get();
  DialogImageSingleButtonAlertContentDesignSpec get contentSpec => designSpec.contentSpec;

  @override
  Widget build(BuildContext context) {
    return DialogStandardContainer(
      backgroundColor: backgroundColor,
      showCloseImage: true,
      closeCallback: closeCallback,
      closeImage: closeImage,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: spaceConfig?.mainTitleTopSpace != null
                ? EdgeInsets.only(
                    top: spaceConfig!.mainTitleTopSpace!, left: contentSpec.mainTitleInsets.left, right: contentSpec.mainTitleInsets.right)
                : contentSpec.mainTitleInsets,
            child: Text(
              mainTitle,
              style: mainTitleTextStyle ??
                  TextStyle(
                      fontSize: mainTitleFontSize ?? contentSpec.mainTitleFontSize,
                      color: mainTitleColor ?? const Color(0xff000000),
                      fontWeight: FontWeight.w700),
            ),
          ),
          Padding(
            padding: spaceConfig?.subTitleTopSpace != null
                ? EdgeInsets.only(top: spaceConfig!.subTitleTopSpace!, left: contentSpec.subTitleInsets.left, right: contentSpec.subTitleInsets.right)
                : contentSpec.subTitleInsets,
            child: Text(
              subTitle,
              style: subTitleTextStyle ??
                  TextStyle(
                      fontSize: subTitleFontSize ?? contentSpec.subTitleFontSize,
                      color: subTitleColor ?? const Color(0xff6c6d71),
                      fontWeight: FontWeight.w500),
            ),
          ),
          Padding(
            padding: spaceConfig?.imageTopSpace != null
                ? EdgeInsets.only(
                    top: spaceConfig!.imageTopSpace!, left: contentSpec.contentImageInsets.left, right: contentSpec.contentImageInsets.right)
                : contentSpec.contentImageInsets,
            child:
                Container(height: contentSpec.imageContainerHeight, decoration: BoxDecoration(border: Border.all(color: Colors.red)), child: image),
          ),
          Padding(
            padding: spaceConfig?.descriptionTopSpace != null
                ? EdgeInsets.only(
                    top: spaceConfig!.descriptionTopSpace!,
                    left: contentSpec.descriptionTextInsets.left,
                    right: contentSpec.descriptionTextInsets.right)
                : contentSpec.descriptionTextInsets,
            child: Text(
              descriptionText,
              style: descriptionTextStyle ??
                  TextStyle(
                    fontSize: descriptionFontSize ?? contentSpec.descriptionTextFontSize,
                    color: descriptionColor ?? const Color(0xff000000),
                    fontWeight: FontWeight.w500,
                    height: descriptionTextHeight ?? 1.43,
                  ),
              textAlign: TextAlign.center,
            ),
          ),
          Padding(
            padding: EdgeInsets.only(
                top: spaceConfig?.buttonTopSpace ?? contentSpec.buttonTopSpace,
                bottom: spaceConfig?.buttonBottomSpace ?? contentSpec.buttonBottomSpace),
            child: GestureDetector(
              onTap: () {
                buttonCallback?.call();
              },
              child: Container(
                  width: contentSpec.buttonWidth,
                  height: contentSpec.buttonHeight,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(color: buttonBackgroundColor ?? const Color(0xff008B54), borderRadius: contentSpec.buttonRadius),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox.fromSize(
                        size: contentSpec.buttonImageSize,
                        child: buttonImage ??
                            const Image(
                              image: AssetImage("assets/icons/ic_ad.png", package: "guru_ui"),
                            ),
                      ),
                      SizedBox(
                        width: contentSpec.buttonImageRightSpace,
                      ),
                      Text(
                        buttonText,
                        style: buttonTextStyle ??
                            TextStyle(
                                fontSize: buttonFontSize ?? contentSpec.buttonFontSize,
                                color: buttonTextColor ?? Colors.white,
                                fontWeight: FontWeight.w600),
                        textAlign: TextAlign.center,
                      )
                    ],
                  )),
            ),
          ),
        ],
      ),
    );
  }
}
