import 'dart:math';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:guru_ui/widget/alerts/dialog_buttons_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_error_picture_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_how_to_play_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_image_double_button_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_image_single_button_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_label_alert_widget.dart';
import 'package:guru_ui/widget/alerts/dialog_single_input_alert_widget.dart';
import 'package:guru_ui/widget/dialog/dialog_core.dart';

class TestAlertList {
  static Widget alert() => Center(
          child: Container(
        width: 300,
        height: 300,
        color: Color.fromRGBO(Random().nextInt(256), Random().nextInt(256), Random().nextInt(256), 1),
      ));
  static Widget howToPlayAlert() => DialogHowToPlayAlertWidget(contentList: [
        DialogHowToPlayContent(
            image: Image.network("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"),
            contentText: "1Win Challenges to earn Crowns!\nComplete a challenge within 24 hours to earn a Jeweled Crown!"),
        DialogHowToPlayContent(
            image: Image.network("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"),
            contentText: "2Win Challenges to earn Crowns!\nComplete a challenge within 24 hours to earn a Jeweled Crown!")
      ], buttonText: "Next",lastButtonText: "Play", titleText: 'How does it work?',);
  static Widget imageDoubleButtonAlert() => DialogImageDoubleButtonAlertWidget(
        mainTitle: "Main Title",
        subTitle: "This is subTitle",
        image: Image.network("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"),
        descriptionText: "This is a short text, because it is shorter, so it will be displayed centered.",
        upButtonText: "Button",
        upButtonImage: Image.network(
            "https://img-qn-3.51miz.com/Element/00/77/94/10/3f50cada_E779410_a8dd2973.png!/quality/90/unsharp/true/compress/true/format/png/fh/320"),
        downButtonText: 'Secondary Button',
      );

  static Widget imageSingleButtonAlert() => DialogImageSingleButtonAlertWidget(
      mainTitle: "Main Title",
      subTitle: "This is subTitle",
      image: Image.network("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"),
      descriptionText: "This is a short text, because it is shorter, so it will be displayed centered.",
      buttonText: "Button",
      buttonImage: Image.network(
          "https://img-qn-3.51miz.com/Element/00/77/94/10/3f50cada_E779410_a8dd2973.png!/quality/90/unsharp/true/compress/true/format/png/fh/320"));
  static Widget errorPictureAlert() => DialogErrorPictureAlertWidget(
        image: Image.network("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"),
        buttonText: "Contact Support",
        messageText: "having problems purchasing?",
        closeCallback: () {
          Get.back();
        },
      );
  static Widget labelAlert() => DialogLabelAlertWidget(
        contentText: "A message should be a short, complete sentence." * 3,
        cancelText: "cancel",
        ackText: "sure",
        cancelCallBack: () {
          Get.back();
        },
      );
  static Widget singleInputAlert() => DialogSingleInputAlertWidget(
        titleText: "Promo Code",
        buttonText: "Next",
        buttonCallback: (value) {
          print(value);
          // Get.back();
        },
      );
  static Widget buttonsAlert() => DialogButtonsAlertWidget(
      contentText: "A message should be a short, complete sentence." * 2, leftButtonText: "Default", rightButtonText: "Primary");
  static List<Widget> list = [
    howToPlayAlert(),
    imageDoubleButtonAlert(),
    imageSingleButtonAlert(),
    errorPictureAlert(),
    singleInputAlert(),
    labelAlert(),
    buttonsAlert(),
    alert()
  ];
}

class TestConfig {
  static Map<String, List<Widget>> categoryList = {"alert": TestAlertList.list};
}

class GuruUITestPage extends StatefulWidget {
  const GuruUITestPage({Key? key}) : super(key: key);

  @override
  _GuruUITestPageState createState() => _GuruUITestPageState();
}

class _GuruUITestPageState extends State<GuruUITestPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView.separated(
          itemCount: TestConfig.categoryList.length,
          separatorBuilder: (context, index) {
            return Container(
              padding: const EdgeInsets.symmetric(horizontal: 10),
              color: Colors.grey,
              height: 0.5,
            );
          },
          itemBuilder: (context, index) {
            return InkWell(
              onTap: () {
                _showGeneralDialog(context, TestConfig.categoryList.values.toList()[index]);
                // _showDialog(context);
              },
              child: Container(
                height: 50,
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: Row(
                  children: [
                    Text(
                      TestConfig.categoryList.keys.toList()[index],
                      style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
                    ),
                    Expanded(child: Container()),
                    const Icon(Icons.arrow_forward_ios_sharp)
                  ],
                ),
              ),
            );
          }),
    );
  }
}

Future _showGeneralDialog(BuildContext context, List<Widget> list) {
  return DialogCore.showDialog(
      barrierColor: Colors.black.withOpacity(0.8),
      barrierDismissible: true,
      widget: GestureDetector(
        onTap: () {
          Get.back();
        },
        child: PageView(
          scrollDirection: Axis.vertical,
          children: list,
        ),
      ));
}

Future _showRawGeneralDialog(BuildContext context, List<Widget> list) {
  return showGeneralDialog(
      barrierColor: Colors.black.withOpacity(0.8),
      barrierDismissible: true,
      barrierLabel: "",
      context: context,
      pageBuilder: (context, animation, secondaryAnimation) {
        return PageView(
          scrollDirection: Axis.vertical,
          children: list,
        );
      });
}

Future _showDialog(BuildContext context) {
  return showDialog(
      context: context,
      useSafeArea: false,
      builder: (context) {
        return Dialog(
          backgroundColor: Colors.black45,
          child: TestAlertList.labelAlert(),
          insetPadding: EdgeInsets.zero,
        );
      });
}
