import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart';
import 'package:image_picker/image_picker.dart';
import 'package:loading_indicator/loading_indicator.dart';
import 'package:provider/provider.dart';
import 'package:searchfield/searchfield.dart';
import 'package:telnow_mobile_new/src/injector/injector.dart';
import 'package:telnow_mobile_new/src/layouts/functions/request.dart';
import 'package:telnow_mobile_new/src/layouts/components/template.dart';
import 'package:telnow_mobile_new/src/storage/sharedpreferences/shared_preferences_manager.dart';
import 'package:telnow_mobile_new/src/utils/U.dart';
import 'package:telnow_mobile_new/src/utils/provider.dart';
import 'package:toggle_switch/toggle_switch.dart';

class WebReqCreatePage extends StatefulWidget {
  final Map<String, dynamic> user;
  final Map<String, dynamic> request;
  final bool fromSearch;
  const WebReqCreatePage({required this.user, required this.request, this.fromSearch = false, super.key});

  @override
  State<WebReqCreatePage> createState() => _WebReqCreatePageState();
}

getColorScheme(val){
  var color;
  switch (val){
    case 0: color = Color(0xFF4FB66C); break;
    case 50: color = Color(0xFFFFA800); break;
    case 100: color = Color(0xFFC9223B); break;
    default: color = Color(0xFF4FB66C);
  }
  return color;
}

class _WebReqCreatePageState extends State<WebReqCreatePage> {
  final RequestFunction reqFunc = RequestFunction();
  final SharedPreferencesManager sharedPreferencesManager = locator<SharedPreferencesManager>();

  TextEditingController controllerDate = new TextEditingController()..text = '';
  TextEditingController controllerDateString = new TextEditingController()..text = '';
  TextEditingController controllerNote = new TextEditingController()..text = '';
  TextEditingController controllerLocation = new TextEditingController()..text = '';
  TextEditingController controllerUserId = new TextEditingController()..text = '';
  TextEditingController controllerReferenceNumber = new TextEditingController()..text = '';

  FocusNode focusNodeLocation = new FocusNode();
  double _currentSliderValue = 0;
  Color sliderColor = getColorScheme(0);

  @override
  void initState() {
    Provider.of<CreateSerModule>(context, listen: false).reset();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if(widget.request['scanToRequest']) Provider.of<CreateSerModule>(context, listen: false).setLocationType(2);
      Provider.of<CreateSerModule>(context, listen: false).setDefaultLocation(widget.user['_isRelated'] ? sharedPreferencesManager.getString(SharedPreferencesManager.keyScoope) == 'INSIDE' ? widget.user['_2ndLocation'] : widget.user['location'] : widget.user['location']);
    });

    reqFunc.getSuggestionLocation(context);
    U.getOtherLabelList(context);
    // TODO: implement initState
    focusNodeLocation.addListener(() {
      context.read<CreateSerModule>().setLocationType(2);
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final FocusNode inputIdFocusNode = FocusNode();
    return Scaffold(
      backgroundColor: backgroundColor,
      appBar: PreferredSize(preferredSize: Size.fromHeight(0), child: AppBar(elevation: 0, backgroundColor: primaryColor)),
      body: Column(
        children: [
          Container(
            padding: EdgeInsets.symmetric(vertical: 25, horizontal: 100),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(widget.request[U.langColumn(context, 'subject')], style: TextStyle(color: textColor, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
                GestureDetector(
                  child: Text('buttonBack'.tr(), style: TextStyle(color: primaryColor, fontSize: 14)),
                  onTap: ()=>navigateBack(context),
                )
              ],
            ),
          ),
          divider(),
          Expanded(
            child: SingleChildScrollView(
              padding: EdgeInsets.symmetric(vertical: 25, horizontal: 100),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.all(20),
                      decoration: BoxDecoration(color: Colors.white, border: Border.all(color: textColor.withValues(alpha: 0.15)), borderRadius: BorderRadius.all(Radius.circular(12))),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              imageTiles(imageUrl: widget.request['_mobileImage'] ?? "null", width: 110, height: 90),
                              SizedBox(width: 20),
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(widget.request[U.langColumn(context, '_requestGroupDescription')]??'', style: TextStyle(color: textColor, fontWeight: FontWeight.w600), maxLines: 2, overflow: TextOverflow.ellipsis),
                                    dashed(),
                                    Text(widget.request[U.langColumn(context, 'subjectDescription')], style: TextStyle(color: textColor), maxLines: 3, overflow: TextOverflow.ellipsis)
                                  ],
                                ),
                              ),
                            ],
                          ),
                          SizedBox(height: 20),
                          widget.request['autoResponse'] ? infoContainer('autoResponseText'.tr()) : Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              widget.user['roomAttendant'] ? Container(
                                margin: EdgeInsets.only(bottom: 32),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(U.otherLabelList()['main-${context.locale.toString()}']??'someone_else'.tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                                    SizedBox(height: 12),
                                    Row(
                                      children: [
                                        Container(
                                          child: ToggleSwitch(
                                            cornerRadius: 20,
                                            minWidth: 20,
                                            minHeight: 20,
                                            borderWidth: 2,
                                            activeBgColors: [[Colors.white], [Colors.white]],
                                            inactiveBgColor: Provider.of<CreateSerModule>(context).others() == 0 ? disabledColor : primaryColor,
                                            initialLabelIndex: context.watch<CreateSerModule>().others(),
                                            totalSwitches: 2,
                                            radiusStyle: true,
                                            onToggle: (index) {
                                              if(index == 1) {
                                                FocusScope.of(context).requestFocus(inputIdFocusNode);
                                              } else {
                                                FocusScope.of(context).unfocus();
                                              }
                                              context.read<CreateSerModule>().setOthers(index);
                                            },
                                          ),
                                          decoration: BoxDecoration(color: Provider.of<CreateSerModule>(context).others() == 0 ? disabledColor : primaryColor, borderRadius: BorderRadius.all(Radius.circular(20))),
                                        ),
                                        SizedBox(width: 8),
                                        Expanded(child: Text(context.watch<CreateSerModule>().others() == 0 ? 'reqForMySelf'.tr() : 'reqForOthers'.tr(), style: TextStyle(color: textColor, fontSize: 12), maxLines: 2, overflow: TextOverflow.ellipsis))
                                      ],
                                    ),
                                    context.read<CreateSerModule>().others()==1?Container(
                                      margin: EdgeInsets.only(top: 12),
                                      width: double.infinity,
                                      child: TextField(
                                        controller: controllerUserId,
                                        focusNode: inputIdFocusNode,
                                        style: const TextStyle(fontSize: 14, color: Colors.black),
                                        autofocus: context.read<CreateSerModule>().others() == 1 ? true : false,
                                        readOnly: false,
                                        decoration: InputDecoration(
                                            hintText: U.otherLabelList()['placeholder-${context.locale.toString()}']??'typeId'.tr(),
                                            hintStyle: TextStyle(color: textColor.withValues(alpha: 0.5), fontSize: 14),
                                            filled: true,
                                            fillColor: backgroundColor,
                                            hoverColor: Colors.black.withValues(alpha: 0.1),
                                            contentPadding: EdgeInsets.all(13),
                                            border: InputBorder.none,
                                            enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                            focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primaryColor)),
                                            isDense: true
                                        ),
                                      ),
                                    ):Container()
                                  ],
                                ),
                              ):Container(),

                              widget.request['noteFormat'] == 'DATE' ? Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                                Text("askScheduleTime".tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                                SizedBox(height: 8,),
                                TextField(
                                  controller: controllerDate,
                                  style: TextStyle(fontSize: 14, color: Colors.black),
                                  readOnly: true,
                                  decoration: InputDecoration(
                                      hintText: 'selectDate'.tr(),
                                      hintStyle: TextStyle(color: textColor.withValues(alpha: 0.5), fontSize: 14),
                                      filled: true,
                                      fillColor: backgroundColor,
                                      hoverColor: Colors.black.withValues(alpha: 0.1),
                                      contentPadding: EdgeInsets.all(13),
                                      prefixIcon: Padding(padding: EdgeInsets.only(left: 13, right: 13), child: U.iconsax('calendar-edit', color: textColor, size: 24)),
                                      border: InputBorder.none,
                                      enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                      focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primaryColor)),
                                      isDense: true
                                  ),
                                  onTap: () {
                                    DatePicker.showDateTimePicker(context, showTitleActions: true,
                                        minTime: DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, DateTime.now().hour, DateTime.now().minute),
                                        onConfirm: (date) {
                                          try {
                                            setState(() {
                                              controllerDate.text = DateFormat('dd MMM yyyy HH:mm:ss', 'id').format(date);
                                              controllerDateString.text = DateFormat('ddMMyyyy HHmm', 'id').format(date);
                                            });
                                          } catch (e) {
                                            print(e.toString());
                                          }
                                        }, currentTime: DateTime.now(), locale: LocaleType.id
                                    );
                                  },
                                ),
                                SizedBox(height: 32,)
                              ],) : Container(),

                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text('addImage'.tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                                  SizedBox(height: 8),
                                  context.watch<CreateSerModule>().images().length > 0 ? Container(
                                    width: double.infinity,
                                    child: LayoutBuilder(
                                      builder: (context, constraints) {
                                        var imageWidth = ((constraints.maxWidth-32)/5)-5;
                                        return Row(
                                          children: [
                                            Row(
                                              children: List.generate(context.watch<CreateSerModule>().images().length, (i){
                                                return GestureDetector(
                                                    child: Container(
                                                      width: imageWidth, height: imageWidth, alignment: Alignment.topRight,
                                                      margin: EdgeInsets.only(right: i == 4 ? 0 : 6),
                                                      child: Transform.translate(
                                                        offset: Offset(3, -3),
                                                        child: GestureDetector(
                                                          child: Container(
                                                            padding: EdgeInsets.all(3),
                                                            child: Icon(Icons.close_rounded, color: Colors.white, size: 18),
                                                            decoration: BoxDecoration(color: Colors.black54, border: Border.all(color: Colors.white, width: 2), borderRadius: BorderRadius.all(Radius.circular(50))),
                                                          ),
                                                          onTap: ()=>context.read<CreateSerModule>().removeImages(i),
                                                        ),
                                                      ),
                                                      decoration: BoxDecoration(
                                                          color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 0.5),
                                                          image: DecorationImage(image: MemoryImage(context.read<CreateSerModule>().images()[i]), fit: BoxFit.cover)
                                                      ),
                                                    ),
                                                    onTap: ()=>navigateTo(context, PhotoPreviewGallery(title: 'image'.tr(), imageList: context.read<CreateSerModule>().images(), startIndex: i, isUrl: false))
                                                );
                                              }),
                                            ),
                                            context.watch<CreateSerModule>().images().length < 5 ? GestureDetector(
                                              child: Container(
                                                width: imageWidth, height: imageWidth, alignment: Alignment.center,
                                                child:  context.watch<CreateSerModule>().setLoadingEffect() ? SizedBox(
                                                  height: 30,
                                                  child: LoadingIndicator(
                                                    indicatorType: Indicator.ballPulseRise,
                                                    colors: U.defaultRainbowColors(),
                                                    strokeWidth: 1,
                                                    backgroundColor: Colors.black.withValues(alpha: 0),
                                                    pathBackgroundColor: Colors.black,
                                                  ),
                                                ) : Icon(Icons.add_rounded, color: Colors.black26, size: 40),
                                                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 2)),
                                              ),
                                              onTap: ()=>pickupImageNew(),
                                            ) : Container(),
                                          ],
                                        );
                                      },
                                    ),
                                  ) : GestureDetector(
                                    child: Container(
                                      padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
                                      decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10)), border: Border.all(color: Color(0xFF078C84)), color: Color(0xFFFFFFFF).withValues(alpha: 0.2)),
                                      child: Row(
                                        children: [
                                          U.iconsax('image', color: primaryColor, size: 30),
                                          SizedBox(width: 8,),
                                          Expanded(child: Text('addImageMsg'.tr(), style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300), maxLines: 2, overflow: TextOverflow.ellipsis)),
                                        ],
                                      ),
                                    ),
                                    onTap: ()=>pickupImageNew(),
                                  ),
                                  // Text("MBUH ==> ${U.newServerVersion(1736473802)} X ${U.retServerVersion()}"),
                                  U.newServerVersion(1736473802) ? Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      SizedBox(height: 32),
                                      Text('changePriority'.tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                                      SizedBox(height: 12),
                                      Container(
                                        height: 32,
                                        decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.circular(25.0),
                                          border: Border.all(
                                            width: 3.0,
                                            color: Colors.transparent,
                                          ),
                                          gradient: LinearGradient(
                                            colors: [
                                              Color(0xFF4FB66C).withValues(alpha: 1),
                                              Color(0xFFFFA800).withValues(alpha: 1),
                                              Color(0xFFC9223B).withValues(alpha: 1),
                                            ],
                                            begin: Alignment.topLeft,
                                            end: Alignment.bottomRight,
                                          ),
                                        ),
                                        child: Container(
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius: BorderRadius.circular(25.0),
                                          ),
                                          child: SliderTheme(
                                            data: SliderThemeData(
                                              inactiveTrackColor: Colors.white,
                                            ),
                                            child: Slider(
                                              activeColor: sliderColor,
                                              value: _currentSliderValue,
                                              max:100,
                                              divisions: 2,
                                              onChanged: (double value) {
                                                setState(() {
                                                  _currentSliderValue = value;
                                                  sliderColor = getColorScheme(value);
                                                });
                                              },
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(height: 4,),
                                      Center(
                                          child: Row(
                                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text('priorityLow'.tr(), style: TextStyle(fontSize: 12),),
                                              Text('priorityNormal'.tr(), style: TextStyle(fontSize: 12)),
                                              Text('priorityHigh'.tr(), style: TextStyle(fontSize: 12)),
                                            ],
                                          )
                                      )
                                    ],
                                  ) : SizedBox(),
                                  U.newServerVersion(1741166029) ? Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      SizedBox(height: 32),
                                      Text('referenceNumber'.tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                                      SizedBox(height: 8),
                                      SizedBox(
                                        width: double.infinity,
                                        child: TextField(
                                          controller: controllerReferenceNumber,
                                          style: TextStyle(fontSize: 14, color: Colors.black),
                                          decoration: InputDecoration(
                                              hintText: 'enterTicketNumber'.tr(),
                                              hintStyle: TextStyle(color: textColor.withValues(alpha: 0.5), fontSize: 14),
                                              filled: true,
                                              fillColor: backgroundColor,
                                              hoverColor: Colors.black.withValues(alpha: 0.1),
                                              contentPadding: EdgeInsets.all(13),
                                              prefixIcon: Padding(padding: EdgeInsets.only(left: 13, right: 13), child: U.iconsax('ticket', color: textColor, size: 24)),
                                              border: InputBorder.none,
                                              enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                              focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primaryColor)),
                                              isDense: true
                                          ),
                                        ),
                                      )
                                    ],
                                  ) : SizedBox(),
                                ],
                              ),
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                  SizedBox(width:30),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        widget.request['autoResponse'] ? Container() : Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text('yourLocation'.tr(), style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
                            !widget.request['scanToRequest'] ? GestureDetector(
                              child: Container(
                                margin: EdgeInsets.only(top: 8),
                                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 15),
                                decoration: BoxDecoration(
                                    color: Provider.of<CreateSerModule>(context).locationType()==1?primaryColor.withValues(alpha: 0.15):Colors.white,
                                    border: Border.all(color: Provider.of<CreateSerModule>(context).locationType()==1?primaryColor:textColor.withValues(alpha: 0.15)),
                                    borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12))
                                ),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    U.iconsax('location', color: textColor, size: 20),
                                    SizedBox(width: 15),
                                    Expanded(child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Text('defaultLocation'.tr(), style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300)),
                                        SizedBox(height: 5),
                                        Text(Provider.of<CreateSerModule>(context).defaultLocation(), style: TextStyle(color: textColor), maxLines: 2, overflow: TextOverflow.ellipsis)
                                      ],
                                    ))
                                  ],
                                ),
                              ),
                              onTap: (){
                                if(!widget.request['scanToRequest']) Provider.of<CreateSerModule>(context, listen: false).setLocationType(1);
                              },
                            ) : Container(),

                            GestureDetector(
                              child: Container(
                                margin: EdgeInsets.only(bottom: 20, top: widget.request['scanToRequest'] ? 8 : 0),
                                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 15),
                                decoration: BoxDecoration(
                                    color: context.watch<CreateSerModule>().locationType()==2?primaryColor.withValues(alpha: 0.15):Colors.white,
                                    border: Border.all(color: context.watch<CreateSerModule>().locationType()==2?primaryColor:textColor.withValues(alpha: 0.15)),
                                    borderRadius: widget.request['scanToRequest'] ? BorderRadius.all(Radius.circular(12.0)) : BorderRadius.only(bottomLeft: Radius.circular(12), bottomRight: Radius.circular(12))
                                ),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    U.iconsax('location', color: Color(0xffD91B1B), size: 20),
                                    SizedBox(width: 15),
                                    Expanded(
                                      child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          Text('specifyAnotherLocation'.tr(), style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300)),
                                          SizedBox(height: 5),
                                          GestureDetector(
                                            child: SizedBox(
                                              width: double.infinity,
                                              child: SearchField(
                                                focusNode: focusNodeLocation,
                                                suggestions: context.watch<CreateSerModule>().suggestion().map((e) => SearchFieldListItem(e, child: Padding(
                                                  padding: EdgeInsets.symmetric(vertical: 5, horizontal: 13),
                                                  child: Text(e, style: TextStyle(fontSize: 14, color: Colors.black)),
                                                ))).toList(),
                                                controller: controllerLocation,
                                                // searchStyle: const TextStyle(fontSize: 14, color: Colors.black),
                                                enabled: true,
                                                readOnly: false,
                                                searchInputDecoration: SearchInputDecoration(
                                                    hintText: 'placeholderLocation'.tr(),
                                                    hintStyle: TextStyle(color: textColor.withValues(alpha: 0.5), fontSize: 14),
                                                    filled: true,
                                                    fillColor: backgroundColor,
                                                    hoverColor: Colors.black.withValues(alpha: 0.1),
                                                    contentPadding: EdgeInsets.all(13),
                                                    border: InputBorder.none,
                                                    disabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                                    enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                                    focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primaryColor)),
                                                    isDense: true
                                                ),
                                                maxSuggestionsInViewPort: 3,
                                                itemHeight: 40,
                                              ),
                                            ),
                                            onTap: ()async{
                                              context.read<CreateSerModule>().setLocationType(2);
                                            },
                                            onTapCancel: () => print(" "),
                                          ),
                                        ],
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              onTap: (){
                                context.read<CreateSerModule>().setLocationType(2);
                              },
                            ),
                          ],
                        ),
                        widget.request['canNotCancel'] ? Padding(
                          padding: EdgeInsets.only(top: 15),
                          child: infoContainer('canNotCancel1'.tr()),
                        ) : Container(),
                        SizedBox(height: 10),
                        widget.request['autoResponse'] ? Container() : Container(
                          margin: EdgeInsets.only(bottom: 10),
                          width: double.infinity,
                          child: TextField(
                            controller: controllerNote,
                            style: TextStyle(fontSize: 14, color: Colors.black),
                            minLines: 1,
                            maxLines: 3,
                            keyboardType: widget.request['noteFormat'] == 'NUMBER' ? TextInputType.number : null,
                            decoration: InputDecoration(
                                hintText: 'placeholderNote'.tr(),
                                hintStyle: TextStyle(color: textColor.withValues(alpha: 0.5), fontSize: 14),
                                filled: true,
                                fillColor: backgroundColor,
                                hoverColor: Colors.black.withValues(alpha: 0.1),
                                contentPadding: EdgeInsets.all(13),
                                prefixIcon: Padding(padding: EdgeInsets.only(left: 13, right: 13), child: U.iconsax('edit-2', color: textColor, size: 24)),
                                border: InputBorder.none,
                                enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Color(0xff262626).withValues(alpha: 0.5))),
                                focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primaryColor)),
                                isDense: true
                            ),
                          ),
                        ),
                        buttonTemplate(text: 'buttonSendRequest'.tr(), action: () async{
                          if ((Provider.of<CreateSerModule>(context, listen: false).locationType() == 2 && controllerLocation.text.trim().isNotEmpty) || (Provider.of<CreateSerModule>(context, listen: false).locationType() == 1 && Provider.of<CreateSerModule>(context, listen: false).defaultLocation() != '')) {
                            if (controllerNote.text.length <= 128) {
                              if (widget.user['roomAttendant'] && Provider.of<CreateSerModule>(context, listen: false).others() == 1){
                                if (controllerUserId.text.trim().isNotEmpty){
                                  if (controllerDateString.text.trim().isEmpty && widget.request['noteFormat'] == 'DATE'){
                                    showError(context, 'dateRequired'.tr());
                                  } else {
                                    reqFunc.sendRequestToOthers(context, widget, controllerUserId, controllerNote, controllerReferenceNumber, controllerLocation, controllerDateString, _currentSliderValue);
                                  }
                                } else {
                                  showError(context, 'idRequired'.tr());
                                }
                              } else if (controllerDateString.text.trim().isNotEmpty && widget.request['noteFormat'] == 'DATE'){
                                dialogSendLater();
                              } else {
                                reqFunc.sendRequest(context, widget, controllerNote, controllerReferenceNumber, controllerLocation, controllerDateString, _currentSliderValue);
                              }
                            } else {
                              showError(context, 'lengthMax'.tr());
                            }
                          } else {
                            showError(context, 'locRequired'.tr());
                          }
                        })
                      ],
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  dialogSendLater(){
    showDialog(
      context: context,
      builder: (contexts) => AlertDialog(
        title: Text('sendingOpt'.tr(), style: TextStyle(color: textColor, fontSize: 16, fontWeight: FontWeight.w500)),
        titlePadding: EdgeInsets.all(20),
        contentPadding: EdgeInsets.fromLTRB(20, 4, 20, 28),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text('sendingOptMsg'.tr(), style: TextStyle(fontSize: 14, color: textColor)),
            SizedBox(height: 12),
            Row(
              children: [
                Expanded(
                  child: GestureDetector(
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 20),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          U.iconsax('timer-start', color: Colors.white, size: 30),
                          SizedBox(height: 9),
                          Text('scheduled'.tr(), style: TextStyle(color: Colors.white, fontSize: 14))
                        ],
                      ),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(12)),
                          gradient: LinearGradient(
                              begin: Alignment.topLeft, end: Alignment.bottomRight,
                              colors: [
                                Color(0xff131480).withValues(alpha: 0.56), Color(0xff131480).withValues(alpha: 0.90), Color(0xff131480).withValues(alpha: 0.75)
                              ]
                          )
                      ),
                    ),
                    onTap: (){
                      navigateBack(contexts);
                      Provider.of<CreateSerModule>(context, listen: false).setSendLater(true);
                      reqFunc.sendRequest(context, widget, controllerNote, controllerLocation, controllerReferenceNumber, controllerDateString, _currentSliderValue);
                    },
                  ),
                ),
                SizedBox(width: 16),
                Expanded(
                  child: GestureDetector(
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 20),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          U.iconsax('star-1', color: Colors.white, size: 30),
                          SizedBox(height: 9),
                          Text('sendNow'.tr(), style: TextStyle(color: Colors.white, fontSize: 14))
                        ],
                      ),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(12)),
                          gradient: LinearGradient(
                              begin: Alignment.topLeft, end: Alignment.bottomRight,
                              colors: [
                                Color(0xff078C84).withValues(alpha: 0.56), Color(0xff078C84).withValues(alpha: 0.90), Color(0xff078C84).withValues(alpha: 0.75)
                              ]
                          )
                      ),
                    ),
                    onTap: (){
                      navigateBack(contexts);
                      reqFunc.sendRequest(context, widget, controllerNote, controllerReferenceNumber, controllerLocation, controllerDateString, _currentSliderValue);
                    },
                  ),
                ),
              ],
            ),
            SizedBox(height: 12),
            divider(),
            SizedBox(height: 12),
            Container(
              padding: EdgeInsets.all(3),
              child: Text('scheduledMsg'.tr(), style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300)),
              decoration: BoxDecoration(
                  color: Color(0xffCCA600).withValues(alpha: 0.2),
                  borderRadius: BorderRadius.all(Radius.circular(3))
              ),
            )
          ],
        ),
      ),
    );
  }

  pickupImageNew()async{
    await reqFunc.getImageNew(context, ImageSource.gallery).then((img){
      img != null ? Provider.of<CreateSerModule>(context, listen: false).setImages(img) : null;
    });
  }
}
