import 'dart:ffi';

import 'package:flutter/material.dart';

import 'dialog_error_picture_alert_design_model.dart';
import 'dialog_standard_container.dart';

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

class DialogErrorPictureAlertWidget extends StatelessWidget {
  final Color? backgroundColor;
  final VoidCallback? closeCallback;
  final Image? closeImage;
  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 DialogErrorPictureAlertSpaceConfig? spaceConfig;
  const DialogErrorPictureAlertWidget({
    Key? key,
    this.backgroundColor,
    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);

  DialogErrorPictureAlertDesignSpec get designSpec => DialogErrorPictureAlertDesignSpec.get();
  DialogErrorPictureAlertContentDesignSpec get contentSpec => designSpec.contentSpec;
  @override
  Widget build(BuildContext context) {
    return DialogStandardContainer(
        backgroundColor: backgroundColor,
        showCloseImage: true,
        closeCallback: closeCallback,
        closeImage: closeImage,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Padding(
              padding: spaceConfig?.imageTopSpace != null
                  ? EdgeInsets.only(top: spaceConfig!.imageTopSpace!, left: contentSpec.imageInsets.left, right: contentSpec.imageInsets.right)
                  : contentSpec.imageInsets,
              child: Container(
                height: contentSpec.imageContainerHeight,
                decoration: BoxDecoration(border: Border.all(color: Colors.red)),
                child: image ?? const Image(image: AssetImage("assets/icons/ic_error.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,
                    )),
              ),
            )
          ],
        ));
  }
}
