import 'package:dropdown_search/dropdown_search.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';

import '../../../core/services/api_service.dart';
import '../../layouts/responsive_layout.dart';
import '../../providers/manager_provider.dart';
import '../../providers/userRoleProvider.dart';
import '../../themes/indicators/date_field_theme.dart';
import '../../themes/indicators/input_field_decoration.dart';

class DateFilterRowPayout extends ConsumerStatefulWidget {
  final TextEditingController startController;
  final String? selectedBroker;
  final List<dynamic>? selectedParnter;
  final String? selectedStaffId;
  final TextEditingController endController;
  final ValueChanged<String?>? onBrokerChanged;
  final ValueChanged<List<String>>? onPartnerChanges;
  final String? dataFrom;
  final VoidCallback onFilter;
  final VoidCallback onRefresh;
  final GlobalKey<FormState> formKey;
  final bool isMobile;
  final role;
  final id;

  const DateFilterRowPayout({
    super.key,
    required this.startController,
    required this.endController,
    required this.onFilter,
    required this.onRefresh,
    this.onBrokerChanged,
    this.onPartnerChanges,
    required this.selectedStaffId,
    required this.selectedParnter,
    this.selectedBroker,
    required this.formKey,
    required this.role,
    required this.id,
    this.isMobile = false,
    this.dataFrom,
  });

  @override
  ConsumerState<DateFilterRowPayout> createState() => _DateFilterRowState();
}

class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
  final GlobalKey<DropdownSearchState<Map<String, dynamic>>> dropDownKey =
      GlobalKey<DropdownSearchState<Map<String, dynamic>>>();

  final GlobalKey<DropdownSearchState<Map<String, dynamic>>> dropDownKeyBroker =
      GlobalKey<DropdownSearchState<Map<String, dynamic>>>();

  final GlobalKey<DropdownSearchState<Map<String, dynamic>>>
  dropDownKeyPartner = GlobalKey<DropdownSearchState<Map<String, dynamic>>>();

  late ApiService apiService;
  // List<dynamic>? selectedPartnerIds = [];
  List<Map<String, dynamic>> getPartnerData = [];
  List<Map<String, dynamic>> filteredPartnerData = [];

  List<Map<String, dynamic>> getBrokerData = [];
  List<Map<String, dynamic>> filteredBrokerData = [];

  String? selectedStaff;
  String? selectedBroker;
  String? selectedPartner;
  String? selectedStaffName;
  dynamic role;
  dynamic managerId;

  bool isLoading = false;
  bool isLoadingBroker = false;
  bool isLoadingAgentList = false;

  @override
  void initState() {
    super.initState();
    apiService = ApiService();

    Future.microtask(() {
      managerId = ref.watch(managerIdProvider);
      final userID = ref.watch(userIdProvider);
      role = ref.watch(userRoleProvider);
      print("managerId - $managerId");
      // if (userID != null && role != null) {
      //   print('hansles');
      //   getPartnerDetails(userID);
      // }

      if (managerId != null && widget.selectedBroker != null) {
        print('managerId - $managerId');
        print('SelectedBroker - $widget.selectedBroker');
        getAgentList(managerId,widget.selectedBroker);
      }
    });

    getBroker();
  }

  Future<void> getBroker() async {
    print('getBroker called');
    setState(() {
      isLoadingBroker = true;
    });

    try {
      final response = await apiService.fetchMasterDropDown('Broker');

      if (response['status'] == 200) {
        print('getBroker - ${response['data']}');
        setState(() {
          getBrokerData = List<Map<String, dynamic>>.from(response['data']);
          print('API Data - $getBrokerData');

          filteredBrokerData = List.from(getBrokerData);
          print('originalData - $filteredBrokerData');
        });
      } else {
        getBrokerData = [];
        filteredBrokerData = [];
      }
    } catch (e) {
      print('Exception occurred: $e');
    } finally {
      setState(() {
        isLoadingBroker = false;
      });
    }
  }

  Future<void> getAgentList(id,broker_id) async {

    print('getAgentListData called');
    setState(() {
      isLoadingAgentList = true;
    });

    try {
      final response = await apiService.fetchAgentUnusedCommissionList(id,broker_id);
      print('getAgentListData called response');
      print('get Agent- ${response['data']}');
      if (response['status'] == 'success') {
        print('get Agent- ${response['data']}');
        setState(() {
          // 1. Convert the response to a list
          final rawList = List<Map<String, dynamic>>.from(response['data']);
          print('API Data - rawList');
          // 2. Filter out items where agent_id is null or empty
          getPartnerData = rawList.where((item) {
            final id = item['agent_id'];
            return id != null && id.toString().isNotEmpty;
          }).toList();
          print('Filtered API Data (No Null IDs) - $getPartnerData');
          // 3. Sync the filtered data to your display list
          filteredPartnerData = List.from(getPartnerData);
        });
      } else {
        getPartnerData = [];
        filteredPartnerData = [];
      }
    } catch (e) {
      print('Exception occurred: $e');
    } finally {
      setState(() {
        isLoadingAgentList = false;
      });
    }
  }

  // Future<void> getPartnerDetails(int id) async {
  //   print('getPartnerDetails called By handler');
  //   setState(() {
  //     isLoading = true;
  //   });
  //
  //   try {
  //     // final response = await apiService.fetchStaffUserList(id, role);
  //     final response = await apiService.fetchStaffListForEnquiryAssignDropDown(
  //       managerId,
  //       id,
  //       role,
  //     );
  //     if (response['status'] == 'success') {
  //       print('getStaffDetails - ${response['data']}');
  //       setState(() {
  //         getPartnerData = List<Map<String, dynamic>>.from(response['data']);
  //         print('API Data - $getPartnerData');
  //
  //         filteredPartnerData = List.from(getPartnerData);
  //         print('originalData - $filteredPartnerData');
  //       });
  //     } else {
  //       getPartnerData = [];
  //       filteredPartnerData = [];
  //     }
  //   } catch (e) {
  //     print('Exception occurred: $e');
  //   } finally {
  //     setState(() {
  //       isLoading = false;
  //     });
  //   }
  // }

  @override
  Widget build(BuildContext context) {
    final spacing = 5.0;

    List<Widget> getRowChildren(bool isMobile, double spacing) {
      final dateFields = [
        buildStartDate(context),
        SizedBox(width: spacing),
        buildEndDate(context),
        SizedBox(width: spacing),
        buildBroker(context),
        SizedBox(width: spacing),
        buildPartner(context),
        SizedBox(width: spacing),
      ];

      final buttons = [
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 0.0),
          // child: GestureDetector(
          //   onTap: () {
          //     if (formKey.currentState!.validate()) onFilter();
          //   },
          //   child: Icon(Icons.filter_alt_outlined),
          // ),
          child: Tooltip(
            message: 'Filter',
            child: IconButton(
              icon: const Icon(
                Icons.search_rounded,
                size: 18,
                color: const Color(0xFF94A3B8),
              ),

              onPressed: () {
                if (widget.formKey.currentState!.validate()) {
                  widget.onFilter();
                }
              },
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(0.0),
          // child: GestureDetector(onTap: onRefresh, child: Icon(Icons.refresh)),
          child: Tooltip(
            message: 'Refresh',
            child: IconButton(
              onPressed: widget.onRefresh,
              icon: const Icon(
                Icons.refresh,
                size: 18,
                color: const Color(0xFF94A3B8),
              ),
            ),
          ),
        ),
      ];

      if (isMobile) {
        // For mobile: buttons below fields
        return [
          ...dateFields,
          SizedBox(height: 10),
          Row(mainAxisAlignment: MainAxisAlignment.end, children: buttons),
        ];
      } else {
        // For desktop: buttons inline with fields
        return [...dateFields, Spacer(), ...buttons];
      }
    }

    return Form(
      key: widget.formKey,
      child: widget.isMobile
          ? Column(
              crossAxisAlignment: CrossAxisAlignment.start,

              children: getRowChildren(widget.isMobile, spacing),
            )
          : Row(
              crossAxisAlignment: CrossAxisAlignment.end,

              children: getRowChildren(widget.isMobile, spacing),
            ),
    );
  }

  Widget buildStartDate(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('Start Date *', style: _textStyle),
        SizedBox(height: 5),
        SizedBox(
          height: 35,
          child: ThemedDateField(
            hintText: "Select Date",
            txtwidth: ResponsiveLayout.isMobile(context)
                ? null
                : MediaQuery.of(context).size.width * 0.15,
            // txtheight: 50,
            // backgroundColor: const Color(0xFFECECEC),
            // validator: (value) => Validators.requiredField(value, "date"),
            controller: widget.startController,
            onDateSelected: (date) {
              print("Picked Date: $date");
              widget.startController.text = DateFormat(
                'dd-MM-yyyy',
              ).format(date);
              //  controllers['date']?.text = date as String;
              Future.microtask(() => widget.onFilter());
            },
          ),
        ),
      ],
    );
  }

  Widget buildEndDate(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('End Date *', style: _textStyle),
        SizedBox(height: 5),
        SizedBox(
          height: 35,
          child: ThemedDateField(
            hintText: "Select Date",
            txtwidth: ResponsiveLayout.isMobile(context)
                ? null
                : MediaQuery.of(context).size.width * 0.15,
            // txtheight: 50,
            // backgroundColor: const Color(0xFFECECEC),
            validator: (value) {
              final fromText = widget.startController.text ?? '';
              if (fromText.isNotEmpty) {
                final startDate = DateFormat('dd-MM-yyyy').parse(fromText);
                if (value == null || value.isEmpty) {
                  return "End Date is required";
                }
                final endDate = DateFormat('dd-MM-yyyy').parse(value);

                if (endDate.isBefore(startDate)) {
                  return "End Date cannot be earlier than Start Date";
                }
              }
              return null; // ✅ no error
            },
            controller: widget.endController,
            // lastDate: DateTime.now(),
            onDateSelected: (date) {
              print("Picked Date: $date");
              widget.endController.text = DateFormat('dd-MM-yyyy').format(date);
              Future.microtask(() => widget.onFilter());
              //  controllers['date']?.text = date as String;
            },
          ),
        ),
      ],
    );
  }

  Widget buildBroker(BuildContext context) {
    Map<String, dynamic>? selectedBrokers = filteredBrokerData.firstWhere(
      (item) => item['id'].toString() == widget.selectedBroker,
      orElse: () => {},
    );
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('Broker *', style: _textStyle),
        SizedBox(height: 5),
        SizedBox(
          height: 35,
          width: MediaQuery.of(context).size.width * 0.15,
          child: DropdownSearch<Map<String, dynamic>>(
            key: dropDownKeyBroker,
            selectedItem: selectedBrokers.isNotEmpty ? selectedBrokers : null,
            items: (filter, infiniteScrollProps) {
              return filteredBrokerData;
            },

            itemAsString: (val) => val['name'].toString(), // what to show
            compareFn: (item, selectedItem) =>
                item['id'] == selectedItem['id'], // ✅ compare by id
            // validator: (val) {
            //   if (val == null) {
            //     return "Required"; // ✅ error message
            //   }
            //   return null;
            // },
            suffixProps: DropdownSuffixProps(
              // make sure the dropdown button is visible
              dropdownButtonProps: DropdownButtonProps(
                isVisible: true,
                padding: EdgeInsets.zero, // remove default padding
                constraints: const BoxConstraints(
                  // shrink icon tap area
                  minWidth: 12,
                  minHeight: 12,
                ),
                iconSize: 15, // smaller icon
                // icon: const Icon(Icons.arrow_drop_down),
              ),
            ),
            dropdownBuilder: (context, selectedItem) => Align(
              alignment: Alignment.centerLeft,
              child: Text(
                selectedItem != null ? selectedItem['name'].toString() : "",
                style: GoogleFonts.poppins(
                  fontSize: 11,
                  color: Colors.black,
                  // color: Color(0XFF6366F1),
                ),
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                softWrap: false,
              ),
            ),
            decoratorProps: DropDownDecoratorProps(
              decoration:
                  AppInputDecorations.dropdownDecoration(
                    label: "Broker",
                  ).copyWith(
                    filled: true,
                    fillColor:
                        Colors.white, // 👈 makes the dropdown input white
                    isDense: true,
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(5),
                      borderSide: const BorderSide(
                        color: Color(0xFFE2E8F0),
                        width: 0.1,
                      ),
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(5),
                      borderSide: const BorderSide(
                        color: Color(0xFFE2E8F0),
                        width: 0.5,
                      ),
                    ),
                    contentPadding: EdgeInsets.symmetric(
                      horizontal: 8,
                      vertical: 6,
                    ),
                  ),
            ),

            popupProps: PopupProps.menu(
              fit: FlexFit.loose,
              constraints: BoxConstraints(maxHeight: 250),
              menuProps: MenuProps(
                backgroundColor:
                    Colors.white, // 👈 sets dropdown background to white
              ),
              showSearchBox: true,
              searchFieldProps: TextFieldProps(
                autofocus: true,
                style: GoogleFonts.inter(fontSize: 11, color: Colors.black),
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(1),
                  filled: true,
                  fillColor: Colors.white,
                  hintText: "Search Broker...",
                  hintStyle: GoogleFonts.inter(
                    fontSize: 12,
                    color: Colors.black,
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.white,
                    ), // 👈 Normal border
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.white,
                      width: 1.5,
                    ), // 👈 Focused border
                  ),
                ),
              ),

              itemBuilder: (context, item, isDisabled, isSelected) {
                return Container(
                  // color: isSelected ? Colors.blue.withOpacity(0.1) : null,
                  padding: const EdgeInsets.symmetric(
                    horizontal: 8,
                    vertical: 3,
                  ),
                  child: Text(
                    item['name'].toString(),
                    style: GoogleFonts.inter(fontSize: 12, color: Colors.black),
                  ),
                );
              },
              // constraints: BoxConstraints(),
            ),
            // onChanged: (val) {
            //   if (val != null) {
            //     print("Selected Broker : ${val['name']}");
            //     print("Id: ${val['id']}");
            //     // selectedBroker = val['id'];
            //     widget.onBrokerChanged?.call(val['id'].toString());
            //     // widget.onBrokerChanged?.call(val['id']);
            //     // controllers['agentId']?.text = val['agent_code'];
            //     // agentId = agent['id'];
            //   }
            // },
            onChanged: (val) {
              if (val != null) {
                String selectedId = val['id'].toString();

                // 1. Notify parent of the change
                widget.onBrokerChanged?.call(selectedId);

                // 2. Clear current partner list so user doesn't see old data
                setState(() {
                  filteredPartnerData = [];
                });

                // 3. Fetch new agents based on this broker
                getAgentList(managerId!, selectedId);
              }
            },


          ),
        ),
      ],
    );
  }

  Widget buildPartner(BuildContext context) {
    final isReadOnly = false;

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("Referer", style: _textStyle),
        SizedBox(height: 5),
        SizedBox(
          height: 35,
          width: MediaQuery.of(context).size.width * 0.4,
          child: DropdownSearch<Map<String, dynamic>>.multiSelection(
            key: dropDownKeyPartner,

            // selectedItem: selectedHandlered.isNotEmpty
            //     ? selectedHandlered
            //     : null,
            selectedItems: filteredPartnerData
                .where(
                  (item) => (widget.selectedParnter ?? []).contains(item['agent_id']),
                )
                .toList(),

            // selectedItems: filteredPartnerData
            //     .where(
            //       (item) => (selectedPartnerIds ?? []).contains(item['id']),
            //     )
            //     .toList(),
            items: (filter, infiniteScrollProps) {
              return filteredPartnerData;
            },

            itemAsString: (val) =>  // what to show
            "${val['agent_name']} | ${val['unused_commission_amount']} (${val['total_policies']})",
            compareFn: (item, selectedItem) =>
                item['agent_id'] == selectedItem['agent_id'], // ✅ compare by id
            // validator: (val) {
            //   if (val == null) {
            //     return "Required"; // ✅ error message
            //   }
            //   return null;
            // },
            // validator: (val) {
            //   if (val == null || val.isEmpty) {
            //     return ""; // 👈 triggers error border, no text
            //   }
            //   return null;
            //
            //   // if (val == null || val.isEmpty) {
            //   //   return "Required";
            //   // }
            //   // return null;
            // },

            decoratorProps: DropDownDecoratorProps(
              decoration:
                  AppInputDecorations.dropdownDecoration(
                    label: "Select Referer",
                  ).copyWith(
                    hintStyle: GoogleFonts.inter(
                      fontSize: 12,
                      color: Colors.black,
                    ),
                    filled: true,
                    errorStyle: const TextStyle(height: 0, fontSize: 0),
                    fillColor:
                        Colors.white, // 👈 makes the dropdown input white
                    enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                        color: Color(0xFFE2E8F0),
                        // color: Colors.white,
                      ), // 👈 Normal border
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                        color: Color(0xFFE2E8F0),
                        // color: Colors.white,
                        width: 1.5,
                      ), // 👈 Focused border
                    ),

                    contentPadding: EdgeInsets.symmetric(
                      horizontal: 8,
                      vertical: 6,
                    ),
                  ),
            ),
            popupProps: PopupPropsMultiSelection.menu(
              fit: FlexFit.loose,
              constraints: BoxConstraints(maxHeight: 250),
              showSearchBox: true,
              menuProps: MenuProps(backgroundColor: Colors.white),

              searchFieldProps: TextFieldProps(
                autofocus: true,
                decoration: InputDecoration(
                  filled: true,
                  fillColor: Colors.white,
                  hintText: "Search Referer...",
                  hintStyle: GoogleFonts.inter(
                    fontSize: 11,
                    color: Colors.black,
                  ),

                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.white),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      // color: Colors.blue,
                      color: Color(0xFFEDF6F5),
                      width: 1.5,
                    ),
                  ),
                ),
              ),

              itemBuilder: (context, item, isDisabled, isSelected) {
                return Container(
                  // color: isSelected ? Colors.blue.withOpacity(0.1) : null,
                  padding: const EdgeInsets.symmetric(
                    horizontal: 8,
                    vertical: 3,
                  ),
                  child: Text(
                    "${item['agent_name']} | ${item['unused_commission_amount']} (${item['total_policies']})",
                    style: GoogleFonts.inter(fontSize: 12, color: Colors.black),
                  ),
                );
              },
            ),

            onChanged: (List<Map<String, dynamic>> selectedVals) {
              // selectedPartnerIds = selectedVals
              //     .map((v) => v['id'].toString())
              //     .toList();
              final ids = selectedVals.map((v) => v['agent_id'].toString()).toList();
              print("Selected PArnter IDs: $widget.selectedPartnerIds");
              widget.onPartnerChanges?.call(ids);
              // widget.onPartnerChanges!(v['id']);
            },
          ),
        ),
      ],
    );
  }

  // Widget buildSelectStaffMem(BuildContext context) {
  //   Map<String, dynamic>? selectedVehicle;
  //   if (widget.selectedStaffId == null) {
  //     selectedVehicle = null;
  //   } else if (widget.selectedStaffId != null) {
  //     selectedVehicle = filteredPartnerData.firstWhere(
  //       (item) => item['id'] == widget.selectedStaffId,
  //       orElse: () => {}, // empty map
  //     );
  //     if (selectedVehicle.isEmpty) selectedVehicle = null;
  //   } else if (selectedStaff != null) {
  //     selectedVehicle = filteredPartnerData.firstWhere(
  //       (item) => item['id'] == selectedStaff,
  //       orElse: () => {}, // empty map
  //     );
  //     if (selectedVehicle.isEmpty) selectedVehicle = null;
  //   } else {
  //     selectedVehicle = null;
  //   }
  //   return Column(
  //     crossAxisAlignment: CrossAxisAlignment.start,
  //     children: [
  //       // Text("Staff Name", style: _textStyle),
  //       // SizedBox(height: 10),
  //       SizedBox(
  //         height: 35,
  //         child: Container(
  //           decoration: BoxDecoration(
  //             borderRadius: BorderRadius.circular(5.0),
  //             border: Border.all(color: Color(0xFFE2E8F0)),
  //             // color: Colors.black,
  //           ),
  //
  //           width: ResponsiveLayout.isMobile(context)
  //               ? null
  //               : MediaQuery.of(context).size.width * 0.13,
  //           // height: 45,
  //           child: DropdownSearch<Map<String, dynamic>>(
  //             // key: dropDownKey,
  //             key: ValueKey(selectedStaff),
  //             // selectedItem: selectedVehicle.isNotEmpty ? selectedVehicle : null,
  //             selectedItem: selectedVehicle,
  //
  //             items: (filter, infiniteScrollProps) {
  //               return filteredPartnerData;
  //             },
  //
  //             itemAsString: (val) => val['name'].toString(),
  //             compareFn: (item, selectedItem) =>
  //                 item['id'] == selectedItem['id'], // ✅ compare by id
  //             dropdownBuilder: (context, selectedItem) => Align(
  //               alignment: Alignment.centerLeft,
  //               child: Text(
  //                 selectedItem != null ? selectedItem['name'].toString() : "",
  //                 style: GoogleFonts.poppins(fontSize: 11, color: Colors.black),
  //                 overflow: TextOverflow.ellipsis,
  //                 maxLines: 1,
  //                 softWrap: false,
  //               ),
  //             ),
  //             decoratorProps: DropDownDecoratorProps(
  //               decoration:
  //                   AppInputDecorations.dropdownDecoration(
  //                     label: "Select Staff ",
  //                   ).copyWith(
  //                     filled: true,
  //                     fillColor:
  //                         Colors.white, // 👈 makes the dropdown input white
  //                     contentPadding: const EdgeInsets.symmetric(
  //                       horizontal: 6,
  //                       vertical: 1, // 👈 adjust this to make the field shorter
  //                     ),
  //                   ),
  //             ),
  //
  //             popupProps: PopupProps.menu(
  //               fit: FlexFit.loose,
  //               constraints: BoxConstraints(maxHeight: 250),
  //               menuProps: MenuProps(
  //                 backgroundColor:
  //                     Colors.white, // 👈 sets dropdown background to white
  //               ),
  //               showSearchBox: true,
  //               searchFieldProps: TextFieldProps(
  //                 decoration: InputDecoration(
  //                   filled: true,
  //                   fillColor: Colors.white,
  //                   hintText: "Search Staff ...",
  //                   hintStyle: GoogleFonts.inter(
  //                     fontSize: 12,
  //                     color: Colors.black,
  //                   ),
  //                   enabledBorder: OutlineInputBorder(
  //                     borderSide: BorderSide(
  //                       color: Colors.white,
  //                     ), // 👈 Normal border
  //                   ),
  //                   focusedBorder: OutlineInputBorder(
  //                     borderSide: BorderSide(
  //                       color: Colors.white,
  //                       width: 1.5,
  //                     ), // 👈 Focused border
  //                   ),
  //                 ),
  //               ),
  //
  //               itemBuilder: (context, item, isDisabled, isSelected) {
  //                 return Container(
  //                   // color: isSelected ? Colors.blue.withOpacity(0.1) : null,
  //                   padding: const EdgeInsets.symmetric(
  //                     horizontal: 8,
  //                     vertical: 3,
  //                   ),
  //                   child: Text(
  //                     item['name'].toString(),
  //                     style: GoogleFonts.inter(
  //                       fontSize: 13,
  //                       color: Colors.black,
  //                     ),
  //                   ),
  //                 );
  //               },
  //
  //               // constraints: BoxConstraints(),
  //             ),
  //
  //             onChanged: (val) {
  //               if (val != null) {
  //                 print("Selected Staff : ${val['name']}");
  //                 print("Id: ${val['id']}");
  //                 // selectedStaffName = val['name'];
  //                 // selectedStaff = val['id'];
  //                 widget.onBrokerChanged!(val['id']);
  //                 // if (widget.onFilterStaff != null)
  //                 //   widget.onFilterStaff!(val['id']);
  //
  //                 // Future.microtask(() => widget.onFilter());
  //                 // controllers['agentId']?.text = val['agent_code'];
  //                 // agentId = agent['id'];
  //               }
  //             },
  //           ),
  //         ),
  //       ),
  //     ],
  //   );
  // }

  static final _textStyle = GoogleFonts.poppins(
    fontSize: 11,
    fontWeight: FontWeight.w500,
  );
}
