import 'package:flutter/material.dart';
import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart';
import 'package:hub/flutter_flow/nav/nav.dart';
import 'package:hub/shared/extensions/dialog_extensions.dart';
import 'package:hub/shared/services/authentication/authentication_service.dart';
import 'package:hub/shared/utils/storage_util.dart';

import '../../../shared/services/localization/localization_service.dart';
import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart';
import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart';
import '/flutter_flow/flutter_flow_util.dart';
import 'menu_component_widget.dart' show MenuComponentWidget;

class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {

  bool isGrid = false;

  late MenuListViewComponentModel menuListViewComponentModel;
  late MenuStaggeredViewComponentModel menuStaggeredViewComponentModel;

  @override void initState(BuildContext context) {
    menuListViewComponentModel =
        createModel(context, () => MenuListViewComponentModel());
    menuStaggeredViewComponentModel =
        createModel(context, () => MenuStaggeredViewComponentModel());
  }
  @override void dispose() {
    menuListViewComponentModel.dispose();
    menuStaggeredViewComponentModel.dispose();
  }

  Future changeMenuStyle(BuildContext context) async {
    isGrid = !isGrid;
  }
  Future openQRCodeScanner(BuildContext context) async {
        context.push(
          '/qrCodePage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openCompleteSchedule(BuildContext context) async {
    context.push(
      '/scheduleCompleteVisitPage',
      extra: <String, dynamic>{
        kTransitionInfoKey: const TransitionInfo(
          hasTransition: true,
          transitionType: PageTransitionType.scale,
          alignment: Alignment.bottomCenter,
        ),
      },
    );
  }
  Future openDeliverySchedule(BuildContext context) async {
    final bool isProvisional = StorageUtil().provisional;
        if (isProvisional == true) {
          context.push(
            '/deliverySchedule',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
    }
  Future openProvisionalSchedule(BuildContext context) async {
    final isProvisional = StorageUtil().provisional;
        if (isProvisional == true) {
          context.push(
            '/provisionalSchedule',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
  }
  Future openFastPassSchedule(BuildContext context) async {
    final isWpp = StorageUtil().whatsapp;
        if (isWpp) {
          context.push(
            '/fastPassPage',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
      }
  Future showSchedules(BuildContext context) async {
    final routesListStr = <String>[
      'scheduleProvisionalVisitPage',
      'fastPassPage',
      'scheduleCompleteVisitPage',
    ];
    final iconsListIcon = <IconData>[
      Icons.date_range_rounded,
      Icons.date_range_rounded,
      Icons.date_range_rounded,
    ];
    final nameListStr = <String>[
      FFLocalizations.of(context).getVariableText(
        ptText: 'Visita\nProvisória',
        enText: 'Provisional\nSchedule',
      ),
      FFLocalizations.of(context).getVariableText(
        ptText: 'Visita\nRápida',
        enText: 'Fast\nSchedule',
      ),
      FFLocalizations.of(context).getVariableText(
        ptText: 'Visita\nCompleta',
        enText: 'Complete\nSchedule',
      ),
    ];
    await showAdaptiveDialog(
      context: context,
      builder: (context) {
        return Padding(
          padding: MediaQuery.viewInsetsOf(context),
          child: OptionSelectionModalWidget(
            routesListStr: routesListStr,
            iconsListIcon: iconsListIcon,
            nameListStr: nameListStr,
          ),
        );
      },
    );
  }
  Future openVisitorsRegister(BuildContext context) async {
        context.push(
          '/registerVisitorPage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openPoepleOnTheProperty(BuildContext context) async {
        context.push(
          '/peopleOnThePropertyPage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future<void> Logout(BuildContext context) async {
    final String title = FFLocalizations.of(context).getVariableText(
      ptText: 'Sair',
      enText: 'Logout',
    );
    final String content = FFLocalizations.of(context).getVariableText(
      ptText: 'Tem certeza que deseja sair?',
      enText: 'Are you sure you want to logout?',
    );
    showAlertDialog(
        context,
        title,
        content,
        () async =>  await AuthenticationService.signOut(context));
  }
  Future openPreferencesSettings(BuildContext context) async {
        context.push(
          '/preferencesSettings',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openMyOrders(BuildContext context) async {
    final isWpp = StorageUtil().whatsapp;
        if (isWpp) {
          context.push(
            '/packageOrder',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
      }
  Future openReservations(BuildContext context) async {
    final isWpp = StorageUtil().whatsapp;
        if (isWpp) {
          context.push(
            '/reservation',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
      }
  Future showHistories(BuildContext context) async {
    await showAdaptiveDialog(
      // isScrollControlled: true,
      // backgroundColor: Colors.transparent,
      // enableDrag: false,
      context: context,
      builder: (context) {
        return Padding(
          padding: MediaQuery.viewInsetsOf(context),
          child: OptionSelectionModalWidget(
            routesListStr: const <String>[
              'liberationHistory',
              'acessHistoryPage',
              'scheduleCompleteVisitPage',
              'messageHistoryPage'
            ],
            iconsListIcon: const <IconData>[
              Icons.history_rounded,
              Icons.history_rounded,
              Icons.history_rounded,
              Icons.history_rounded,
            ],
            nameListStr: <String>[
              FFLocalizations.of(context).getVariableText(
                ptText: 'Histórico\nde Liberação',
                enText: 'Liberation\nHistory',
              ),
              FFLocalizations.of(context).getVariableText(
                ptText: 'Histórico\nde Acesso',
                enText: 'Access\nHistory',
              ),
              FFLocalizations.of(context).getVariableText(
                ptText: 'Histórico\nde Visita',
                enText: 'Visit\nHistory',
              ),
              FFLocalizations.of(context).getVariableText(
                ptText: 'Histórico\nde Mensagens',
                enText: 'Message\nHistory',
              ),
            ],
          ),
        );
      },
    );
  }
  Future openLiberationsHistory(BuildContext context) async {
        context.push(
          '/liberationHistory',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openAccessHistory(BuildContext context) async {
        context.push(
          '/acessHistoryPage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openVisitsHistory(BuildContext context) async {
        context.push(
          '/scheduleCompleteVisitPage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openMessagesHistory(BuildContext context) async {
        context.push(
          '/messageHistoryPage',
          extra: <String, dynamic>{
            kTransitionInfoKey: const TransitionInfo(
              hasTransition: true,
              transitionType: PageTransitionType.scale,
              alignment: Alignment.bottomCenter,
            ),
          },
        );
      }
  Future openPetsRegister(BuildContext context) async {
    bool isPet = StorageUtil().pets;
        if (isPet) {
          context.push(
            '/petsPage',
            extra: <String, dynamic>{
              kTransitionInfoKey: const TransitionInfo(
                hasTransition: true,
                transitionType: PageTransitionType.scale,
                alignment: Alignment.bottomCenter,
              ),
            },
          );
        } else {
          DialogUnavailable.unavailableFeature(context);
        }
      }


}

