import 'dart:io';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:generp/Models/crmModels/GetDistrictOnStateResponse.dart';
import 'package:generp/Models/crmModels/GetSegmentOnTeamResponse.dart';
import 'package:generp/Models/crmModels/GetSourceOnReferenceResponse.dart';
import 'package:generp/Models/crmModels/GetSubLocOnDistrictResponse.dart';
import 'package:generp/Models/crmModels/LeadListViewResponse.dart';
import 'package:generp/Notifiers/crmProvider/LeadListProvider.dart';
import 'package:generp/Utils/commonServices.dart';
import 'package:provider/provider.dart';
import 'package:generp/screens/screensExports.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../Utils/app_colors.dart';
import '../../Utils/commonWidgets.dart';
import '../../Utils/dropdownTheme.dart';
import '../commonDateRangeFilter.dart';

class Leadlistbymode extends StatefulWidget {
  final pageTitleName;
  final mode;
  final filter;

  const Leadlistbymode({
    super.key,
    required this.pageTitleName,
    required this.mode,
    this.filter,
  });

  @override
  State<Leadlistbymode> createState() => _LeadlistbymodeState();
}

class _LeadlistbymodeState extends State<Leadlistbymode> {
  Dropdowntheme ddtheme = Dropdowntheme();
  Map _source = {ConnectivityResult.mobile: true};
  final MyConnectivity _connectivity = MyConnectivity.instance;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _connectivity.initialise();
    _connectivity.myStream.listen((source) {
      setState(() => _source = source);
    });
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      final provider = Provider.of<Leadlistprovider>(context, listen: false);
      provider.crmLeadListViewAPIFunction(context, widget.mode);
      if (widget.filter != null) {
        provider.crmLeadListAPIFunction(
          context,
          widget.mode,
          widget.filter!.status,
          widget.filter!.openStatus,
          "",
          "",
          "",
          "",
          "",
        );
      } else {
        provider.crmLeadListAPIFunction(
          context,
          widget.mode,
          "",
          "",
          "",
          "",
          "",
          "",
          "",
        );
      }
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _connectivity.disposeStream();
  }

  @override
  Widget build(BuildContext context) {
    switch (_source.keys.toList()[0]) {
      case ConnectivityResult.mobile:
        connection = 'Online';
        break;
      case ConnectivityResult.wifi:
        connection = 'Online';
        break;
      case ConnectivityResult.none:
      default:
        connection = 'Offline';
    }
    return (connection == "Online")
        ? Platform.isAndroid
            ? WillPopScope(
              onWillPop: () => onBackPressed(context),
              child: SafeArea(
                top: false,
                bottom: true,
                child: _scaffold(context),
              ),
            )
            : _scaffold(context)
        : NoNetwork(context);
  }

  Widget _scaffold(BuildContext context) {
    return Consumer<Leadlistprovider>(
      builder: (context, provider, child) {
        final crmLists = provider.crmLeadList;
        return Scaffold(
          resizeToAvoidBottomInset: true,
          appBar: appbar2New(
            context,
            widget.pageTitleName,
            provider.resetForm,
            Row(
              children: [
                InkResponse(
                  onTap: () async {
                    _showFilterSheetNew(context);
                  },
                  child: SvgPicture.asset(
                    "assets/svg/filter_ic.svg",
                    height: 25,
                  ),
                ),
              ],
            ),
            0xFFFFFFFF,
          ),
          backgroundColor: AppColors.scaffold_bg_color,
          body:
              provider.isLoading
                  ? Center(
                    child: CircularProgressIndicator.adaptive(
                      valueColor: AlwaysStoppedAnimation<Color>(
                        AppColors.app_blue,
                      ),
                    ),
                  )
                  : crmLists.isNotEmpty
                  ? SizedBox(
                    child: Scrollbar(
                      thumbVisibility: false,
                      child: ListView.builder(
                        itemCount: crmLists.length,
                        shrinkWrap: true,
                        physics: AlwaysScrollableScrollPhysics(),
                        itemBuilder: (context, index) {
                          if (crmLists.isEmpty) {
                            return SizedBox(
                              child: Center(child: Text("No Data Available")),
                            );
                          }
                          return InkResponse(
                            onTap: () async {
                              Navigator.push(
                                context,
                                MaterialPageRoute(
                                  builder:
                                      (context) => LeadDetailsByMode(
                                        pageTitleName: widget.pageTitleName,
                                        mode: widget.mode,
                                        leadId:
                                            provider.crmLeadList[index].leadid,
                                      ),
                                ),
                              );
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(
                                horizontal: 10,
                                vertical: 5,
                              ),
                              margin: EdgeInsets.symmetric(
                                horizontal: 10,
                                vertical: 5,
                              ),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(16),
                              ),
                              child: Column(
                                children: [
                                  Row(
                                    children: [
                                      Expanded(
                                        flex: 1,
                                        child: Container(
                                          height: 50,
                                          width: 35,
                                          child: SvgPicture.asset(
                                            "assets/svg/crm/lead_details_list_ic.svg",
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: 10),
                                      Expanded(
                                        flex: 6,
                                        child: SizedBox(
                                          child: Column(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: [
                                              Text(
                                                crmLists[index].company!,
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  fontFamily: "JakartaMedium",
                                                  fontSize: 14,
                                                  color: AppColors.semi_black,
                                                ),
                                              ),
                                              Text(
                                                crmLists[index].product ?? "-",
                                                maxLines: 1,
                                                style: TextStyle(
                                                  fontFamily: "JakartaMedium",
                                                  fontSize: 12,
                                                  color: AppColors.grey_semi,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: 10),
                                      Expanded(
                                        flex: 1,
                                        child: InkResponse(
                                          onTap: () {
                                            launch(
                                              'tel://${crmLists[index].mob1}',
                                            );
                                          },
                                          child: SizedBox(
                                            height: 35,
                                            width: 35,
                                            child: SvgPicture.asset(
                                              "assets/svg/crm/lead_list_call_ic.svg",
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  )
                  : Emptywidget(context),
        );
      },
    );
  }

  // Future<void> _showFilterSheet(BuildContext context) {
  //   return showModalBottomSheet(
  //     useSafeArea: true,
  //     isDismissible: true,
  //     isScrollControlled: true,
  //     showDragHandle: true,
  //     backgroundColor: Colors.white,
  //     enableDrag: true,
  //     context: context,
  //     builder: (context) {
  //       return StatefulBuilder(
  //         builder: (context, setState) {
  //           return SafeArea(
  //             child: Consumer<Leadlistprovider>(
  //               builder: (context, provider, child) {
  //                 return Container(
  //                   margin: EdgeInsets.only(
  //                     bottom: 15,
  //                     left: 15,
  //                     right: 15,
  //                     top: 10,
  //                   ),
  //                   padding: EdgeInsets.only(
  //                     bottom: MediaQuery.of(context).viewInsets.bottom,
  //                   ),
  //                   child: SingleChildScrollView(
  //                     child: Column(
  //                       crossAxisAlignment: CrossAxisAlignment.start,
  //                       mainAxisSize: MainAxisSize.min,
  //                       children: [
  //                         SizedBox(height: 15),
  //                         Row(
  //                           children: [
  //                             Expanded(
  //                               child: Text(
  //                                 "Filter",
  //                                 style: TextStyle(
  //                                   color: AppColors.app_blue,
  //                                   fontSize: 14,
  //                                 ),
  //                               ),
  //                             ),
  //                           ],
  //                         ),
  //                         textControllerWidget(
  //                           context,
  //                           provider.sLeadIDController,
  //                           "Lead ID",
  //                           "Enter Lead ID",
  //                           provider.onChangedLeadId,
  //                           TextInputType.text,
  //                           false,
  //                           null,
  //                         ),
  //                         if (widget.mode != "executive") ...[
  //                           TextWidget(context, "Employee"),
  //                           DropdownButtonHideUnderline(
  //                             child: Row(
  //                               children: [
  //                                 Expanded(
  //                                   child: DropdownButton2<Employees>(
  //                                     hint: Text(
  //                                       "Select Source",
  //                                       style: TextStyle(fontSize: 14),
  //                                     ),
  //                                     items:
  //                                         provider.employeesList
  //                                             .map(
  //                                               (slist) =>
  //                                                   DropdownMenuItem<Employees>(
  //                                                     value: slist,
  //                                                     child: Text(
  //                                                       slist.name!,
  //                                                       style: TextStyle(
  //                                                         fontSize: 14,
  //                                                       ),
  //                                                     ),
  //                                                   ),
  //                                             )
  //                                             .toList(),
  //                                     value:
  //                                         provider.employeesList.contains(
  //                                               provider.selectedEmployee,
  //                                             )
  //                                             ? provider.selectedEmployee
  //                                             : null,
  //
  //                                     // value: provider.selectedEmployees,
  //                                     onChanged: (Employees? value) {
  //                                       if (value != null) {
  //                                         if (provider
  //                                             .employeesList
  //                                             .isNotEmpty) {
  //                                           provider.selectedEmployee = value;
  //                                           provider.selectedEmployeeId =
  //                                               value!.id!;
  //                                           provider.selectedEmployeeValue =
  //                                               value!.name!;
  //                                           provider
  //                                               .crmLeadListSourceOnReferenceAPIFunction(
  //                                                 context,
  //                                                 widget.mode,
  //                                                 provider.selectedSourceId,
  //                                               );
  //                                         }
  //                                       }
  //                                     },
  //                                     isExpanded: true,
  //                                     buttonStyleData: ddtheme.buttonStyleData,
  //                                     iconStyleData: ddtheme.iconStyleData,
  //                                     menuItemStyleData:
  //                                         ddtheme.menuItemStyleData,
  //                                     dropdownStyleData:
  //                                         ddtheme.dropdownStyleData,
  //                                   ),
  //                                 ),
  //                               ],
  //                             ),
  //                           ),
  //                         ],
  //                         TextWidget(context, "Lead Status"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<String>(
  //                                   hint: Text(
  //                                     "Select Lead Status",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.leadStatusList
  //                                           .map(
  //                                             (leadStatus) =>
  //                                                 DropdownMenuItem<String>(
  //                                                   value: leadStatus,
  //                                                   child: Text(
  //                                                     leadStatus!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedLeadStatus,
  //                                   onChanged: (String? value) {
  //                                     if (value != null) {
  //                                       provider.selectedLeadStatus = value;
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "Open/Close Status"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<String>(
  //                                   hint: Text(
  //                                     "Select Open/Close Status",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.openStatusList
  //                                           .map(
  //                                             (leadStatus) =>
  //                                                 DropdownMenuItem<String>(
  //                                                   value: leadStatus,
  //                                                   child: Text(
  //                                                     leadStatus!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedOpenStatus,
  //                                   onChanged: (String? value) {
  //                                     if (value != null) {
  //                                       provider.selectedOpenStatus = value;
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //                         textControllerWidget(
  //                           context,
  //                           provider.mobileNumberController,
  //                           "Mobile Number",
  //                           "Enter Mobile Number",
  //                           provider.onChangedMobileNum,
  //                           TextInputType.number,
  //                           false,
  //                           FilteringTextInputFormatter.digitsOnly,
  //                         ),
  //                         textControllerWidget(
  //                           context,
  //                           provider.companyNameController,
  //                           "Company Name",
  //                           "Enter Company Name",
  //                           provider.onChangedCompanyName,
  //                           TextInputType.text,
  //                           false,
  //                           null,
  //                         ),
  //
  //                         TextWidget(context, "Source"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<Sources>(
  //                                   hint: Text(
  //                                     "Select Source",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.sourcesList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<Sources>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.name!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedSource,
  //                                   onChanged: (Sources? value) {
  //                                     if (value != null) {
  //                                       if (provider.sourcesList.isNotEmpty) {
  //                                         provider.selectedSource = value;
  //                                         provider.selectedSourceId =
  //                                             value!.id!;
  //                                         provider.selectedSourceValue =
  //                                             value!.name!;
  //                                         provider
  //                                             .crmLeadListSourceOnReferenceAPIFunction(
  //                                               context,
  //                                               widget.mode,
  //                                               provider.selectedSourceId,
  //                                             );
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "Reference"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<References>(
  //                                   hint: Text(
  //                                     "Select Reference",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.referencesList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<References>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.name!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedReference,
  //                                   onChanged: (References? value) {
  //                                     if (value != null) {
  //                                       if (provider
  //                                           .referencesList
  //                                           .isNotEmpty) {
  //                                         provider.selectedReference = value;
  //                                         provider.selectedReferenceId =
  //                                             value!.id!;
  //                                         provider.selectedReferenceValue =
  //                                             value!.name!;
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "Team"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<Teams>(
  //                                   hint: Text(
  //                                     "Select Team",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.teamsList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<Teams>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.name!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedTeam,
  //                                   onChanged: (Teams? value) {
  //                                     if (value != null) {
  //                                       if (provider.teamsList.isNotEmpty) {
  //                                         provider.selectedTeam = value;
  //                                         provider.selectedTeamId = value!.id!;
  //                                         provider.selectedTeamValue =
  //                                             value!.name!;
  //                                         provider
  //                                             .crmLeadListSegmentOnTeamAPIFunction(
  //                                               context,
  //                                               widget.mode,
  //                                               provider.selectedTeamId,
  //                                             );
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "Segment"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<Segments>(
  //                                   hint: Text(
  //                                     "Select Segment",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.segmentsList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<Segments>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.name!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedSegment,
  //                                   onChanged: (Segments? value) {
  //                                     if (value != null) {
  //                                       if (provider.segmentsList.isNotEmpty) {
  //                                         provider.selectedSegment = value;
  //                                         provider.selectedSegmentId =
  //                                             value!.id!;
  //                                         provider.selectedSegmentValue =
  //                                             value!.name!;
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "State"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<States>(
  //                                   hint: Text(
  //                                     "Select State",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.statesList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<States>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.name!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedStates,
  //                                   onChanged: (States? value) {
  //                                     if (value != null) {
  //                                       if (provider.statesList.isNotEmpty) {
  //                                         provider.selectedStates = value;
  //                                         provider.selectedStateId = value!.id!;
  //                                         provider.selectedStateValue =
  //                                             value!.name!;
  //                                         if (provider
  //                                             .districtsList
  //                                             .isNotEmpty) {
  //                                           provider.districtsList.clear();
  //                                           // provider.selectedDistricts = null;
  //                                           provider.selectedDistrictId = null;
  //                                           provider.selectedDistrictValue = "";
  //                                         }
  //                                         provider
  //                                             .crmLeadListDistrictsOnStateAPIFunction(
  //                                               context,
  //                                               widget.mode,
  //                                               provider.selectedStateId,
  //                                             );
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "District"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<Districts>(
  //                                   hint: Text(
  //                                     "Select District",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.districtsList
  //                                           .map(
  //                                             (slist) =>
  //                                                 DropdownMenuItem<Districts>(
  //                                                   value: slist,
  //                                                   child: Text(
  //                                                     slist.district!,
  //                                                     style: TextStyle(
  //                                                       fontSize: 14,
  //                                                     ),
  //                                                   ),
  //                                                 ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedDistricts,
  //                                   onChanged: (Districts? value) {
  //                                     if (value != null) {
  //                                       if (provider.districtsList.isNotEmpty) {
  //                                         provider.selectedDistricts = value;
  //                                         provider.selectedDistrictId =
  //                                             value!.id!;
  //                                         provider.selectedDistrictValue =
  //                                             value!.district!;
  //                                         if (provider
  //                                             .subLocationsList
  //                                             .isNotEmpty) {
  //                                           provider.subLocationsList.clear();
  //                                           // provider.selectedSubLocations =
  //                                           //     null;
  //                                           provider.selectedSubLocationId =
  //                                               null;
  //                                           provider.selectedSubLocationValue =
  //                                               "";
  //                                         }
  //                                         provider
  //                                             .crmLeadListSubLocOnDistrictAPIFunction(
  //                                               context,
  //                                               widget.mode,
  //                                               provider.selectedDistrictId,
  //                                             );
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         TextWidget(context, "Sub Location"),
  //                         DropdownButtonHideUnderline(
  //                           child: Row(
  //                             children: [
  //                               Expanded(
  //                                 child: DropdownButton2<SubLocations>(
  //                                   hint: Text(
  //                                     "Select Sub Location",
  //                                     style: TextStyle(fontSize: 14),
  //                                   ),
  //                                   items:
  //                                       provider.subLocationsList
  //                                           .map(
  //                                             (slist) => DropdownMenuItem<
  //                                               SubLocations
  //                                             >(
  //                                               value: slist,
  //                                               child: Text(
  //                                                 slist.subLocality!,
  //                                                 style: TextStyle(
  //                                                   fontSize: 14,
  //                                                 ),
  //                                               ),
  //                                             ),
  //                                           )
  //                                           .toList(),
  //                                   value: provider.selectedSubLocations,
  //                                   onChanged: (SubLocations? value) {
  //                                     if (value != null) {
  //                                       if (provider
  //                                           .subLocationsList
  //                                           .isNotEmpty) {
  //                                         provider.selectedSubLocations = value;
  //                                         provider.selectedSubLocationId =
  //                                             value!.id!;
  //                                         provider.selectedSubLocationValue =
  //                                             value!.subLocality!;
  //                                       }
  //                                     }
  //                                   },
  //                                   isExpanded: true,
  //                                   buttonStyleData: ddtheme.buttonStyleData,
  //                                   iconStyleData: ddtheme.iconStyleData,
  //                                   menuItemStyleData:
  //                                       ddtheme.menuItemStyleData,
  //                                   dropdownStyleData:
  //                                       ddtheme.dropdownStyleData,
  //                                 ),
  //                               ),
  //                             ],
  //                           ),
  //                         ),
  //
  //                         InkResponse(
  //                           onTap: () {
  //                             // provider.crmLeadListAPIFunction(
  //                             //   context,
  //                             //   widget.mode,
  //                             //   provider.selectedEmployeeId,
  //                             //   provider.selectedLeadStatus,
  //                             //   provider.selectedOpenStatus,
  //                             //   provider.selectedSourceId,
  //                             //   provider.selectedReferenceId,
  //                             //   provider.selectedTeamId,
  //                             //   provider.selectedSegmentId,
  //                             //   provider.selectedStateId,
  //                             //   provider.selectedDistrictId,
  //                             //   provider.selectedSubLocationId,
  //                             // );
  //                             Navigator.pop(context);
  //                           },
  //                           child: Container(
  //                             height: 45,
  //                             alignment: Alignment.center,
  //                             margin: EdgeInsets.symmetric(horizontal: 10),
  //                             padding: EdgeInsets.symmetric(
  //                               horizontal: 10,
  //                               vertical: 5,
  //                             ),
  //                             decoration: BoxDecoration(
  //                               color: AppColors.app_blue,
  //                               borderRadius: BorderRadius.circular(15),
  //                             ),
  //                             child: Text(
  //                               "Submit",
  //                               style: TextStyle(
  //                                 fontSize: 15,
  //                                 fontFamily: "JakartaMedium",
  //                                 color: Colors.white,
  //                               ),
  //                             ),
  //                           ),
  //                         ),
  //                       ],
  //                     ),
  //                   ),
  //                 );
  //               },
  //             ),
  //           );
  //         },
  //       );
  //     },
  //   );
  // }

  Future<void> _showFilterSheetNew1(BuildContext context) {
    List<bool> isSelected = List.generate(
      9,
      (index) => index == 0 ? true : false,
    );

    return showModalBottomSheet(
      useSafeArea: true,
      isDismissible: true,
      isScrollControlled: true,
      showDragHandle: true,
      backgroundColor: Colors.white,
      enableDrag: true,
      context: context,
      builder: (context) {
        return StatefulBuilder(
          builder: (context, setState) {
            return SafeArea(
              child: Padding(
                padding: EdgeInsets.only(
                  bottom: MediaQuery.of(context).viewInsets.bottom,
                ),
                child: Consumer<Leadlistprovider>(
                  builder: (context, provider, child) {
                    int selectedIndex = isSelected.indexWhere(
                      (element) => element == true,
                    );
                    final headings = [
                      "Lead Status",
                      "Open/Close Status",
                      "Mobile Number",
                      "Company Name",
                      "Source",
                      "Reference",
                      "Team",
                      "Segment",
                    ];
                    if (widget.mode != "executive") {
                      headings.add("Employee");
                    }
                    return Container(
                      height: MediaQuery.of(context).size.height * 0.7,

                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 15),
                            child: Text(
                              "Filter",
                              style: TextStyle(
                                color: AppColors.app_blue,
                                fontSize: 18,
                                fontFamily: "JakartaSemiBold",
                              ),
                            ),
                          ),
                          const SizedBox(height: 20),
                          // Two-Column Layout
                          Expanded(
                            child: Container(
                              decoration: BoxDecoration(
                                border: Border(
                                  top: BorderSide(
                                    color: const Color(0xFFA5DAF9),
                                  ),
                                  bottom: BorderSide(
                                    color: const Color(0xFFA5DAF9),
                                  ),
                                ),
                              ),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  // Left Column: Headings
                                  Expanded(
                                    flex: 3,
                                    child: Column(
                                      children: List.generate(headings.length, (
                                        jj,
                                      ) {
                                        return Expanded(
                                          child: InkResponse(
                                            onTap: () {
                                              setState(() {
                                                // Reset all to false
                                                isSelected = List.generate(
                                                  headings.length,
                                                  (index) => false,
                                                );
                                                // Set the clicked item to true
                                                isSelected[jj] = true;
                                              });
                                            },
                                            child: Container(
                                              padding:
                                                  const EdgeInsets.symmetric(
                                                    vertical: 7.5,
                                                    horizontal: 10,
                                                  ),
                                              decoration: BoxDecoration(
                                                border: Border(
                                                  left:
                                                      isSelected[jj]
                                                          ? BorderSide(
                                                            color:
                                                                AppColors
                                                                    .app_blue,
                                                            width: 5.0,
                                                          )
                                                          : const BorderSide(
                                                            color:
                                                                Colors
                                                                    .transparent,
                                                          ),
                                                  bottom:
                                                      jj == headings.length - 1
                                                          ? const BorderSide(
                                                            color:
                                                                Colors
                                                                    .transparent,
                                                          )
                                                          : const BorderSide(
                                                            color: Color(
                                                              0xFFA5DAF9,
                                                            ),
                                                          ),
                                                ),
                                                color: const Color(0xFFE6F6FF),
                                              ),
                                              child: Center(
                                                child: Text(
                                                  headings[jj],
                                                  textAlign: TextAlign.center,
                                                  style: TextStyle(
                                                    fontSize: 14,
                                                    fontFamily:
                                                        "JakartaRegular",
                                                    color: AppColors.semi_black,
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        );
                                      }),
                                    ),
                                  ),
                                  // Right Column: Dynamic Input Fields
                                  Expanded(
                                    flex: 5,
                                    child: SingleChildScrollView(
                                      padding: const EdgeInsets.symmetric(
                                        horizontal: 10,
                                        vertical: 5,
                                      ),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        mainAxisSize: MainAxisSize.min,
                                        children: [
                                          if (selectedIndex == 0) ...[
                                            ...provider.leadStatusList.map((
                                              status,
                                            ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                      AppColors.app_blue,
                                                  controlAffinity:
                                                      ListTileControlAffinity
                                                          .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    status!,
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                      provider
                                                          .selectedLeadStatus ==
                                                      status,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      if (value == true) {
                                                        provider.selectedLeadStatus =
                                                            status;
                                                      } else {
                                                        provider.selectedLeadStatus =
                                                            null;
                                                      }
                                                      print(
                                                        provider
                                                            .selectedLeadStatus,
                                                      );
                                                    });
                                                  },
                                                  contentPadding:
                                                      EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 1) ...[
                                            ...provider.openStatusList.map((
                                              status,
                                            ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                      AppColors.app_blue,
                                                  controlAffinity:
                                                      ListTileControlAffinity
                                                          .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    status!,
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                      provider
                                                          .selectedOpenStatus ==
                                                      status,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      if (value == true) {
                                                        provider.selectedOpenStatus =
                                                            status;
                                                      } else {
                                                        provider.selectedOpenStatus =
                                                            null;
                                                      }
                                                    });
                                                  },
                                                  contentPadding:
                                                      EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 2) ...[
                                            textControllerWidget(
                                              context,
                                              provider.mobileNumberController,
                                              "Mobile Number",
                                              "Enter Mobile Number",
                                              provider.onChangedMobileNum,
                                              TextInputType.number,
                                              false,
                                              FilteringTextInputFormatter
                                                  .digitsOnly,
                                            ),
                                          ] else if (selectedIndex == 3) ...[
                                            textControllerWidget(
                                              context,
                                              provider.companyNameController,
                                              "Company Name",
                                              "Enter Company Name",
                                              provider.onChangedCompanyName,
                                              TextInputType.text,
                                              false,
                                              null,
                                            ),
                                          ] else if (selectedIndex == 4) ...[
                                            ...provider.sourcesList.map((
                                              source,
                                            ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                      AppColors.app_blue,
                                                  controlAffinity:
                                                      ListTileControlAffinity
                                                          .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    source.name!,
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                      provider.selectedSource ==
                                                      source,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      if (value == true) {
                                                        provider.selectedSource =
                                                            source!;
                                                        provider.selectedSourceId =
                                                            source.id!;
                                                        provider.selectedSourceValue =
                                                            source.name!;
                                                      } else {

                                                        provider.selectedSourceId =
                                                            null;
                                                        provider.selectedSourceValue =
                                                            null;
                                                        if (provider
                                                                .selectedReference !=
                                                            null) {
                                                          provider
                                                              .referencesList
                                                              .clear();

                                                          provider.selectedReferenceId =
                                                              null;
                                                          provider.selectedReferenceValue =
                                                              null;
                                                        }
                                                      }
                                                      // Call API if needed
                                                      provider
                                                          .crmLeadListSourceOnReferenceAPIFunction(
                                                            context,
                                                            widget.mode,
                                                            provider
                                                                .selectedSourceId,
                                                          );
                                                    });
                                                  },
                                                  contentPadding:
                                                      EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 5) ...[
                                            if (provider
                                                .referencesList
                                                .isEmpty) ...[
                                              errorWidget(
                                                context,
                                                "Please Select Source First",
                                              ),
                                            ] else ...[
                                              ...provider.referencesList.map((
                                                reference,
                                              ) {
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                        AppColors.app_blue,
                                                    controlAffinity:
                                                        ListTileControlAffinity
                                                            .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      reference.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                        provider
                                                            .selectedReference ==
                                                        reference,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        if (value == true) {
                                                          provider.selectedReference =
                                                              reference;
                                                          provider.selectedReferenceId =
                                                              reference.id!;
                                                          provider.selectedReferenceValue =
                                                              reference.name!;
                                                        } else {
                                                          provider
                                                              .referencesList
                                                              .clear();

                                                          provider.selectedReferenceId =
                                                              null;
                                                          provider.selectedReferenceValue =
                                                              null;
                                                        }
                                                      });
                                                    },
                                                    contentPadding:
                                                        EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                            ],
                                          ] else if (selectedIndex == 6) ...[
                                            ...provider.teamsList.map((team) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                      AppColors.app_blue,
                                                  title: Text(
                                                    team.name!,
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  controlAffinity:
                                                      ListTileControlAffinity
                                                          .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  value:
                                                      provider.selectedTeam ==
                                                      team,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      if (value == true) {
                                                        provider.selectedTeam =
                                                            team;
                                                        provider.selectedTeamId =
                                                            team.id!;
                                                        provider.selectedTeamValue =
                                                            team.name!;
                                                      } else {
                                                        provider.selectedTeamId =
                                                            null;
                                                        provider.selectedTeamValue =
                                                            null;
                                                        if (provider
                                                                .selectedSegment !=
                                                            null) {
                                                          provider.segmentsList
                                                              .clear();

                                                          provider.selectedSegmentId =
                                                              null;
                                                          provider.selectedSegmentValue =
                                                              null;
                                                        }
                                                      }
                                                      provider
                                                          .crmLeadListSegmentOnTeamAPIFunction(
                                                            context,
                                                            widget.mode,
                                                            provider
                                                                .selectedTeamId,
                                                          );
                                                    });
                                                  },
                                                  contentPadding:
                                                      EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 7) ...[
                                            if (provider
                                                .segmentsList
                                                .isEmpty) ...[
                                              errorWidget(
                                                context,
                                                "Please Select Team ID First",
                                              ),
                                            ] else ...[
                                              ...provider.segmentsList.map((
                                                segment,
                                              ) {
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                        AppColors.app_blue,
                                                    controlAffinity:
                                                        ListTileControlAffinity
                                                            .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      segment.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                        provider
                                                            .selectedSegment ==
                                                        segment,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        if (value == true) {
                                                          provider.selectedSegment =
                                                              segment;
                                                          provider.selectedSegmentId =
                                                              segment.id!;
                                                          provider.selectedSegmentValue =
                                                              segment.name!;
                                                        } else {
                                                          provider.segmentsList
                                                              .clear();

                                                          provider.selectedSegmentId =
                                                              null;
                                                          provider.selectedSegmentValue =
                                                              null;
                                                        }
                                                      });
                                                    },
                                                    contentPadding:
                                                        EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                            ],
                                          ] else if (widget.mode !=
                                              "executive") ...[
                                            ...provider.employeesList.map((
                                              employee,
                                            ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                      AppColors.app_blue,
                                                  controlAffinity:
                                                      ListTileControlAffinity
                                                          .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    employee.name!,
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                      provider
                                                          .selectedEmployee ==
                                                      employee,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      if (value == true) {
                                                        provider.selectedEmployee =
                                                            employee;
                                                        provider.selectedEmployeeId =
                                                            employee.id!;
                                                        provider.selectedEmployeeValue =
                                                            employee.name!;
                                                      }
                                                      provider
                                                          .crmLeadListSourceOnReferenceAPIFunction(
                                                            context,
                                                            widget.mode,
                                                            provider
                                                                .selectedSourceId,
                                                          );
                                                    });
                                                  },
                                                  contentPadding:
                                                      EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ],
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          // Search Button
                          Padding(
                            padding: const EdgeInsets.symmetric(
                              horizontal: 15,
                              vertical: 20,
                            ),
                            child: InkResponse(
                              onTap: () {
                                provider.crmLeadListAPIFunction(
                                  context,
                                  widget.mode,
                                  provider.selectedLeadStatus,
                                  provider.selectedOpenStatus,
                                  provider.selectedSourceId,
                                  provider.selectedReferenceId,
                                  provider.selectedTeamId,
                                  provider.selectedSegmentId,
                                  provider.selectedAlphabet,
                                );
                                Navigator.pop(context);
                              },
                              child: Container(
                                height: 45,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: AppColors.app_blue,
                                  borderRadius: BorderRadius.circular(15),
                                ),
                                child: const Text(
                                  "Search",
                                  style: TextStyle(
                                    fontSize: 15,
                                    fontFamily: "JakartaMedium",
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                ),
              ),
            );
          },
        );
      },
    );
  }

  Future<void> _showFilterSheetNew(BuildContext context) {
    List<bool> isSelected = List.generate(
      9,
          (index) => index == 0 ? true : false,
    );

    return showModalBottomSheet(
      useSafeArea: true,
      isDismissible: true,
      isScrollControlled: true,
      showDragHandle: true,
      backgroundColor: Colors.white,
      enableDrag: true,
      context: context,
      builder: (context) {
        return StatefulBuilder(
          builder: (context, setState) {
            return SafeArea(
              child: Padding(
                padding: EdgeInsets.only(
                  bottom: MediaQuery.of(context).viewInsets.bottom,
                ),
                child: Consumer<Leadlistprovider>(
                  builder: (context, provider, child) {
                    int selectedIndex = isSelected.indexWhere(
                          (element) => element == true,
                    );
                    final headings = [
                      "Lead Status",
                      "Open/Close Status",
                      "Mobile Number",
                      "Company Name",
                      "Source",
                      "Reference",
                      "Team",
                      "Segment",
                    ];
                    if (widget.mode != "executive") {
                      headings.add("Employee");
                    }
                    return Container(
                      height: MediaQuery.of(context).size.height * 0.7,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 15),
                            child: Text(
                              "Filter",
                              style: TextStyle(
                                color: AppColors.app_blue,
                                fontSize: 18,
                                fontFamily: "JakartaSemiBold",
                              ),
                            ),
                          ),
                          const SizedBox(height: 20),
                          Expanded(
                            child: Container(
                              decoration: BoxDecoration(
                                border: Border(
                                  top: BorderSide(
                                    color: const Color(0xFFA5DAF9),
                                  ),
                                  bottom: BorderSide(
                                    color: const Color(0xFFA5DAF9),
                                  ),
                                ),
                              ),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Expanded(
                                    flex: 3,
                                    child: Column(
                                      children: List.generate(headings.length, (
                                          jj,
                                          ) {
                                        return Expanded(
                                          child: InkResponse(
                                            onTap: () {
                                              setState(() {
                                                isSelected = List.generate(
                                                  headings.length,
                                                      (index) => false,
                                                );
                                                isSelected[jj] = true;
                                              });
                                            },
                                            child: Container(
                                              padding:
                                              const EdgeInsets.symmetric(
                                                vertical: 7.5,
                                                horizontal: 10,
                                              ),
                                              decoration: BoxDecoration(
                                                border: Border(
                                                  left:
                                                  isSelected[jj]
                                                      ? BorderSide(
                                                    color:
                                                    AppColors
                                                        .app_blue,
                                                    width: 5.0,
                                                  )
                                                      : const BorderSide(
                                                    color:
                                                    Colors
                                                        .transparent,
                                                  ),
                                                  bottom:
                                                  jj == headings.length - 1
                                                      ? const BorderSide(
                                                    color:
                                                    Colors
                                                        .transparent,
                                                  )
                                                      : const BorderSide(
                                                    color: Color(
                                                      0xFFA5DAF9,
                                                    ),
                                                  ),
                                                ),
                                                color: const Color(0xFFE6F6FF),
                                              ),
                                              child: Row(
                                                children: [
                                                  Expanded(
                                                    child: Text(
                                                      headings[jj],
                                                      textAlign: TextAlign.center,
                                                      style: TextStyle(
                                                        fontSize: 14,
                                                        fontFamily:
                                                        "JakartaRegular",
                                                        color: AppColors.semi_black,
                                                      ),
                                                    ),
                                                  ),
                                                  if (_isFilterSelected(provider, jj))...[
                                                    Container(
                                                      margin: EdgeInsets.only(left: 5),
                                                      width: 8,
                                                      height: 8,
                                                      decoration: BoxDecoration(
                                                        color: Colors.green,
                                                        shape: BoxShape.circle,
                                                      ),
                                                    ),
                                                  ]
                                                ],
                                              ),
                                            ),
                                          ),
                                        );
                                      }),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 5,
                                    child: SingleChildScrollView(
                                      padding: const EdgeInsets.symmetric(
                                        horizontal: 10,
                                        vertical: 5,
                                      ),
                                      child: Column(
                                        crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                        mainAxisSize: MainAxisSize.min,
                                        children: [
                                          if (selectedIndex == 0) ...[
                                            ...provider.leadStatusList.map((
                                                status,
                                                ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                  AppColors.app_blue,
                                                  controlAffinity:
                                                  ListTileControlAffinity
                                                      .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    status ?? 'Unknown Status',
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                  provider
                                                      .selectedLeadStatus ==
                                                      status,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      provider.selectedLeadStatus =
                                                      value == true ? status : null;
                                                    });
                                                  },
                                                  contentPadding:
                                                  EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 1) ...[
                                            ...provider.openStatusList.map((
                                                status,
                                                ) {
                                              return SizedBox(
                                                height: 35,
                                                child: CheckboxListTile(
                                                  activeColor:
                                                  AppColors.app_blue,
                                                  controlAffinity:
                                                  ListTileControlAffinity
                                                      .leading,
                                                  checkboxShape: CircleBorder(
                                                    side: BorderSide(
                                                      width: 0.5,
                                                    ),
                                                  ),
                                                  title: Text(
                                                    status ?? 'Unknown Status',
                                                    style: const TextStyle(
                                                      fontSize: 14,
                                                    ),
                                                  ),
                                                  value:
                                                  provider
                                                      .selectedOpenStatus ==
                                                      status,
                                                  onChanged: (bool? value) {
                                                    setState(() {
                                                      provider.selectedOpenStatus =
                                                      value == true ? status : null;
                                                    });
                                                  },
                                                  contentPadding:
                                                  EdgeInsets.zero,
                                                ),
                                              );
                                            }).toList(),
                                          ] else if (selectedIndex == 2) ...[
                                            textControllerWidget(
                                              context,
                                              provider.mobileNumberController,
                                              "Mobile Number",
                                              "Enter Mobile Number",
                                              provider.onChangedMobileNum,
                                              TextInputType.number,
                                              false,
                                              FilteringTextInputFormatter
                                                  .digitsOnly,
                                            ),
                                          ] else if (selectedIndex == 3) ...[
                                            textControllerWidget(
                                              context,
                                              provider.companyNameController,
                                              "Company Name",
                                              "Enter Company Name",
                                              provider.onChangedCompanyName,
                                              TextInputType.text,
                                              false,
                                              null,
                                            ),
                                          ] else if (selectedIndex == 4) ...[
                                            if (provider.sourcesList.isEmpty)
                                              errorWidget(
                                                context,
                                                "No Sources Available",
                                              )
                                            else
                                              ...provider.sourcesList.map((
                                                  source,
                                                  ) {
                                                if (source == null ||
                                                    source.id == null ||
                                                    source.name == null)
                                                  return SizedBox.shrink();
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                    AppColors.app_blue,
                                                    controlAffinity:
                                                    ListTileControlAffinity
                                                        .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      source.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                    provider.selectedSource ==
                                                        source,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        if (value == true) {
                                                          provider.selectedSource =
                                                              source;
                                                        } else {
                                                          provider.selectedSource =
                                                          null;
                                                          provider.referencesList
                                                              .clear();
                                                          provider.selectedReference =
                                                          null;
                                                          provider.selectedReferenceId =
                                                          null;
                                                          provider.selectedReferenceValue =
                                                          null;
                                                        }
                                                        provider
                                                            .crmLeadListSourceOnReferenceAPIFunction(
                                                          context,
                                                          widget.mode,
                                                          provider
                                                              .selectedSourceId,
                                                        );
                                                      });
                                                    },
                                                    contentPadding:
                                                    EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                          ] else if (selectedIndex == 5) ...[
                                            if (provider
                                                .referencesList
                                                .isEmpty) ...[
                                              errorWidget(
                                                context,
                                                "Please Select Source First",
                                              ),
                                            ] else ...[
                                              ...provider.referencesList.map((
                                                  reference,
                                                  ) {
                                                if (reference == null ||
                                                    reference.id == null ||
                                                    reference.name == null)
                                                  return SizedBox.shrink();
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                    AppColors.app_blue,
                                                    controlAffinity:
                                                    ListTileControlAffinity
                                                        .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      reference.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                    provider
                                                        .selectedReference ==
                                                        reference,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        provider.selectedReference =
                                                        value == true
                                                            ? reference
                                                            : null;
                                                      });
                                                    },
                                                    contentPadding:
                                                    EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                            ],
                                          ] else if (selectedIndex == 6) ...[
                                            if (provider.teamsList.isEmpty)
                                              errorWidget(
                                                context,
                                                "No Teams Available",
                                              )
                                            else
                                              ...provider.teamsList.map((team) {
                                                if (team == null ||
                                                    team.id == null ||
                                                    team.name == null)
                                                  return SizedBox.shrink();
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                    AppColors.app_blue,
                                                    controlAffinity:
                                                    ListTileControlAffinity
                                                        .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      team.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                    provider.selectedTeam ==
                                                        team,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        if (value == true) {
                                                          provider.selectedTeam =
                                                              team;
                                                        } else {
                                                          provider.selectedTeam =
                                                          null;
                                                          provider.segmentsList
                                                              .clear();
                                                          provider.selectedSegment =
                                                          null;
                                                          provider.selectedSegmentId =
                                                          null;
                                                          provider.selectedSegmentValue =
                                                          null;
                                                        }
                                                        provider
                                                            .crmLeadListSegmentOnTeamAPIFunction(
                                                          context,
                                                          widget.mode,
                                                          provider
                                                              .selectedTeamId,
                                                        );
                                                      });
                                                    },
                                                    contentPadding:
                                                    EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                          ] else if (selectedIndex == 7) ...[
                                            if (provider
                                                .segmentsList
                                                .isEmpty) ...[
                                              errorWidget(
                                                context,
                                                "Please Select Team First",
                                              ),
                                            ] else ...[
                                              ...provider.segmentsList.map((
                                                  segment,
                                                  ) {
                                                if (segment == null ||
                                                    segment.id == null ||
                                                    segment.name == null)
                                                  return SizedBox.shrink();
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                    AppColors.app_blue,
                                                    controlAffinity:
                                                    ListTileControlAffinity
                                                        .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      segment.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                    provider
                                                        .selectedSegment ==
                                                        segment,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        provider.selectedSegment =
                                                        value == true
                                                            ? segment
                                                            : null;
                                                      });
                                                    },
                                                    contentPadding:
                                                    EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                            ],
                                          ] else if (widget.mode !=
                                              "executive") ...[
                                            if (provider.employeesList.isEmpty)
                                              errorWidget(
                                                context,
                                                "No Employees Available",
                                              )
                                            else
                                              ...provider.employeesList.map((
                                                  employee,
                                                  ) {
                                                if (employee == null ||
                                                    employee.id == null ||
                                                    employee.name == null)
                                                  return SizedBox.shrink();
                                                return SizedBox(
                                                  height: 35,
                                                  child: CheckboxListTile(
                                                    activeColor:
                                                    AppColors.app_blue,
                                                    controlAffinity:
                                                    ListTileControlAffinity
                                                        .leading,
                                                    checkboxShape: CircleBorder(
                                                      side: BorderSide(
                                                        width: 0.5,
                                                      ),
                                                    ),
                                                    title: Text(
                                                      employee.name!,
                                                      style: const TextStyle(
                                                        fontSize: 14,
                                                      ),
                                                    ),
                                                    value:
                                                    provider
                                                        .selectedEmployee ==
                                                        employee,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        provider.selectedEmployee =
                                                        value == true
                                                            ? employee
                                                            : null;
                                                      });
                                                    },
                                                    contentPadding:
                                                    EdgeInsets.zero,
                                                  ),
                                                );
                                              }).toList(),
                                          ],
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.symmetric(
                              horizontal: 15,
                              vertical: 20,
                            ),
                            child: InkResponse(
                              onTap: () {
                                provider.crmLeadListAPIFunction(
                                  context,
                                  widget.mode,
                                  provider.selectedLeadStatus,
                                  provider.selectedOpenStatus,
                                  provider.selectedSourceId,
                                  provider.selectedReferenceId,
                                  provider.selectedTeamId,
                                  provider.selectedSegmentId,
                                  provider.selectedAlphabet,
                                );
                                Navigator.pop(context);
                              },
                              child: Container(
                                height: 45,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: AppColors.app_blue,
                                  borderRadius: BorderRadius.circular(15),
                                ),
                                child: const Text(
                                  "Search",
                                  style: TextStyle(
                                    fontSize: 15,
                                    fontFamily: "JakartaMedium",
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                ),
              ),
            );
          },
        );
      },
    );
  }

  bool _isFilterSelected(Leadlistprovider provider, int index) {
    switch (index) {
      case 0:
        return provider.selectedLeadStatus != null;
      case 1:
        return provider.selectedOpenStatus != null;
      case 2:
        return provider.mobileNumberController.text.isNotEmpty;
      case 3:
        return provider.companyNameController.text.isNotEmpty;
      case 4:
        return provider.selectedSource != null;
      case 5:
        return provider.selectedReference != null;
      case 6:
        return provider.selectedTeam != null;
      case 7:
        return provider.selectedSegment != null;
      case 8:
        return provider.selectedEmployee != null;
      default:
        return false;
    }
  }
}
