import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/models/dashboard/menu_entries.dart';
import 'package:mohem_flutter_app/models/my_team/get_employee_subordinates_list.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/my_attendance/dynamic_screens/dynamic_listview_screen.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:provider/provider.dart';

class ServicesMenuListScreenParams {
  final String title;
  final List<GetMenuEntriesList> list;
  final String? selectedEmp;
  GetEmployeeSubordinatesList? getEmployeeSubordinates;

  ServicesMenuListScreenParams(this.title, this.list, {this.selectedEmp});
}

class ServicesMenuListScreen extends StatelessWidget {
  late ServicesMenuListScreenParams servicesMenuData;

  ServicesMenuListScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    servicesMenuData = ModalRoute.of(context)!.settings.arguments as ServicesMenuListScreenParams;

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBarWidget(context, title: servicesMenuData.title),
      body: SizedBox(
        width: double.infinity,
        height: double.infinity,
        child: servicesMenuData.list.isEmpty
            ? Utils.getNoDataWidget(context)
            : ListView.separated(
                padding: const EdgeInsets.all(21),
                itemBuilder: (cxt, index) => itemView("assets/images/pdf.svg", servicesMenuData.list[index].prompt!, context).onPress(() {
                      if (servicesMenuData.list[index].parentMenuName == "MBL_PERINFO_SS") {
                        if (servicesMenuData.list[index].requestType == "BASIC_DETAILS") {
                          Navigator.pushNamed(context, AppRoutes.basicDetails);
                        } else if (servicesMenuData.list[index].requestType == "PHONE_NUMBERS") {
                          Navigator.pushNamed(context, AppRoutes.personalInfo);
                        } else if (servicesMenuData.list[index].requestType == "ADDRESS") {
                          Navigator.pushNamed(context, AppRoutes.contactDetails);
                        } else if (servicesMenuData.list[index].requestType == "CONTACT") {
                          Navigator.pushNamed(context, AppRoutes.familyMembers);
                        }
                        return;
                      } else if (servicesMenuData.list[index].requestType == "ABSENCE") {
                        Navigator.pushNamed(context, AppRoutes.leaveBalance, arguments: servicesMenuData.selectedEmp);
                        return;
                      }
                      if (servicesMenuData.list[index].requestType == "EIT") {
                        Navigator.pushNamed(context, AppRoutes.dynamicScreen,
                            arguments: DynamicListViewParams(servicesMenuData.list[index].prompt!, servicesMenuData.list[index].functionName!, selectedEmp: servicesMenuData.selectedEmp));
                      } else {
                        if (servicesMenuData.list[index].requestType == "TERMINATION") {
                          Navigator.pushNamed(context, AppRoutes.endEmploymentScreen,
                              arguments: DynamicListViewParams(servicesMenuData.list[index].prompt!, servicesMenuData.list[index].functionName!));
                        } else {
                          var provider = Provider.of<DashboardProviderModel>(context, listen: false);
                          List<GetMenuEntriesList> menuList = provider.getMenuEntriesList?.where((element) => element.parentMenuName == servicesMenuData.list[index].menuName).toList() ?? [];
                          Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(servicesMenuData.list[index].prompt!, menuList));
                        }
                      }
                    }),
                separatorBuilder: (cxt, index) => 12.height,
                itemCount: servicesMenuData.list.length),
      ),
    );
  }

  Widget itemView(String icon, String title, context) {
    return Row(
      children: [
        (title).toText16().expanded,
        12.width,
        RotatedBox(
          quarterTurns: AppState().isArabic(context) ? 2 : 4,
          child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.darkIconColor),
        ),
      ],
    ).objectContainerView();
  }
}
