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

class DialogInternetErrorAlertSpaceConfig {
  final double? titleTopSpace;
  final double? imageTopSpace;
  final double? messageTopSpace;
  final double? buttonTopSpace;
  final double? buttonBottomSpace;
  DialogInternetErrorAlertSpaceConfig({
    this.titleTopSpace,
    this.imageTopSpace,
    this.messageTopSpace,
    this.buttonTopSpace,
    this.buttonBottomSpace,
  });
}

class DialogInternetErrorPictureAlertWidget extends StatelessWidget {
  final Color? backgroundColor;
  final VoidCallback? closeCallback;
  final Image? closeImage;
  final String title;
  final TextStyle? titleStyle;
  final Color? titleTextColor;
  final double? titleFontSize;
  final Image? image;
  final String messageText;
  final TextStyle? messageStyle;
  final Color? messageTextColor;
  final double? messageFontSize;

  final String buttonText;
  final TextStyle? buttonTextStyle;
  final Color? buttonTextColor;
  final double? buttonFontSize;

  final Color? buttonBackgroundColor;
  final VoidCallback? buttonCallback;
  final DialogInternetErrorAlertSpaceConfig? spaceConfig;
  const DialogInternetErrorPictureAlertWidget({
    Key? key,
    this.backgroundColor,
    required this.title,
    this.titleStyle,
    this.titleFontSize,
    this.titleTextColor,
    this.image,
    required this.messageText,
    this.messageStyle,
    this.messageFontSize,
    this.messageTextColor,
    required this.buttonText,
    this.buttonTextStyle,
    this.buttonTextColor,
    this.buttonFontSize,
    this.buttonBackgroundColor,
    this.buttonCallback,
    this.closeCallback,
    this.closeImage,
    this.spaceConfig,
  }) : super(key: key);

  DialogInternetErrorAlertDesignSpec get designSpec => DialogInternetErrorAlertDesignSpec.get();
  DialogInternetErrorAlertContentDesignSpec get contentSpec => designSpec.contentSpec;
  @override
  Widget build(BuildContext context) {
    return DialogStandardContainer(
        backgroundColor: backgroundColor,
        showCloseImage: false,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              height: spaceConfig?.titleTopSpace ?? contentSpec.titleTopSpace,
            ),
            Text(
              title,
              style: titleStyle ??
                  TextStyle(
                      fontSize: titleFontSize ?? contentSpec.titleFontSize,
                      color: titleTextColor ?? const Color(0xff191b34),
                      fontWeight: FontWeight.w700),
              textAlign: TextAlign.center,
            ),
            Padding(
              padding: spaceConfig?.imageTopSpace != null
                  ? EdgeInsets.only(top: spaceConfig!.imageTopSpace!, left: contentSpec.imageInsets.left, right: contentSpec.imageInsets.right)
                  : contentSpec.imageInsets,
              child: Container(
                  decoration: BoxDecoration(border: Border.all(color: Colors.red)),
                  child: image ?? const Image(image: AssetImage("assets/icons/ic_wifi.png", package: "guru_ui"))),
            ),
            Padding(
              padding: spaceConfig?.messageTopSpace != null
                  ? EdgeInsets.only(top: spaceConfig!.messageTopSpace!, left: contentSpec.messageInsets.left, right: contentSpec.messageInsets.right)
                  : contentSpec.messageInsets,
              child: Text(
                messageText,
                style: messageStyle ??
                    TextStyle(
                        fontSize: messageFontSize ?? contentSpec.messageFontSize,
                        color: messageTextColor ?? const Color(0xff000000),
                        fontWeight: FontWeight.w500),
                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: Text(
                      buttonText,
                      style: buttonTextStyle ??
                          TextStyle(
                              fontSize: buttonFontSize ?? contentSpec.buttonFontSize,
                              color: buttonTextColor ?? Colors.white,
                              fontWeight: FontWeight.w600),
                      textAlign: TextAlign.center,
                    )),
              ),
            )
          ],
        ));
  }
}
