import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
import '../../main.dart';

class MIHSuccessMessage extends StatefulWidget {
  final String successType;
  final String successMessage;
  const MIHSuccessMessage({
    super.key,
    required this.successType,
    required this.successMessage,
  });

  @override
  State<MIHSuccessMessage> createState() => _MIHSuccessMessageState();
}

class _MIHSuccessMessageState extends State<MIHSuccessMessage> {
  var messageTypes = <String, Widget>{};
  late String message;
  late double popUpWidth;
  late double? popUpheight;
  late double popUpTitleSize;
  late double popUpSubtitleSize;
  late double popUpBodySize;
  late double popUpIconSize;
  late double popUpPaddingSize;
  late Size? size;

  void checkScreenSize() {
    if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
      setState(() {
        popUpWidth = (size!.width / 4) * 2;
        popUpheight = null;
        popUpTitleSize = 25.0;
        popUpSubtitleSize = 20.0;
        popUpBodySize = 15;
        popUpPaddingSize = 25.0;
        popUpIconSize = 100;
      });
    } else {
      setState(() {
        popUpWidth = size!.width - (size!.width * 0.1);
        popUpheight = null;
        popUpTitleSize = 20.0;
        popUpSubtitleSize = 18.0;
        popUpBodySize = 15;
        popUpPaddingSize = 15.0;
        popUpIconSize = 100;
      });
    }
  }

  void setSuccessmessage() {
    messageTypes["Success"] = Stack(
      children: [
        Container(
          padding: EdgeInsets.all(popUpPaddingSize),
          width: popUpWidth,
          height: popUpheight,
          decoration: BoxDecoration(
            color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
            borderRadius: BorderRadius.circular(25.0),
            border: Border.all(
                color: MzanziInnovationHub.of(context)!.theme.successColor(),
                width: 5.0),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(
                Icons.check_circle_outline_rounded,
                size: popUpIconSize,
                color: MzanziInnovationHub.of(context)!.theme.successColor(),
              ),
              //const SizedBox(height: 15),
              Text(
                "Success!",
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: MzanziInnovationHub.of(context)!.theme.successColor(),
                  fontSize: popUpTitleSize,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 15),
              Center(
                child: Text(
                  message,
                  style: TextStyle(
                    color:
                        MzanziInnovationHub.of(context)!.theme.secondaryColor(),
                    fontSize: popUpBodySize,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              const SizedBox(height: 15),
              MihButton(
                onPressed: () {
                  Navigator.pop(context);
                },
                buttonColor:
                    MzanziInnovationHub.of(context)!.theme.successColor(),
                width: 300,
                child: Text(
                  "Dismiss",
                  style: TextStyle(
                    color:
                        MzanziInnovationHub.of(context)!.theme.primaryColor(),
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget? getSuccessMessage(String type) {
    return messageTypes[type];
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    size = MediaQuery.of(context).size;
    checkScreenSize();
    message = widget.successMessage;
    setSuccessmessage();
    return Dialog(child: getSuccessMessage(widget.successType));
  }
}
