import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttericon/elusive_icons.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/barangay_admin/barangay_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/class_components_admin.dart/class_components_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/land_subclassification/land_subclassification_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/memoranda/memoranda_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/municipalities_admin/municipalities_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/signatories/signatories_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/trees_improvements/trees_improvements_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/type_of_location/type_of_location_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/type_of_road/type_of_road_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/unit_construction/unit_construction_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/value_adjustments/value_adjustments_bloc.dart';
import 'package:unit2/screens/offline/passo/admin/barangay.dart';
import 'package:unit2/screens/offline/passo/admin/class_components.dart';
import 'package:unit2/screens/offline/passo/admin/globalSyncService.dart';
import 'package:unit2/screens/offline/passo/admin/land_classification.dart';
import 'package:unit2/screens/offline/passo/admin/land_sub_classification.dart';
import 'package:unit2/screens/offline/passo/admin/memoranda.dart';
import 'package:unit2/screens/offline/passo/admin/municipalities.dart';
import 'package:unit2/screens/offline/passo/admin/signatories.dart';
import 'package:unit2/screens/offline/passo/admin/trees_improvements.dart';
import 'package:unit2/screens/offline/passo/admin/type_of_location.dart';
import 'package:unit2/screens/offline/passo/admin/type_of_road.dart';
import 'package:unit2/screens/offline/passo/admin/unit_construction.dart';
import 'package:unit2/screens/offline/passo/admin/value_adjustment.dart';
import 'package:unit2/screens/profile/components/main_menu.dart';
import 'package:unit2/sevices/offline/offline_passo/admin/api_services/type_of_location.dart';
import 'package:unit2/theme-data.dart/colors.dart';

import '../../../../bloc/offline/offline_passo/admin/land_classification/land_classification_bloc.dart';

class AdminMainScreen extends StatefulWidget {
  const AdminMainScreen({super.key});

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

class _AdminMainScreen extends State<AdminMainScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: primary,
        title: const Text("PASSO Admin"),
        centerTitle: true,
        // actions: [
        //   TextButton(
        //     style: TextButton.styleFrom(
        //       textStyle: const TextStyle(fontSize: 15),
        //     ),
        //     onPressed: () async {
        //       try {
        //         GlobalSyncService().syncAllData();
        //       } catch (e) {
        //         // Handle any errors that might occur during the API call or database insertion.
        //         print("Error: $e");
        //       }
        //     },
        //     child: const Text('SYNC'),
        //   ),
        // ],
      ),
      body: ListView(
        children: [
          MainMenu(
            icon: Elusive.wrench,
            title: "Municipalities",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      MunicipalitiesAdminBloc()..add(LoadMunicipalities()),
                  child: const MunicipalitiesAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Barangay",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) => BarangayAdminBloc()..add(LoadBarangay()),
                  child: const BarangayAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Class Components",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      ClassComponentsAdminBloc()..add(LoadClassComponents()),
                  child: const ClassComponentsAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Structural Types",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      UnitConstructionAdminBloc()..add(LoadUnitConstruct()),
                  child: const UnitConstructionAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Signatories",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      SignatoriesAdminBloc()..add(LoadSignatories()),
                  child: const SignatoriesAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Memoranda",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      MemorandaAdminBloc()..add(LoadMemoranda()),
                  child: const MemorandaAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Land SubClassification",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) => LandSubclassificationBloc()
                    ..add(const LoadLandSubClassification()),
                  child: const LandSubClassificationAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Land Classification",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) => LandClassificationBloc()
                    ..add(const LoadLandClassification()),
                  child: const LandClassificationAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Trees",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      TreesImprovementsBloc()..add(LoadTreesImprovements()),
                  child: const TreesImprovementsAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Type of Road",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      TypeOfRoadBloc()..add(const LoadTypeOfRoad()),
                  child: const TypesOfRoadAdminPage(),
                );
              }));
            },
          ),
          const Divider(),
          MainMenu(
            icon: Elusive.wrench,
            title: "Type of Location",
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                return BlocProvider(
                  create: (context) =>
                      TypeOfLocationBloc()..add(const LoadTypeOfLocation()),
                  child: const TypesOfLocationAdminPage(),
                );
              }));
            },
          ),
        ],
      ),
    );
  }
}
