/*
 * This file is part of Stack Wallet.
 *
 * Copyright (c) 2023 Cypher Stack
 * All Rights Reserved.
 * The code is distributed under GPLv3 license, see LICENSE file for details.
 * Generated by Cypher Stack on 2023-05-26
 *
 */

import 'package:flutter/material.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';

class FetchMonkeyDialog extends StatefulWidget {
  const FetchMonkeyDialog({
    Key? key,
    required this.onCancel,
  }) : super(key: key);

  final Future<void> Function() onCancel;

  @override
  State<FetchMonkeyDialog> createState() => _FetchMonkeyDialogState();
}

class _FetchMonkeyDialogState extends State<FetchMonkeyDialog> {
  late final Future<void> Function() onCancel;
  @override
  void initState() {
    onCancel = widget.onCancel;

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (Util.isDesktop) {
      return DesktopDialog(
        child: Column(
          children: [
            DesktopDialogCloseButton(
              onPressedOverride: () async {
                await onCancel.call();
                if (mounted) {
                  Navigator.of(context).pop();
                }
              },
            ),
            const Spacer(
              flex: 1,
            ),
            const RotatingArrows(
              width: 40,
              height: 40,
            ),
            const Spacer(
              flex: 2,
            ),
            Text(
              "Fetching MonKey",
              style: STextStyles.desktopH2(context),
              textAlign: TextAlign.center,
            ),
            const SizedBox(
              height: 16,
            ),
            Text(
              "We are fetching your MonKey",
              style: STextStyles.desktopTextMedium(context).copyWith(
                color: Theme.of(context).extension<StackColors>()!.textDark3,
              ),
              textAlign: TextAlign.center,
            ),
            const Spacer(
              flex: 2,
            ),
            Padding(
              padding: const EdgeInsets.only(
                left: 32,
                right: 32,
                bottom: 32,
              ),
              child: SecondaryButton(
                label: "Cancel",
                width: 272.5,
                onPressed: () async {
                  await onCancel.call();
                  if (mounted) {
                    Navigator.of(context).pop();
                  }
                },
              ),
            ),
          ],
        ),
      );
    } else {
      return WillPopScope(
        onWillPop: () async {
          return false;
        },
        child: StackDialog(
          title: "Fetching MonKey",
          message: "We are fetching your MonKey",
          icon: const RotatingArrows(
            width: 24,
            height: 24,
          ),
          rightButton: TextButton(
            style: Theme.of(context)
                .extension<StackColors>()!
                .getSecondaryEnabledButtonStyle(context),
            child: Text(
              "Cancel",
              style: STextStyles.itemSubtitle12(context),
            ),
            onPressed: () async {
              await onCancel.call();
              if (mounted) {
                Navigator.of(context).pop();
              }
            },
          ),
        ),
      );
    }
  }
}