// import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hub/components/molecular_components/option_selection_modal/option_selection_modal_model.dart';
import 'package:hub/flutter_flow/flutter_flow_animations.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_util.dart';

class OptionSelectionModalWidget extends StatefulWidget {
  const OptionSelectionModalWidget({
    super.key,
    this.routesListStr,
    this.iconsListIcon,
    this.nameListStr,
  });

  final List<String>? routesListStr;
  final List<IconData?>? iconsListIcon;
  final List<String>? nameListStr;

  @override
  State<OptionSelectionModalWidget> createState() =>
      _OptionSelectionModalWidgetState();
}

class _OptionSelectionModalWidgetState extends State<OptionSelectionModalWidget>
    with TickerProviderStateMixin {
  late OptionSelectionModalModel _model;

  final animationsMap = <String, AnimationInfo>{};

  @override
  void setState(VoidCallback callback) {
    super.setState(callback);
    _model.onUpdate();
  }

  @override
  void initState() {
    super.initState();
    _model = createModel(context, () => OptionSelectionModalModel());

    animationsMap.addAll({
      'wrapOnPageLoadAnimation': AnimationInfo(
        trigger: AnimationTrigger.onPageLoad,
        effectsBuilder: () => [
          ScaleEffect(
            curve: Curves.easeInOut,
            delay: 0.0.ms,
            duration: 100.0.ms,
            begin: const Offset(0.0, 0.0),
            end: const Offset(1.0, 1.0),
          ),
        ],
      ),
    });
  }

  @override
  void dispose() {
    _model.maybeDispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: GestureDetector(
        onTap: () async {
          context.pop();
        },
        child: Align(
          alignment: Alignment.center,
          child: GridView.builder(
            padding: EdgeInsets.zero,
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              crossAxisSpacing: 10.0,
              mainAxisSpacing: 10.0,
              mainAxisExtent: 120.0,
              childAspectRatio: 10,
            ),
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: widget.routesListStr!.length,
            itemBuilder: (context, optionsListIndex) {
              return GestureDetector(
                onTap: () async {
                  context.pop();
                  if (widget.routesListStr![optionsListIndex] ==
                      'scheduleCompleteVisitPage') {
                    // Navegação para a página ScheduleCompleteVisitPage com queryParameters
                    context.go(
                      '/scheduleCompleteVisitPage',
                      extra: {
                        'visitStartDateStr': DateFormat('yyyy-MM-dd HH:mm:ss')
                            .format(DateTime.now()),
                        'visitEndDateStr': DateFormat('yyyy-MM-dd HH:mm:ss')
                            .format(
                                DateTime.now().add(const Duration(days: 1))),
                      },
                    );
                  } else {
                    // Navegação para outras páginas
                    context.go(widget.routesListStr![optionsListIndex]);
                  }
                },
                child: Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Container(
                    width: 50.0,
                    height: 50.0,
                    decoration: BoxDecoration(
                      color: FlutterFlowTheme.of(context).primaryBackground,
                      boxShadow: [
                        BoxShadow(
                          blurRadius: 4.0,
                          color: FlutterFlowTheme.of(context).customColor5,
                          offset: const Offset(
                            0.0,
                            2.0,
                          ),
                        )
                      ],
                      borderRadius: BorderRadius.circular(24.0),
                      shape: BoxShape.rectangle,
                      border: Border.all(
                        color: FlutterFlowTheme.of(context).alternate,
                        width: 0.5,
                      ),
                    ),
                    child: Padding(
                      padding: const EdgeInsets.all(10.0),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Align(
                            alignment: const AlignmentDirectional(0.0, 0.0),
                            child: Row(
                              mainAxisSize: MainAxisSize.max,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Expanded(
                                  child: Align(
                                    alignment:
                                        const AlignmentDirectional(-1.0, 0.0),
                                    child: Padding(
                                      padding:
                                          const EdgeInsetsDirectional.fromSTEB(
                                              8.0, 0.0, 0.0, 0.0),
                                      child: Container(
                                        width: 30.0,
                                        height: 30.0,
                                        decoration: BoxDecoration(
                                          color: FlutterFlowTheme.of(context)
                                              .primaryBackground,
                                          shape: BoxShape.circle,
                                        ),
                                        alignment: const AlignmentDirectional(
                                            0.0, 0.0),
                                        child: Icon(
                                          widget.iconsListIcon![
                                              optionsListIndex]!,
                                          color: FlutterFlowTheme.of(context)
                                              .accent1,
                                          size: 34.0,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Align(
                            alignment: const AlignmentDirectional(0.0, 0.0),
                            child: Row(
                              mainAxisSize: MainAxisSize.min,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Align(
                                  alignment:
                                      const AlignmentDirectional(0.0, 0.0),
                                  child: Text(
                                    widget.nameListStr![optionsListIndex],
                                    style: FlutterFlowTheme.of(context)
                                        .titleLarge
                                        .override(
                                          fontFamily: 'Nunito',
                                          color: FlutterFlowTheme.of(context)
                                              .primaryText,
                                          fontSize: 14.0,
                                          letterSpacing: 0.0,
                                          fontWeight: FontWeight.w500,
                                          useGoogleFonts: GoogleFonts.asMap()
                                              .containsKey('Nunito'),
                                        ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ].divide(const SizedBox(height: 0.0)),
                      ),
                    ),
                  ),
                ),
              );
            },
          ).animateOnPageLoad(animationsMap['wrapOnPageLoadAnimation']!),
        ),
      ),
    );
  }
}
