// import 'package:absenkuv3/Bloc/AuthBloc.dart';
// import 'package:absenkuv3/Bloc/FilterBottomSheetBloc.dart';
// import 'package:absenkuv3/Bloc/NavigatorBloc.dart';
// import 'package:absenkuv3/Repository/Model/mDropdown.dart';
// import 'package:absenkuv3/Repository/Model/mFilter.dart';
// import 'package:absenkuv3/Repository/Model/mLogin.dart';
// import 'package:absenkuv3/Setting/PengaturanBahasa.dart';
// import 'package:absenkuv3/UI/Modul/Absensi/KomponenAbsensi.dart';
// import 'package:absenkuv3/UI/Template/AutoComplete/Bloc/AutoCompleteFilterPerusahaanBloc.dart';
// import 'package:absenkuv3/UI/Template/AutoComplete/Bloc/AutoCompletePegawaiBawahanBloc.dart';
// import 'package:absenkuv3/UI/Template/AutoComplete/UI/AutoCompletePegawaiBawahan.dart';
// import 'package:absenkuv3/UI/Template/AutoComplete/UI/AutoCompletePerusahaanFilterKanban.dart';
// import 'package:absenkuv3/UI/Template/DateRangePicker/Bloc/DateRangePickerBloc.dart' as dateRangePicker;
// import 'package:absenkuv3/UI/Template/DateRangePicker/UI/templateDateRangePicker.dart';
// import 'package:absenkuv3/UI/Template/DateRangePicker/UI/templateNewDateRangePicker.dart';
// import 'package:absenkuv3/UI/Template/MonthPicker/UI/templateMonthPicker.dart';
// import 'package:absenkuv3/UI/Template/MonthPicker/UI/templateMonthPickerNonFloating.dart';
// import 'package:absenkuv3/UI/Template/MonthPicker/UI/templateNewMonthPicker.dart';
// import 'package:absenkuv3/UI/Template/style.dart';
// import 'package:absenkuv3/UI/Template/templateButton.dart';
// import 'package:autocomplete_textfield/autocomplete_textfield.dart';
// import 'package:flutter/material.dart';
// import 'package:flutter_bloc/flutter_bloc.dart';
// import 'MonthPicker/Bloc/MonthPickerBloc.dart' as monthPicker;
// import 'MonthPicker/Bloc/MonthPickerBloc.dart';
//
// class FilterBottomSheetKanban extends StatefulWidget {
//   bool adaFilterTanggal;
//   bool adaFilterStatus;
//   bool adaFilterRangeTanggal;
//   // DateTime? monthYears;
//   ModelFilter? modelFilter;
//   FilterBottomSheetKanban(this.modelFilter, {this.adaFilterTanggal=true, this.adaFilterStatus=false, this.adaFilterRangeTanggal=true});
//   @override
//   _FilterBottomSheetKanbanState createState() => _FilterBottomSheetKanbanState();
// }
//
// class _FilterBottomSheetKanbanState extends State<FilterBottomSheetKanban> {
//   DataDropdown? dataPegawai;
//   List<DataDropdown>? listDataPegawai;
//   DataDropdown? dataPerusahaan;
//   DataDropdown? dataStatus;
//   DateTime? monthYear;
//   List<DateTime>? dateRange;
//   TextEditingController _valueControllerPegawai = TextEditingController();
//   GlobalKey<AutoCompleteTextFieldState<DataDropdown>> key =
//   GlobalKey<AutoCompleteTextFieldState<DataDropdown>>();
//   // ModelFilter? modelFilter;
//
//   @override
//   void initState() {
//     // TODO: implement initState
//     super.initState();
//     initialFilter();
//     // modelFilter!.monthYear = widget.monthYears;
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return BlocProvider(create: (context) {
//       return monthPicker.MonthPickerBloc(MonthPickerProgressState());
//     },
//     child: BlocBuilder<AuthBloc, LoginRespon>(
//         builder: (BuildContext context, LoginRespon loginRespon){
//           return TombolIcon(
//             onClick: ()=>_settingModalBottomSheet(loginRespon),
//             icon : Icons.filter_alt,
//             bgnColor: Colors.white,
//             size: 32,
//             iconColor: CustomStyle.color1,);
//         }),
//       );
//     }
//
//     void initialFilter(){
//       // if(widget.monthYears != null){
//       //   modelFilter = ModelFilter(monthYear: widget.monthYears);
//       // }else{
//       //   if(widget.adaFilterRangeTanggal){
//       //     modelFilter = ModelFilter(dateRange: [DateTime.now(), DateTime.now()]);
//       //   }else{
//       //     modelFilter = null;
//       //   }
//       // }
//       if(widget.modelFilter!.monthYear == null){
//         widget.modelFilter!.monthYear = DateTime.now();
//       }
//       print("modelfilternya : ${widget.modelFilter!.monthYear}");
//       BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(SetFilterPerusahaan(null));
//       BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(GetFilterPerusahaan(""));
//       BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(GetPegawaiBawahan(null));
//       // BlocProvider.of<cabang.DropdownCabangBloc>(context).add(cabang.GetDataDropdown());
//       // BlocProvider.of<departemen.DropdownDepartemenBloc>(context).add(departemen.GetDataDropdown());
//       BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.SetDate([DateTime.now(),DateTime.now()]));
//       BlocProvider.of<monthPicker.MonthPickerBloc>(context).add(monthPicker.SetDate(widget.modelFilter!.monthYear));
//       // BlocProvider.of<monthPicker.MonthPickerBloc>(context).add(monthPicker.SetDate(selectedDateTime));
//       // BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.InitialDate());
//       // BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.InitialDate());
//       // if(widget.adaFilterStatus) BlocProvider.of<status.DropdownStatusBloc>(context).add(status.GetDataDropdown());
//     }
//     void resetFilter(){
//       // if(widget.monthYears != null){
//       //   modelFilter = ModelFilter(monthYear: widget.monthYears);
//       // }else{
//       //   if(widget.adaFilterRangeTanggal){
//       //     modelFilter = ModelFilter(dateRange: [DateTime.now(), DateTime.now()]);
//       //   }else{
//       //     modelFilter = null;
//       //   }
//       // }
//       widget.modelFilter = ModelFilter();
//       widget.modelFilter!.monthYear = DateTime.now();
//       BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.SetDate([DateTime.now(),DateTime.now()]));
//       BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(SetFilterPerusahaan(null));
//       BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(SetPegawaiBawahan(null));
//       // BlocProvider.of<cabang.DropdownCabangBloc>(context).add(cabang.SelectDataDropdown(null));
//       // BlocProvider.of<departemen.DropdownDepartemenBloc>(context).add(departemen.SelectDataDropdown(null));
//       BlocProvider.of<monthPicker.MonthPickerBloc>(context).add(monthPicker.SetDate(DateTime.now()));
//       // BlocProvider.of<FilterBottomSheetBloc>(context).add(setFilterBottomSheet(modelFilter));
//       // BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.InitialDate());
//       // if(widget.adaFilterStatus) BlocProvider.of<status.DropdownStatusBloc>(context).add(status.GetDataDropdown());
//     }
//
//     void _settingModalBottomSheet(LoginRespon loginRespon){
//
//     showModalBottomSheet(
//         backgroundColor: Colors.white,
//         elevation: 0,
//         context: context,
//         isDismissible: false,
//         isScrollControlled: true,
//         showDragHandle: true,
//         shape: RoundedRectangleBorder(
//             borderRadius: BorderRadius.circular(18)
//         ),
//         builder: (context) => StatefulBuilder(
//             builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
//               return FutureBuilder<String>(
//                   future: PengaturanBahasa().getDataBahasa(),
//                   builder: (context, snapshot) {
//                     return SingleChildScrollView(
//                       child: Padding(
//                         padding: EdgeInsets.only(
//                             bottom: MediaQuery.of(context).viewInsets.bottom),
//                         child: ConstrainedBox(
//                           constraints: BoxConstraints(
//                               minHeight: widget.adaFilterTanggal?MediaQuery.of(context).size.height/3:MediaQuery.of(context).size.height/4
//                           ),
//                           child: Container(
//                             color: Colors.white,
//                             margin: EdgeInsets.fromLTRB(27, 0, 27, 14),
//                             child: Column(
//                               children: [
//                                 Row(
//                                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
//                                   children: [
//                                   Text(snapshot.data == null || snapshot.data == 'en' ? "Search Filters" : "Filter Pencarian", style: TextStyle(color: CustomStyle.fontColorBlack, fontSize: 14, fontWeight: FontWeight.w700),),
//                                   SizedBox(width: 8,),
//                                   GestureDetector(
//                                       onTap: (){
//                                         BlocProvider.of<NavigatorBloc>(context).add(NavigatePop(context));
//                                         resetFilter();
//                                       },
//                                       child: Icon(Icons.close, color: CustomStyle.fontColorBlack, size: 21,)),
//                                 ],),
//                                 SizedBox(height: 24),
//                                 BlocBuilder<FilterBottomSheetBloc, FilterBottomSheetState>(builder: (context, filterBottomSheetState){
//                                   if(filterBottomSheetState is setFilterSuccess){
//                                     return BlocListener<AutoCompleteFilterPerusahaanBloc, AutoCompleteFilterPerusahaanState>(
//                                       listener: (BuildContext context, AutoCompleteFilterPerusahaanState state){
//                                         if(state is SetFilterPerusahaanSuccess) dataPerusahaan = state.perusahaan;
//                                       },
//                                       // child: AutoCompletePerusahaanFilterKanban(filterBottomSheetState.modelFilter, fontSize:CustomStyle.fontSizeSmall,radius: 14, formHeight: 41, title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',),
//                                       child: AutoCompletePerusahaanFilterKanban(
//                                         filterBottomSheetState.modelFilter,
//                                         snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',
//                                         fontSize:CustomStyle.fontSizeSmall,
//                                         formHeight: 34,
//                                         // initialData: filterBottomSheetState.modelFilter!=null
//                                         //     ? filterBottomSheetState.modelFilter!.namaPerusahaan??null
//                                         //     : null,
//                                         initialData: dataPerusahaan==null?null:dataPerusahaan!.nama,
//                                         // prefixIcon: Icon(Icons.search, size: 20)
//                                       ),
//                                     );
//                                   }
//
//                                   else  return BlocListener<AutoCompleteFilterPerusahaanBloc, AutoCompleteFilterPerusahaanState>(
//                                     listener: (BuildContext context, AutoCompleteFilterPerusahaanState state){
//                                       if(state is SetFilterPerusahaanSuccess) dataPerusahaan = state.perusahaan;
//                                     },
//                                     // child: AutoCompletePerusahaanFilterKanban(null, fontSize:CustomStyle.fontSizeSmall,radius: 14, formHeight: 41, title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan'),
//                                     child: AutoCompletePerusahaanFilterKanban(
//                                       null,
//                                       snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',
//                                       fontSize:CustomStyle.fontSizeSmall,
//                                       formHeight: 34,
//                                       // prefixIcon: Icon(Icons.search, size: 20)
//                                     ),
//                                   );
//                                 }),
//                                 // SizedBox(height: 24),
//                                 !loginRespon.dataLogin!.adminAtasan! ? Container() :
//                                 BlocBuilder<FilterBottomSheetBloc, FilterBottomSheetState>(builder: (context, filterBottomSheetState){
//                                     return BlocBuilder<AutoCompletePegawaiBawahanBloc, AutoCompletePegawaiBawahanState>(
//                                       builder: (BuildContext context, AutoCompletePegawaiBawahanState state){
//                                         if(state is SetPegawaiBawahanSuccess) {
//                                           dataPegawai = state.pegawaiBawahan;
//                                           _valueControllerPegawai.text = dataPegawai!.nama!;
//                                         }
//                                         else if(state is GetPegawaiBawahanSuccess) listDataPegawai = state.listPegawaiBawahan;
//
//                                         // return AutoCompletePegawaiBawahan(
//                                         //     widget.modelFilter,
//                                         //     snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
//                                         //     fontSize:CustomStyle.fontSizeSmall,
//                                         //     formHeight: 34,
//                                         //     // initialData: filterBottomSheetState.modelFilter!=null
//                                         //     //     ? filterBottomSheetState.modelFilter!.namaPegawai??null
//                                         //     //     : null,
//                                         //     initialData: dataPegawai==null?null:dataPegawai!.nama,
//                                         //     // prefixIcon: Icon(Icons.search, size: 20)
//                                         // );
//
//                                         return Container(
//                                           margin: EdgeInsets.only(bottom: 13),
//                                           child: InputDecorator(
//                                             decoration: InputDecoration(
//                                                 label: Row(
//                                                   children: [
//                                                     Text("Sales"),
//                                                     SizedBox(width: 7),
//                                                     // Text("*", style: TextStyle(color: Colors.red),),
//                                                   ],
//                                                 ),
//                                                 contentPadding: EdgeInsets.only(bottom: 0),
//                                                 enabledBorder: InputBorder.none
//                                               // enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: CustomStyle.colorLineFormDropdown)),
//                                             ),
//                                             child:
//                                             Autocomplete<DataDropdown>(
//                                                 displayStringForOption: (option) => option.nama!,
//                                                 optionsBuilder: (TextEditingValue tectEditingValue){
//                                                   if(listDataPegawai != null){
//                                                     return listDataPegawai!.where((DataDropdown option){
//                                                       return option.nama!.toLowerCase().contains(tectEditingValue.text.toLowerCase());
//                                                     }).toList();
//
//                                                   }else{
//                                                     return Iterable<DataDropdown>.empty();
//                                                   }
//
//                                                 },
//                                                 initialValue: _valueControllerPegawai.value,
//
//                                                 onSelected: (DataDropdown val){
//                                                   BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(SetPegawaiBawahan(val));
//                                                 }
//                                             ),
//                                           ),
//                                         );
//                                       },
//                                       // child: AutoCompletePegawaiBawahan(
//                                       //   filterBottomSheetState.modelFilter,
//                                       //   fontSize:CustomStyle.fontSizeSmall,
//                                       //   radius: 14,
//                                       //   formHeight: 34,
//                                       //   title: snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
//                                       //   prefixIcon: Icon(Icons.search, size: 20)),
//
//
//                                       // AutoCompletePegawaiBawahan(
//                                       //   filterBottomSheetState.modelFilter,
//                                       //   snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
//                                       //   fontSize:CustomStyle.fontSizeSmall,
//                                       //   formHeight: 34,
//                                       //   // initialData: filterBottomSheetState.modelFilter!=null
//                                       //   //     ? filterBottomSheetState.modelFilter!.namaPegawai??null
//                                       //   //     : null,
//                                       //   initialData: dataPegawai==null?null:dataPegawai!.nama,
//                                       //   // prefixIcon: Icon(Icons.search, size: 20)
//                                       // ),
//                                     );
//                                   // }
//
//                                   // else  return BlocListener<AutoCompletePegawaiBawahanBloc, AutoCompletePegawaiBawahanState>(
//                                   //   listener: (BuildContext context, AutoCompletePegawaiBawahanState state){
//                                   //     if(state is SetPegawaiBawahanSuccess) dataPegawai = state.pegawaiBawahan;
//                                   //   },
//                                   //   // child: AutoCompletePegawaiBawahan(
//                                   //   //   null,
//                                   //   //   fontSize:CustomStyle.fontSizeSmall,
//                                   //   //   radius: 14,
//                                   //   //   formHeight: 41,
//                                   //   //   title: snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
//                                   //   //   prefixIcon: Icon(Icons.search, size: 20)),
//                                   //   child: AutoCompletePegawaiBawahan(
//                                   //     null,
//                                   //     snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
//                                   //     fontSize:CustomStyle.fontSizeSmall,
//                                   //     formHeight: 34,
//                                   //     // prefixIcon: Icon(Icons.search, size: 20)
//                                   //   ),
//                                   // );
//                                 }),
//                                 widget.adaFilterRangeTanggal?Container(
//                                   margin: EdgeInsets.only(bottom: 12),
//                                   child: Column(
//                                     crossAxisAlignment: CrossAxisAlignment.start,
//                                     children: [
//                                       // Padding(
//                                       //   padding: const EdgeInsets.only(bottom: 8, left: 11),
//                                       //   child: Text(
//                                       //     snapshot.data == null || snapshot.data == 'en' ? 'Date' : 'Tanggal',
//                                       //     style: TextStyle(color: Colors.grey, fontWeight: FontWeight.w500, fontSize: CustomStyle.fontSizeSmall),
//                                       //   ),
//                                       // ),
//                                       BlocListener<dateRangePicker.DateRangePickerBloc, dateRangePicker.DateRangePickerState>(
//                                         listener: (BuildContext context, dateRangePicker.DateRangePickerState dateRangePickerState){
//                                           if(dateRangePickerState is dateRangePicker.DateAvailable) {
//                                             dateRange = dateRangePickerState.date;
//                                           }
//                                         },
//                                         child: TemplateNewDateRangePicker(),
//                                       ),
//                                     ],
//                                   ),
//                                 ):Container(),
//
//                                 widget.adaFilterTanggal?
//                                 Container(
//                                   margin: EdgeInsets.only(bottom: 12),
//                                   child: Column(
//                                     crossAxisAlignment: CrossAxisAlignment.start,
//                                     children: [
//                                       // Padding(
//                                       //   padding: const EdgeInsets.only(bottom: 8, left: 11),
//                                       //   child: Text(
//                                       //     snapshot.data == null || snapshot.data == 'en' ? 'Month Year' : 'Bulan Tahun',
//                                       //     style: TextStyle(color: Colors.grey, fontWeight: FontWeight.w500, fontSize: CustomStyle.fontSizeSmall),
//                                       //   ),
//                                       // ),
//                                       Row(
//                                         children: [
//                                           Expanded(
//                                             // flex: 3,
//                                             child: BlocBuilder<monthPicker.MonthPickerBloc, monthPicker.MonthPickerState>(
//                                               builder: (BuildContext context, monthPicker.MonthPickerState state){
//                                                 print("hahaha : ${state}");
//                                                 monthYear = state.dateTime;
//
//                                                 return TemplateNewMonthPicker(lastMonth: true);
//                                               },
//                                               // child: TemplateMonthPickerNonFloating(lastMonth: true),
//                                               // child: ,
//                                             ),
//                                           ),
//                                           // SizedBox(width: 8),
//                                         ],
//                                       ),
//                                     ],
//                                   ),
//                                 ):Container(),
//                                 SizedBox(height: 24,),
//                                 Row(
//                                   mainAxisAlignment: MainAxisAlignment.end,
//                                   children: [
//                                     TemplateButton(
//                                       onClick: ()=>resetFilter(),
//                                       label: "Reset", expand: true, color: Colors.transparent, contentColor: CustomStyle.color1, fontSize: CustomStyle.fontSizeNormal, bold: true, paddingTopBottom: 0, heightButton: 34,paddingLeftRight: 8,),
//                                     TemplateButton(
//                                       onClick: (){
//                                         if(monthYear != null) widget.modelFilter!.monthYear = monthYear;
//                                         else widget.modelFilter!.monthYear = null;
//                                         if(dateRange != null) widget.modelFilter!.dateRange = dateRange;
//                                         else widget.modelFilter!.dateRange = null;
//                                         if(dataPegawai != null){
//                                           widget.modelFilter!.idPegawai = dataPegawai!.id;
//                                           widget.modelFilter!.namaPegawai = dataPegawai!.nama;
//                                         } else{
//                                           widget.modelFilter!.idPegawai = null;
//                                           widget.modelFilter!.namaPegawai = null;
//                                         }
//                                         if(dataPerusahaan != null){
//                                           widget.modelFilter!.idPerusahaan = dataPerusahaan!.id;
//                                           widget.modelFilter!.namaPerusahaan = dataPerusahaan!.nama;
//                                         } else{
//                                           widget.modelFilter!.idPerusahaan = null;
//                                           widget.modelFilter!.namaPerusahaan = null;
//                                         }
//
//                                         // print("object outputnya : ${widget.modelFilter!.monthYear}");
//                                         // print("object outputnya : ${widget.modelFilter!.dateRange}");
//                                         // print("object outputnya : ${widget.modelFilter!.namaPerusahaan}");
//                                         // print("object outputnya : ${widget.modelFilter!.namaPegawai}");
//                                         print("object outputnya : ${_valueControllerPegawai.value}");
//
//
//                                           // modelFilter = ModelFilter(monthYear: monthYear==null?widget.monthYears:monthYear,
//                                           //                         dateRange: dateRange==null?null:dateRange,
//                                           //                         idPegawai: dataPegawai!=null?dataPegawai!.id:null,
//                                           //                         namaPegawai: dataPegawai!=null?dataPegawai!.nama:null,
//                                           //                         idPerusahaan: dataPerusahaan!=null?dataPerusahaan!.id:null,
//                                           //                         namaPerusahaan: dataPerusahaan!=null?dataPerusahaan!.nama:null);
//                                         // BlocProvider.of<FilterBottomSheetBloc>(context).add(setFilterBottomSheet(widget.modelFilter));
//                                         // BlocProvider.of<NavigatorBloc>(context).add(NavigatePop(context));
//                                       },
//                                       label: snapshot.data == null || snapshot.data == 'en' ? "Apply" : "Terapkan", expand: true, color: Colors.transparent, contentColor: CustomStyle.color1, fontSize: CustomStyle.fontSizeNormal, bold: true, paddingTopBottom: 0, heightButton: 34, paddingLeftRight: 8,),
//                                   ],
//                                 )
//                               ],
//                             ),
//                           ),
//                         ),
//                       ),
//                     );
//                   }
//               );
//             }));
//   }
// }












import 'package:absenkuv3/Bloc/AuthBloc.dart';
import 'package:absenkuv3/Bloc/FilterBottomSheetBloc.dart';
import 'package:absenkuv3/Bloc/NavigatorBloc.dart';
import 'package:absenkuv3/Repository/Model/mDropdown.dart';
import 'package:absenkuv3/Repository/Model/mFilter.dart';
import 'package:absenkuv3/Repository/Model/mLogin.dart';
import 'package:absenkuv3/Setting/PengaturanBahasa.dart';
import 'package:absenkuv3/UI/Modul/Absensi/KomponenAbsensi.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/Bloc/AutoCompleteFilterGroupAreaBloc.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/Bloc/AutoCompleteFilterPerusahaanBloc.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/Bloc/AutoCompletePegawaiBawahanBloc.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/UI/AutoCompleteGroupAreaFilterKanban.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/UI/AutoCompletePegawaiBawahan2.dart';
import 'package:absenkuv3/UI/Template/AutoComplete/UI/AutoCompletePerusahaanFilterKanban2.dart';
import 'package:absenkuv3/UI/Template/DateRangePicker/Bloc/DateRangePickerBloc.dart' as dateRangePicker;
import 'package:absenkuv3/UI/Template/DateRangePicker/UI/templateNewDateRangePicker.dart';
import 'package:absenkuv3/UI/Template/FilterToggle/Bloc/ToogleFilterBloc.dart';
import 'package:absenkuv3/UI/Template/MonthPicker/UI/templateNewMonthPicker.dart';
import 'package:absenkuv3/UI/Template/style.dart';
import 'package:absenkuv3/UI/Template/templateButton.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'MonthPicker/Bloc/MonthPickerBloc.dart' as monthPicker;
import 'package:intl/intl.dart';

class FilterBottomSheetKanban extends StatefulWidget {
  bool adaFilterTanggal;
  bool adaFilterStatus;
  bool adaFilterRangeTanggal;
  DateTime? monthYears;
  List<DateTime>? dateRange;
  FilterBottomSheetKanban(this.monthYears, this.dateRange, {this.adaFilterTanggal=true, this.adaFilterStatus=false, this.adaFilterRangeTanggal=true});
  @override
  _FilterBottomSheetKanbanState createState() => _FilterBottomSheetKanbanState();
}

class _FilterBottomSheetKanbanState extends State<FilterBottomSheetKanban> {
  DataDropdown? dataPegawai;
  DataDropdown? dataPerusahaan;
  DataDropdown? dataGroupArea;
  DataDropdown? dataStatus;
  DateTime? monthYear;
  List<DateTime>? dateRange;
  ModelFilter? modelFilter;
  String _selectedFilterBulan = 'Bulan Ini';
  String _selectedFilterTanggal = 'Tanggal Ini';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initialFilter();
    // modelFilter!.monthYear = widget.monthYears;
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(create: (context) {
      return monthPicker.MonthPickerBloc(monthPicker.MonthPickerProgressState());
    },
      child: BlocBuilder<AuthBloc, LoginRespon>(
          builder: (BuildContext context, LoginRespon loginRespon){
            return BlocListener<ToogleFilterBloc, ToogleFilterState?>(
              listener: (BuildContext context, ToogleFilterState? state) {
                if (state is SuccessToogleChangeState) {
                  _selectedFilterBulan = state.toogleChange;
                  _selectedFilterTanggal = state.toogleChange;
                }
              },
              child: BlocListener<FilterBottomSheetBloc, FilterBottomSheetState>(
                  listener: (BuildContext context, FilterBottomSheetState stateBottomSheet) {
                    if (stateBottomSheet is setFilterSuccess) {
                      widget.monthYears = stateBottomSheet.modelFilter!.monthYear;
                      widget.dateRange = stateBottomSheet.modelFilter!.dateRange;
                    }
                  },
                child: TombolIcon(
                  onClick: (){
                    if(widget.monthYears != null){
                      if(DateTime(widget.monthYears!.year, widget.monthYears!.month, 01) == DateTime(DateTime.now().year, DateTime.now().month, 01)){
                        _selectedFilterBulan = "Bulan Ini";
                        monthYear = DateTime(DateTime.now().year, DateTime.now().month, 01);
                      }else if(DateTime(widget.monthYears!.year, widget.monthYears!.month, 01) == DateTime(DateTime.now().year, DateTime.now().month-1, 01)){
                        _selectedFilterBulan = "Bulan Lalu";
                        monthYear = DateTime(DateTime.now().year, DateTime.now().month-1, 01);
                      }else{
                        _selectedFilterBulan = "Pilih Bulan Sendiri";
                        monthYear = DateTime(widget.monthYears!.year, widget.monthYears!.month, 01);
                      }
                      BlocProvider.of<ToogleFilterBloc>(context).add(InitWithValueStateEvent(context, _selectedFilterBulan));
                      _settingModalBottomSheet(loginRespon, _selectedFilterBulan);
                    }
                    if(widget.dateRange != null){
                      if((DateFormat('yyyy-MM-dd').format(widget.dateRange![0]) == DateFormat('yyyy-MM-dd').format(DateTime.now()))
                          && (DateFormat('yyyy-MM-dd').format(widget.dateRange![1]) == DateFormat('yyyy-MM-dd').format(DateTime.now()))){
                        _selectedFilterTanggal = "Hari Ini";
                        dateRange = [
                          DateTime.now(),
                          DateTime.now(),
                        ];
                      }else if((DateFormat('yyyy-MM-dd').format(widget.dateRange![0]) == DateFormat('yyyy-MM-dd').format(DateTime.now().subtract(const Duration(days: 1))))
                          && (DateFormat('yyyy-MM-dd').format(widget.dateRange![1]) == DateFormat('yyyy-MM-dd').format(DateTime.now().subtract(const Duration(days: 1))))){
                        _selectedFilterTanggal = "Kemarin";
                        dateRange = [
                          DateTime.now().subtract(const Duration(days: 1)),
                          DateTime.now().subtract(const Duration(days: 1)),
                        ];
                      }else{
                        _selectedFilterTanggal = "Pilih Tanggal Sendiri";
                        dateRange = widget.dateRange;
                      }
                      BlocProvider.of<ToogleFilterBloc>(context).add(InitWithValueStateEvent(context, _selectedFilterTanggal));
                      _settingModalBottomSheet(loginRespon, _selectedFilterTanggal);
                    }
                  },
                  icon : Icons.filter_alt,
                  bgnColor: Colors.white,
                  size: 32,
                  iconColor: CustomStyle.color1,),
              )
            );
          }),
    );
  }

  void initialFilter(){
    if(widget.monthYears != null){
      modelFilter = ModelFilter(monthYear: widget.monthYears);
    }else{
      if(widget.adaFilterRangeTanggal){
        modelFilter = ModelFilter(dateRange: [DateTime.now(), DateTime.now()]);
      }else{
        modelFilter = null;
      }
    }

    BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(SetFilterPerusahaan(null));
    BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(GetFilterPerusahaan(""));
    BlocProvider.of<AutoCompleteFilterGroupAreaBloc>(context).add(GetFilterGroupArea(""));
    BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(GetPegawaiBawahan(null, ""));
    BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.SetDate([DateTime.now(),DateTime.now()]));
    BlocProvider.of<monthPicker.MonthPickerBloc>(context).add(monthPicker.SetDate(widget.monthYears));
  }
  void resetFilter(BuildContext _con){
    BlocProvider.of<dateRangePicker.DateRangePickerBloc>(context).add(dateRangePicker.SetDate([DateTime.now(),DateTime.now()]));
    BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(SetFilterPerusahaan(null));
    BlocProvider.of<AutoCompleteFilterGroupAreaBloc>(context).add(SetFilterGroupArea(null));
    BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(SetPegawaiBawahan(null));
    BlocProvider.of<monthPicker.MonthPickerBloc>(context).add(monthPicker.SetDate(DateTime.now()));
    // _selectedFilterTanggal = 'Bulan Ini';
    // BlocProvider.of<ToogleFilterBloc>(_con).add(InitWithValueStateEvent(_con, _selectedFilterTanggal));
    // BlocProvider.of<ToogleFilterBloc>(_con).add(ChangeEvent(_con, _selectedFilterTanggal));
    setState(() {
      if(widget.monthYears != null){
        modelFilter = ModelFilter(monthYear: widget.monthYears);
      }else{
        if(widget.adaFilterRangeTanggal){
          modelFilter = ModelFilter(dateRange: [DateTime.now(), DateTime.now()]);
        }else{
          modelFilter = null;
        }
      }
      _selectedFilterBulan = 'Bulan Ini';
      _selectedFilterTanggal = 'Hari Ini';
      dataPegawai = null;
      dataPerusahaan = null;
    });
  }

  void _settingModalBottomSheet(LoginRespon loginRespon, String? _selectedFilterTanggal){
    showModalBottomSheet(
        backgroundColor: Colors.white,
        elevation: 0,
        context: context,
        isDismissible: false,
        isScrollControlled: true,
        showDragHandle: true,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
        builder: (context) => StatefulBuilder(
            builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
              final String language = 'id';
              final Map<String, String> filterOptions1 = {
                'Bulan Ini': language == 'id' ? 'Bulan Ini' : 'Current Month',
                'Bulan Lalu': language == 'id' ? 'Bulan Lalu' : 'Last Month',
                'Pilih Bulan Sendiri': language == 'id' ? 'Pilih Bulan Sendiri' : 'Choose Your Own Month',
              };
              final Map<String, String> filterOptions2 = {
                'Hari Ini': language == 'id' ? 'Hari Ini' : 'Current Date',
                'Kemarin': language == 'id' ? 'Kemarin' : 'Yesterday',
                'Pilih Tanggal Sendiri': language == 'id' ? 'Pilih Tanggal Sendiri' : 'Choose Your Own Date',
              };
              return FutureBuilder<String>(
                  future: PengaturanBahasa().getDataBahasa(),
                  builder: (context, snapshot) {
                    return SingleChildScrollView(
                      child: Padding(
                        padding: EdgeInsets.only(
                            bottom: MediaQuery.of(context).viewInsets.bottom),
                        child: ConstrainedBox(
                          constraints: BoxConstraints(
                              minHeight: widget.adaFilterTanggal?MediaQuery.of(context).size.height/3:MediaQuery.of(context).size.height/4
                          ),
                          child: Container(
                            color: Colors.white,
                            margin: EdgeInsets.fromLTRB(27, 0, 27, 14),
                            child: Column(
                              children: [
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(snapshot.data == null || snapshot.data == 'en' ? "Search Filters" : "Filter Pencarian", style: TextStyle(color: CustomStyle.fontColorBlack, fontSize: 14, fontWeight: FontWeight.w700),),
                                    SizedBox(width: 8,),
                                    GestureDetector(
                                        onTap: (){
                                          BlocProvider.of<NavigatorBloc>(context).add(NavigatePop(context));
                                          // resetFilter();
                                        },
                                        child: Icon(Icons.close, color: CustomStyle.fontColorBlack, size: 21,)),
                                  ],),
                                SizedBox(height: 7),
                                Divider(thickness: 1),

                                BlocBuilder<FilterBottomSheetBloc, FilterBottomSheetState>(builder: (context, filterBottomSheetState){
                                  if(filterBottomSheetState is setFilterSuccess){
                                    return BlocListener<AutoCompleteFilterPerusahaanBloc, AutoCompleteFilterPerusahaanState>(
                                      listener: (BuildContext context, AutoCompleteFilterPerusahaanState state){
                                        if(state is SetFilterPerusahaanSuccess) dataPerusahaan = state.perusahaan;
                                      },
                                      // child: AutoCompletePerusahaanFilterKanban(filterBottomSheetState.modelFilter, fontSize:CustomStyle.fontSizeSmall,radius: 14, formHeight: 41, title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',),
                                      child: AutoCompletePerusahaanFilterKanban2(
                                          filterBottomSheetState.modelFilter,
                                          fontSize:CustomStyle.fontSizeSmall,
                                          radius: 14,
                                          formHeight: 34,
                                          dataCallback: (DataDropdown? val){
                                            dataPerusahaan = val;
                                          },
                                          title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',
                                          prefixIcon: Icon(Icons.search, size: 20)
                                      ),
                                    );
                                  }

                                  else  return BlocListener<AutoCompleteFilterPerusahaanBloc, AutoCompleteFilterPerusahaanState>(
                                    listener: (BuildContext context, AutoCompleteFilterPerusahaanState state){
                                      if(state is SetFilterPerusahaanSuccess) dataPerusahaan = state.perusahaan;
                                    },
                                    // child: AutoCompletePerusahaanFilterKanban(null, fontSize:CustomStyle.fontSizeSmall,radius: 14, formHeight: 41, title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan'),
                                    child: AutoCompletePerusahaanFilterKanban2(
                                        null,
                                        fontSize:CustomStyle.fontSizeSmall,
                                        radius: 14,
                                        formHeight: 34,
                                        title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',
                                        prefixIcon: Icon(Icons.search, size: 20)
                                    ),
                                  );
                                }),
                                !loginRespon.dataLogin!.adminAtasan! ? Container() :
                                BlocBuilder<FilterBottomSheetBloc, FilterBottomSheetState>(builder: (context, filterBottomSheetState){
                                  if(filterBottomSheetState is setFilterSuccess){
                                    return BlocListener<AutoCompleteFilterGroupAreaBloc, AutoCompleteFilterGroupAreaState>(
                                      listener: (BuildContext context, AutoCompleteFilterGroupAreaState state){
                                        if(state is SetFilterGroupAreaSuccess){
                                          dataGroupArea = state.GroupArea;
                                          // BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(GetPegawaiBawahan(null, dataGroupArea==null?null:dataGroupArea!.id));
                                        }
                                      },
                                      // child: AutoCompletePerusahaanFilterKanban(filterBottomSheetState.modelFilter, fontSize:CustomStyle.fontSizeSmall,radius: 14, formHeight: 41, title: snapshot.data == null || snapshot.data == 'en' ? 'Customer' : 'Pelanggan',),
                                      child: AutoCompleteGroupAreaFilterKanban(
                                          filterBottomSheetState.modelFilter,
                                          fontSize:CustomStyle.fontSizeSmall,
                                          radius: 14,
                                          formHeight: 34,
                                          dataCallback: (DataDropdown? val){
                                            dataGroupArea = val;
                                            // BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(GetPegawaiBawahan(null, dataGroupArea==null?"":dataGroupArea!.id));
                                          },
                                          title: snapshot.data == null || snapshot.data == 'en' ? 'Group / Area' : 'Group / Area',
                                          prefixIcon: Icon(Icons.search, size: 20)
                                      ),
                                    );
                                  }

                                  else  return BlocListener<AutoCompleteFilterGroupAreaBloc, AutoCompleteFilterGroupAreaState>(
                                    listener: (BuildContext context, AutoCompleteFilterGroupAreaState state){
                                      if(state is SetFilterGroupAreaSuccess) {
                                        dataGroupArea = state.GroupArea;
                                      }
                                    },
                                    child: AutoCompleteGroupAreaFilterKanban(
                                        null,
                                        fontSize:CustomStyle.fontSizeSmall,
                                        radius: 14,
                                        formHeight: 34,
                                        title: snapshot.data == null || snapshot.data == 'en' ? 'Group / Area' : 'Group / Area',
                                        prefixIcon: Icon(Icons.search, size: 20),
                                        dataCallback: (val){
                                          if(val != null){
                                            dataGroupArea = val;
                                            // BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(SetPegawaiBawahan(dataGroupArea));
                                          }
                                        },
                                    ),
                                  );
                                }),
                                !loginRespon.dataLogin!.adminAtasan! ? Container() :
                                BlocBuilder<FilterBottomSheetBloc, FilterBottomSheetState>(builder: (context, filterBottomSheetState){
                                  if(filterBottomSheetState is setFilterSuccess){
                                    return BlocListener<AutoCompletePegawaiBawahanBloc, AutoCompletePegawaiBawahanState>(
                                      listener: (BuildContext context, AutoCompletePegawaiBawahanState state){
                                        if(state is SetPegawaiBawahanSuccess) dataPegawai = state.pegawaiBawahan;
                                      },
                                      child: AutoCompletePegawaiBawahan2(
                                        filterBottomSheetState.modelFilter,
                                        fontSize:CustomStyle.fontSizeSmall,
                                        radius: 14,
                                        formHeight: 34,
                                        dataCallback: (DataDropdown? val){
                                          dataPegawai = val;
                                        },
                                        title: snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
                                        prefixIcon: Icon(Icons.search, size: 20)
                                      ),
                                    );
                                  }
                                  else return BlocListener<AutoCompletePegawaiBawahanBloc, AutoCompletePegawaiBawahanState>(
                                    listener: (BuildContext context, AutoCompletePegawaiBawahanState state){
                                      if(state is SetPegawaiBawahanSuccess) dataPegawai = state.pegawaiBawahan;
                                    },
                                    child: AutoCompletePegawaiBawahan2(
                                      null,
                                      fontSize:CustomStyle.fontSizeSmall,
                                      radius: 14,
                                      formHeight: 34,
                                      title: snapshot.data == null || snapshot.data == 'en' ? 'Sales' : 'Sales',
                                      prefixIcon: Icon(Icons.search, size: 20)
                                    ),
                                  );
                                }),
                                widget.adaFilterRangeTanggal?Container(
                                  margin: EdgeInsets.only(bottom: 12),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      SizedBox(height: 24),
                                      Text(snapshot.data == null || snapshot.data == 'en' ? "Date Range" : "Range Tanggal", style: TextStyle(color: CustomStyle.fontColorBlack, fontSize: 14, fontWeight: FontWeight.w700),),
                                      SizedBox(height: 7),
                                      Row(
                                        children: [
                                          Expanded(
                                            child: BlocBuilder<ToogleFilterBloc, ToogleFilterState?>(
                                              builder: (BuildContext context, ToogleFilterState? state) {
                                                if (state is SuccessToogleChangeState) {
                                                  return Container(
                                                    child: Column(
                                                      mainAxisSize: MainAxisSize.min,
                                                      crossAxisAlignment: CrossAxisAlignment.start,
                                                      children: [
                                                        ...filterOptions2.entries.map((entry) {
                                                          return _buildFilterOption(
                                                            context: context,
                                                            label: entry.value,
                                                            value: entry.key,
                                                            selectedValue: _selectedFilterTanggal,
                                                            onChanged: (value) {
                                                              _selectedFilterTanggal = value;
                                                              BlocProvider.of<ToogleFilterBloc>(context).add(ChangeEvent(context, value));

                                                              if(value == 'Hari Ini'){
                                                                dateRange = [
                                                                  DateTime.now().subtract(const Duration(days: 1)),
                                                                  DateTime.now().subtract(const Duration(days: 1)),
                                                                ];
                                                              }else if (value == 'Kemarin') {
                                                                dateRange = [
                                                                  DateTime.now().subtract(const Duration(days: 1)),
                                                                  DateTime.now().subtract(const Duration(days: 1)),
                                                                ];
                                                              } else if (value == 'Pilih Tanggal Sendiri') {

                                                              }
                                                            },
                                                          );
                                                        }).toList(),
                                                        if (_selectedFilterTanggal == 'Pilih Tanggal Sendiri')
                                                          BlocListener<dateRangePicker.DateRangePickerBloc, dateRangePicker.DateRangePickerState>(
                                                            listener: (BuildContext context, dateRangePicker.DateRangePickerState dateRangePickerState){
                                                              if(dateRangePickerState is dateRangePicker.DateAvailable) {
                                                                dateRange = dateRangePickerState.date;
                                                              }
                                                            },
                                                            child: TemplateNewDateRangePicker(),
                                                          ),
                                                      ],
                                                    ),
                                                  );
                                                } else {
                                                  return Container();
                                                }
                                              },
                                            ),
                                          ),
                                        ],
                                      ),
                                      // BlocListener<dateRangePicker.DateRangePickerBloc, dateRangePicker.DateRangePickerState>(
                                      //   listener: (BuildContext context, dateRangePicker.DateRangePickerState dateRangePickerState){
                                      //     if(dateRangePickerState is dateRangePicker.DateAvailable) {
                                      //       dateRange = dateRangePickerState.date;
                                      //     }
                                      //   },
                                      //   child: TemplateNewDateRangePicker(),
                                      // ),
                                    ],
                                  ),
                                ):Container(),

                                widget.adaFilterTanggal?
                                Container(
                                  margin: EdgeInsets.only(bottom: 12),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      SizedBox(height: 24),
                                      Text(snapshot.data == null || snapshot.data == 'en' ? "Month - Year" : "Bulan - Tahun", style: TextStyle(color: CustomStyle.fontColorBlack, fontSize: 14, fontWeight: FontWeight.w700),),
                                      SizedBox(height: 7),
                                      Row(
                                        children: [
                                          // Expanded(
                                          //   child: BlocListener<monthPicker.MonthPickerBloc, monthPicker.MonthPickerState>(
                                          //     listener: (BuildContext context, monthPicker.MonthPickerState state){
                                          //       monthYear = state.dateTime;
                                          //     },
                                          //     child: TemplateNewMonthPicker(lastMonth: true),
                                          //   ),
                                          // ),
                                          Expanded(
                                            child: BlocBuilder<ToogleFilterBloc, ToogleFilterState?>(
                                              builder: (BuildContext context, ToogleFilterState? state) {
                                                if (state is SuccessToogleChangeState) {
                                                  return Container(
                                                    child: Column(
                                                      mainAxisSize: MainAxisSize.min,
                                                      crossAxisAlignment: CrossAxisAlignment.start,
                                                      children: [
                                                        ...filterOptions1.entries.map((entry) {
                                                          return _buildFilterOption(
                                                            context: context,
                                                            label: entry.value,
                                                            value: entry.key,
                                                            selectedValue: _selectedFilterTanggal,
                                                            onChanged: (value) {
                                                              _selectedFilterTanggal = value;
                                                              BlocProvider.of<ToogleFilterBloc>(context).add(ChangeEvent(context, value));

                                                              if(value == 'Bulan Ini'){
                                                                monthYear = DateTime(DateTime.now().year, DateTime.now().month, 01);
                                                              }else if (value == 'Bulan Lalu') {
                                                                monthYear = DateTime(DateTime.now().year, DateTime.now().month-1, 01);
                                                              } else if (value == 'Pilih Bulan Sendiri') {

                                                              }
                                                            },
                                                          );
                                                        }).toList(),
                                                        if (_selectedFilterTanggal == 'Pilih Bulan Sendiri')
                                                          BlocListener<monthPicker.MonthPickerBloc, monthPicker.MonthPickerState>(
                                                            listener: (BuildContext context, monthPicker.MonthPickerState state){
                                                              monthYear = state.dateTime;
                                                            },
                                                            child: Container(
                                                                margin: EdgeInsets.symmetric(horizontal: 13),
                                                                child: TemplateNewMonthPicker(lastMonth: true)),
                                                          ),
                                                      ],
                                                    ),
                                                  );
                                                } else {
                                                  return Container();
                                                }
                                              },
                                            ),
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                ):Container(),
                                SizedBox(height: 24,),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    TemplateButton(
                                      onClick: ()=>resetFilter(context),
                                      label: "Reset", expand: true, color: Colors.transparent, contentColor: CustomStyle.color1, fontSize: CustomStyle.fontSizeNormal, bold: true, paddingTopBottom: 0, heightButton: 34,paddingLeftRight: 8,),
                                    TemplateButton(
                                      onClick: (){
                                        modelFilter = ModelFilter(monthYear: monthYear==null?widget.monthYears:monthYear,
                                            dateRange: dateRange==null?widget.dateRange:dateRange,
                                            idGroup: dataGroupArea!=null?dataGroupArea!.id:null,
                                            namaGroup: dataGroupArea!=null?dataGroupArea!.nama:null,
                                            idPegawai: dataPegawai!=null?dataPegawai!.id:null,
                                            namaPegawai: dataPegawai!=null?dataPegawai!.nama:null,
                                            idPerusahaan: dataPerusahaan!=null?dataPerusahaan!.id:null,
                                            namaPerusahaan: dataPerusahaan!=null?dataPerusahaan!.nama:null);

                                        BlocProvider.of<AutoCompletePegawaiBawahanBloc>(context).add(SetPegawaiBawahan(dataPegawai));
                                        BlocProvider.of<AutoCompleteFilterGroupAreaBloc>(context).add(SetFilterGroupArea(dataGroupArea));
                                        BlocProvider.of<AutoCompleteFilterPerusahaanBloc>(context).add(SetFilterPerusahaan(dataPerusahaan));
                                        BlocProvider.of<FilterBottomSheetBloc>(context).add(setFilterBottomSheet(modelFilter));
                                        BlocProvider.of<NavigatorBloc>(context).add(NavigatePop(context));
                                      },
                                      label: snapshot.data == null || snapshot.data == 'en' ? "Apply" : "Terapkan", expand: true, color: Colors.transparent, contentColor: CustomStyle.color1, fontSize: CustomStyle.fontSizeNormal, bold: true, paddingTopBottom: 0, heightButton: 34, paddingLeftRight: 8,),
                                  ],
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    );
                  }
              );
            }));
  }

  Widget _buildFilterOption({required BuildContext context, required String label, required String value, required String? selectedValue, required Function(String) onChanged,}) {
    return Column(
      children: [
        GestureDetector(
          onTap: () => onChanged(value),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(label, style: TextStyle( fontSize: 13, color: Colors.grey.shade800)),
              Container(
                margin: EdgeInsets.only(right: 5),
                child: Transform.scale(
                  scale: 0.9,
                  child: Radio<String>(
                    visualDensity: VisualDensity(vertical: -3),
                    value: value,
                    groupValue: selectedValue,
                    materialTapTargetSize: MaterialTapTargetSize.padded,
                    activeColor: selectedValue == value
                        ? CustomStyle.color1
                        : Colors.transparent,
                    onChanged: (value) => onChanged(value!),
                  ),
                ),
              ),
            ],
          ),
        ),
        Divider(
          thickness: 0.2,
          color: CustomStyle.fontColorGrey,
        ),
      ],
    );
  }
}





