
import 'dart:ui';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/my_team/my_team_api_client.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/generated/locale_keys.g.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';

class CreateRequest extends StatefulWidget {
  const CreateRequest ({Key? key}) : super(key: key);

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

class _CreateRequestState extends State<CreateRequest> {
  String searchEmpEmail ="";
  String searchEmpName ="";
  String searchEmpNo = "";
  String? empId;
  List<GetEmployeeSubordinatesList> getEmployeeSubordinatesList = [];
//  late DashboardProviderModel data;
  List<GetMenuEntriesList> getMenuEntriesList = [];
  GetEmployeeSubordinatesList? getEmployeeSubordinates;

  @override
  void initState() {
    super.initState();
  //  data.fetchMenuEntries();
    employeeSubRequest();
  }

  void employeeSubRequest() async {
    try {
      Utils.showLoading(context);
      getEmployeeSubordinatesList = await MyTeamApiClient().getEmployeeSubordinates(searchEmpEmail.toString(), searchEmpName.toString(), searchEmpNo.toString());
      getMenuEntriesList = await MyTeamApiClient().employeeSubordinatesRequest(getEmployeeSubordinates?.eMPLOYEENUMBER);
      Utils.hideLoading(context);
      setState(() {});
    } catch (ex) {
      Utils.hideLoading(context);
      Utils.handleException(ex, context, null);
    }
  }

  @override
  Widget build(BuildContext context) {
    getEmployeeSubordinates ??= ModalRoute.of(context)?.settings.arguments as GetEmployeeSubordinatesList;
    print(getMenuEntriesList.length);
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBarWidget(
        context,
        title: LocaleKeys.createRequest.tr(),
      ),
        body: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: getMenuEntriesList.isEmpty
              ? Utils.getNoDataWidget(context)
              : ListView.separated(
              padding: const EdgeInsets.all(21),
              itemBuilder: (cxt, index) => itemView("assets/images/pdf.svg", getMenuEntriesList[index].prompt!, index).onPress(() {
                Navigator.pushNamed(context, AppRoutes.dynamicScreen, arguments: DynamicListViewParams(getMenuEntriesList[index].prompt!, getMenuEntriesList[index].functionName!));
              }),
              separatorBuilder: (cxt, index) => 12.height,
              itemCount: getMenuEntriesList.length),
        ),

    );
  }

  Widget itemView(String icon, String title, index) {
    return  getMenuEntriesList[index].parentMenuName !=""? Row(
      children: [
        (title).toText16().expanded, 12.width,
        SvgPicture.asset(
          "assets/images/arrow_next.svg",
          color: MyColors.darkIconColor,
        )
      ],
    ).objectContainerView() : SizedBox();
  }
}
