import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:intl/intl.dart';
import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/memoranda/memoranda_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/admin/signatories/signatories_admin_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/building/assessment_offline/bldg_assessment_offline_bloc.dart';
import 'package:unit2/screens/offline/passo/building/edit/edit_building.dart';
import 'package:unit2/theme-data.dart/colors.dart';

import '../../../../../model/offline/offline_profile.dart';
import '../../../../../model/passo/memoranda.dart';
import '../../../../../model/passo/property_assessment.dart';
import '../../../../../model/passo/property_assessment_edit.dart';
import '../../../../../model/passo/signatories.dart';
import '../../../../../theme-data.dart/form-style.dart';
import '../../../../../widgets/passo/custom_formBuilder_fields.dart';

class PropertyAssessmentEditOfflinePage extends StatefulWidget {
  int tempId;
  Function onSAve;
  final OfflineProfile offlineProfile;
  PropertyAssessmentEditOfflinePage(
      this.tempId, this.onSAve, this.offlineProfile);
  @override
  _PropertyAssessmentEditOfflinePage createState() =>
      _PropertyAssessmentEditOfflinePage();
}

class _PropertyAssessmentEditOfflinePage
    extends State<PropertyAssessmentEditOfflinePage> {
  double assessment_level = 0;
  bool isTaxable = false;
  bool isExempt = false;
  String _memoranda = '';
  String _notes = "";
  String appraised_by = "";
  String rec_by = "";
  String approved_by = "";
  String appraised_by_designation = "";
  String rec_by_designation = "";
  String approved_by_designation = "";
  final focus = FocusNode();
  final focuss = FocusNode();
  final appraisedByFocus = FocusNode();
  final recByFocus = FocusNode();
  final apprvdByFocus = FocusNode();
  final quarter = ['1st', '2nd', '3rd', '4th'];

  TextEditingController memorandaController = TextEditingController();
  TextEditingController noteController = TextEditingController();

  String assessmentLevel(marketValues, property_class) {
    final marketValue = double.parse(marketValues);
    switch (property_class) {
      case 'Residential':
        if (marketValue < 175000) {
          // setState(() {
          //   assessment_level = 0;
          // });
          return '0 ';
        } else if (marketValue < 300000 && marketValue > 175000) {
          // setState(() {
          //   assessment_level = 0.10;
          // });
          return '10 ';
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.20;
          // });
          return '20 ';
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.25;
          // });
          return '25 ';
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return '30 ';
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return '35 ';
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return '40 ';
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return '50 ';
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return '60 ';
        }
        break;
      case 'Agricultural':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.45;
          // });
          return '45 ';
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return '50 ';
        } else if (marketValue < 750000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.55;
          // });
          return '55 ';
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return '60 ';
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.65;
          // });
          return '65 ';
        } else if (marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return '70 ';
        }
        break;
      case 'Commercial':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return '30 ';
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return '35 ';
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return '40 ';
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return '50 ';
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return '60 ';
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return '70 ';
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.75;
          // });
          return '75 ';
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.80;
          // });
        }
        break;
      case 'Industrial':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return '30 ';
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return '35 ';
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return '40 ';
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return '50 ';
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return '60 ';
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return '70 ';
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.75;
          // });
          return '75 ';
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.80;
          // });
          return '80 ';
        }
        break;
      case 'Mineral':
        break;
      case 'Timberland':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.45;
          // });
          return '45 ';
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return '50 ';
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.55;
          // });
          return '55 ';
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return '60 ';
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.65;
          // });
          return '65 ';
        } else if (marketValue < 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return '70 ';
        }
        break;
      default:
    }
    return '';
  }

  double assessmentValue(marketValues, property_class) {
    final marketValue = double.parse(marketValues);
    switch (property_class) {
      case 'Residential':
        if (marketValue < 175000) {
          // setState(() {
          //   assessment_level = 0;
          // });
          return marketValue * 0;
        } else if (marketValue < 300000 && marketValue > 175000) {
          // setState(() {
          //   assessment_level = 0.10;
          // });
          return marketValue * 0.10;
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.20;
          // });
          return marketValue * 0.20;
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.25;
          // });
          return marketValue * 0.25;
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return marketValue * 0.30;
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return marketValue * 0.35;
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return marketValue * 0.40;
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return marketValue * 0.50;
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return marketValue * 0.60;
        }
        break;
      case 'Agricultural':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.45;
          // });
          return marketValue * 0.45;
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return marketValue * 0.50;
        } else if (marketValue < 750000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.55;
          // });
          return marketValue * 0.55;
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return marketValue * 0.60;
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.65;
          // });
          return marketValue * 0.65;
        } else if (marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return marketValue * 0.70;
        }
        break;
      case 'Commercial':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return marketValue * 0.30;
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return marketValue * 0.35;
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return marketValue * 0.40;
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return marketValue * 0.50;
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return marketValue * 0.60;
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return marketValue * 0.70;
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.75;
          // });
          return marketValue * 0.75;
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.80;
          // });
        }
        break;
      case 'Industrial':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.30;
          // });
          return marketValue * 0.30;
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.35;
          // });
          return marketValue * 0.35;
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.40;
          // });
          return marketValue * 0.40;
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return marketValue * 0.50;
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return marketValue * 0.60;
        } else if (marketValue < 5000000 && marketValue > 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return marketValue * 0.70;
        } else if (marketValue < 10000000 && marketValue > 5000000) {
          // setState(() {
          //   assessment_level = 0.75;
          // });
          return marketValue * 0.75;
        } else if (marketValue > 10000000) {
          // setState(() {
          //   assessment_level = 0.80;
          // });
          return marketValue * 0.80;
        }
        break;
      case 'Mineral':
        break;
      case 'Timberland':
        if (marketValue < 300000) {
          // setState(() {
          //   assessment_level = 0.45;
          // });
          return marketValue * 0.45;
        } else if (marketValue < 500000 && marketValue > 300000) {
          // setState(() {
          //   assessment_level = 0.50;
          // });
          return marketValue * 0.50;
        } else if (marketValue < 750000 && marketValue > 500000) {
          // setState(() {
          //   assessment_level = 0.55;
          // });
          return marketValue * 0.55;
        } else if (marketValue < 1000000 && marketValue > 750000) {
          // setState(() {
          //   assessment_level = 0.60;
          // });
          return marketValue * 0.60;
        } else if (marketValue < 2000000 && marketValue > 1000000) {
          // setState(() {
          //   assessment_level = 0.65;
          // });
          return marketValue * 0.65;
        } else if (marketValue < 2000000) {
          // setState(() {
          //   assessment_level = 0.70;
          // });
          return marketValue * 0.70;
        }
        break;
      default:
    }
    return 0;
  }

  @override
  Widget build(BuildContext context) {
    var width = MediaQuery.of(context).size.width;
    return ProgressHUD(
      padding: const EdgeInsets.all(24),
      backgroundColor: Colors.black87,
      indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
      child:
          BlocConsumer<BldgAssessmentOfflineBloc, BldgAssessmentOfflineState>(
        listener: (context, state) {
          // if (state is PropertyAssessmentEditLoading) {
          //   final progress = ProgressHUD.of(context);
          //   progress!.showWithText("Please wait...");
          // }
          if (state is SpecificBldgAssessmentLoaded) {
            setState(() {
              isTaxable = state.assessment.taxable == '1' ? true : false;
              isExempt = state.assessment.exempt == '1' ? true : false;
              memorandaController.text = state.assessment.memoranda;
              _memoranda = state.assessment.memoranda;
              noteController.text = state.assessment.note;
              _notes = state.assessment.note;
              appraised_by_designation =
                  state.assessment.appraisedbyDesignation!;
              rec_by_designation = state.assessment.recommendapprDesignation!;
              approved_by_designation = state.assessment.approvedbyDesignation!;
            });
          }
          // if (state is PropertyAssessmentEditErrorState) {
          //   final progress = ProgressHUD.of(context);
          //   progress?.dismiss();
          // }
        },
        builder: (context, state) {
          if (state is SpecificBldgAssessmentLoaded) {
            final assessment = state.assessment;
            return BlocConsumer<SignatoriesAdminBloc, SignatoriesAdminState>(
              listener: (context, state) {
                // if (state is SignatoriesLoading) {
                //   final progress = ProgressHUD.of(context);
                //   progress!.showWithText("Please wait...");
                // }

                // if (state is SignatoriesErrorState) {
                //   final progress = ProgressHUD.of(context);
                //   progress?.dismiss();
                // }
              },
              builder: (context, state) {
                if (state is SignatoriesLoaded) {
                  final signatories = state.signatories;

                  return BlocConsumer<MemorandaAdminBloc, MemorandaAdminState>(
                    listener: (context, state) {
                      // if (state is MemorandaLoading) {
                      //   final progress = ProgressHUD.of(context);
                      //   progress!.showWithText("Please wait...");
                      // }
                      // if (state is MemorandaLoaded) {
                      //   final progress = ProgressHUD.of(context);
                      //   progress?.dismiss();
                      // }
                      // if (state is MemorandaErrorState) {
                      //   final progress = ProgressHUD.of(context);
                      //   progress?.dismiss();
                      // }
                    },
                    builder: (context, state) {
                      if (state is MemorandaLoaded) {
                        final memoranda = state.memo;
                        final note = state.memo;
                        return Padding(
                          padding: const EdgeInsets.all(20.0),
                          child: FormBuilder(
                            key: offlineBldgEditKey,
                            initialValue: {
                              'qtr': assessment.qtr?.toString() ?? '',
                              'yr': assessment.yr?.toString() ?? '',
                              'app_date':
                                  assessment.appraisedbyDate?.toString() ?? '',
                              'rec_date':
                                  assessment.recommendapprDate?.toString() ??
                                      '',
                              'sworn_statement':
                                  assessment.swornstatementNo ?? '',
                              'date_received':
                                  assessment.dateReceived?.toString() ?? '',
                              'date_of_entry':
                                  assessment.entryDateAssessment?.toString() ??
                                      '',
                              'approve_date':
                                  assessment.approvedbyDate?.toString() ?? '',
                            },
                            enabled: true,
                            onChanged: () {
                              offlineBldgEditKey.currentState!.save();
                              debugPrint(offlineBldgEditKey.currentState!.value
                                  .toString());
                            },
                            autovalidateMode: AutovalidateMode.disabled,
                            skipDisabled: true,
                            child: Column(
                              children: [
                                Container(
                                  margin:
                                      const EdgeInsets.fromLTRB(0, 20, 0, 20),
                                  child: const Text(
                                    'PROPERTY ASSESSMENT cont..',
                                    style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18,
                                    ),
                                    textAlign: TextAlign.left,
                                  ),
                                ),
                                Expanded(
                                  child: Container(
                                    margin: const EdgeInsets.symmetric(
                                        horizontal: 20),
                                    child: SingleChildScrollView(
                                      scrollDirection: Axis.vertical,
                                      child: Column(
                                        children: [
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceAround,
                                            children: [
                                              Row(
                                                children: [
                                                  const Text('Taxable'),
                                                  Checkbox(
                                                    checkColor: Colors.white,
                                                    value: isTaxable,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        isTaxable = value!;
                                                      });
                                                    },
                                                  )
                                                ],
                                              ),
                                              Row(
                                                children: [
                                                  const Text('Exempt'),
                                                  Checkbox(
                                                    checkColor: Colors.white,
                                                    value: isExempt,
                                                    onChanged: (bool? value) {
                                                      setState(() {
                                                        isExempt = value!;
                                                      });
                                                    },
                                                  )
                                                ],
                                              ),
                                            ],
                                          ),
                                          Column(
                                            children: [
                                              const SizedBox(
                                                height: 20,
                                              ),
                                              const Text(
                                                'EFFECTIVITY OF ASSESSMENT / REASSESSMENT  / SWORN STATEMENT:',
                                                style: TextStyle(
                                                    fontWeight:
                                                        FontWeight.bold),
                                              ),
                                              const SizedBox(
                                                height: 20,
                                              ),
                                              SingleChildScrollView(
                                                scrollDirection:
                                                    Axis.horizontal,
                                                child: Row(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment
                                                          .spaceAround,
                                                  children: [
                                                    SizedBox(
                                                        width: 90,
                                                        height: 50,
                                                        child:
                                                            customDropDownField(
                                                                'Qtr',
                                                                '',
                                                                'qtr',
                                                                quarter)),
                                                    SizedBox(
                                                      width: 10,
                                                    ),
                                                    SizedBox(
                                                        width: 100,
                                                        height: 50,
                                                        child: customTextField(
                                                            'Sworn Statement No.',
                                                            '',
                                                            'sworn_statement',
                                                            TextInputType
                                                                .number)),
                                                    SizedBox(
                                                      width: 10,
                                                    ),
                                                    SizedBox(
                                                        width: 90,
                                                        height: 50,
                                                        child: customTextField(
                                                            'Year',
                                                            '',
                                                            'yr',
                                                            TextInputType
                                                                .number)),
                                                  ],
                                                ),
                                              ),
                                            ],
                                          ),
                                          const SizedBox(
                                            height: 10,
                                          ),
                                          Divider(
                                            thickness: 2,
                                          ),
                                          Row(
                                            children: [
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Expanded(
                                                child: SizedBox(
                                                    width: width / 2 - 100,
                                                    height: 50,
                                                    child: customDatTimePicker(
                                                        'Date Received',
                                                        '',
                                                        'date_received')),
                                              ),
                                              const SizedBox(
                                                width: 20,
                                              ),
                                              Expanded(
                                                child: SizedBox(
                                                    width: width / 2 - 100,
                                                    height: 50,
                                                    child: customDatTimePicker(
                                                        'Date of Entry',
                                                        '',
                                                        'date_of_entry')),
                                              )
                                            ],
                                          ),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          const Align(
                                            alignment: Alignment.centerLeft,
                                            child: Text(
                                              'APPRAISED/ASSESSED BY:',
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold),
                                              textAlign: TextAlign.start,
                                            ),
                                          ),
                                          SingleChildScrollView(
                                            scrollDirection: Axis.horizontal,
                                            child: Row(children: [
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  const Text('Name'),
                                                  Container(
                                                    padding:
                                                        EdgeInsets.fromLTRB(
                                                            20, 0, 0, 0),
                                                    margin: const EdgeInsets
                                                        .fromLTRB(0, 10, 0, 0),
                                                    width: 250,
                                                    decoration: BoxDecoration(
                                                      border: Border.all(
                                                        color: Colors
                                                            .grey, // You can set the color here
                                                        width:
                                                            0.9, // You can set the width here
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5), // Set the border radius here
                                                    ),
                                                    child: SearchField(
                                                      itemHeight: 65,
                                                      hint: assessment
                                                          .appraisedbyName,
                                                      suggestions: signatories
                                                          .map((Signatories
                                                                  signatories) =>
                                                              SearchFieldListItem(
                                                                  '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname}',
                                                                  item:
                                                                      signatories,
                                                                  child:
                                                                      ListTile(
                                                                    title: Text(
                                                                      '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname!}',
                                                                      overflow:
                                                                          TextOverflow
                                                                              .ellipsis,
                                                                      textAlign:
                                                                          TextAlign
                                                                              .center,
                                                                    ),
                                                                  )))
                                                          .toList(),

                                                      validator:
                                                          FormBuilderValidators
                                                              .required(
                                                                  errorText:
                                                                      "This field is required"),
                                                      searchStyle: TextStyle(),

                                                      ////agency suggestion tap
                                                      focusNode:
                                                          appraisedByFocus,
                                                      suggestionState:
                                                          Suggestion.expand,
                                                      onSuggestionTap:
                                                          (appraised) {
                                                        setState(() {
                                                          appraised_by =
                                                              "${appraised.item?.firstname} ${appraised.item?.middlename} ${appraised.item?.lastname}";
                                                          appraised_by_designation =
                                                              appraised.item!
                                                                  .designation;
                                                        });
                                                        appraisedByFocus
                                                            .unfocus();
                                                      },
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Designation'),
                                                  Container(
                                                      padding:
                                                          EdgeInsets.fromLTRB(
                                                              10, 15, 10, 10),
                                                      margin: const EdgeInsets
                                                          .fromLTRB(
                                                          0, 10, 0, 0),
                                                      width: 250,
                                                      height: 50,
                                                      decoration: BoxDecoration(
                                                        border: Border.all(
                                                          color: Colors
                                                              .grey, // You can set the color here
                                                          width:
                                                              0.9, // You can set the width here
                                                        ),
                                                        borderRadius:
                                                            BorderRadius.circular(
                                                                5), // Set the border radius here
                                                      ),
                                                      child: Text(
                                                        appraised_by_designation
                                                            .toUpperCase(),
                                                        style: TextStyle(
                                                            fontSize: 15),
                                                        textAlign:
                                                            TextAlign.center,
                                                      )),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Date'),
                                                  Container(
                                                      width: 100,
                                                      child:
                                                          customDatTimePicker(
                                                              '',
                                                              '',
                                                              'app_date')),
                                                ],
                                              ),
                                            ]),
                                          ),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          const Align(
                                              alignment: Alignment.centerLeft,
                                              child: Text(
                                                'RECOMMENDING APPROVAL:',
                                                style: TextStyle(
                                                    fontWeight:
                                                        FontWeight.bold),
                                              )),
                                          SingleChildScrollView(
                                            scrollDirection: Axis.horizontal,
                                            child: Row(children: [
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  const Text('Name'),
                                                  Container(
                                                    padding:
                                                        EdgeInsets.fromLTRB(
                                                            20, 0, 0, 0),
                                                    margin: const EdgeInsets
                                                        .fromLTRB(0, 10, 0, 0),
                                                    width: 250,
                                                    decoration: BoxDecoration(
                                                      border: Border.all(
                                                        color: Colors
                                                            .grey, // You can set the color here
                                                        width:
                                                            0.9, // You can set the width here
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5), // Set the border radius here
                                                    ),
                                                    child: SearchField(
                                                      itemHeight: 65,
                                                      hint: assessment
                                                          .recommendapprName,
                                                      suggestions: signatories
                                                          .map((Signatories
                                                                  signatories) =>
                                                              SearchFieldListItem(
                                                                  '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname}',
                                                                  item:
                                                                      signatories,
                                                                  child:
                                                                      ListTile(
                                                                    title: Text(
                                                                      '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname!}',
                                                                      overflow:
                                                                          TextOverflow
                                                                              .ellipsis,
                                                                      textAlign:
                                                                          TextAlign
                                                                              .center,
                                                                    ),
                                                                  )))
                                                          .toList(),

                                                      validator:
                                                          FormBuilderValidators
                                                              .required(
                                                                  errorText:
                                                                      "This field is required"),
                                                      searchStyle: TextStyle(),

                                                      ////agency suggestion tap
                                                      focusNode: recByFocus,
                                                      suggestionState:
                                                          Suggestion.expand,
                                                      onSuggestionTap:
                                                          (appraised) {
                                                        setState(() {
                                                          rec_by =
                                                              "${appraised.item?.firstname} ${appraised.item?.middlename} ${appraised.item?.lastname}";
                                                          rec_by_designation =
                                                              appraised.item!
                                                                  .designation;
                                                        });
                                                        recByFocus.unfocus();
                                                      },
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Designation'),
                                                  Container(
                                                      padding:
                                                          EdgeInsets.fromLTRB(
                                                              10, 15, 10, 10),
                                                      margin: const EdgeInsets
                                                          .fromLTRB(
                                                          0, 10, 0, 0),
                                                      width: 250,
                                                      height: 50,
                                                      decoration: BoxDecoration(
                                                        border: Border.all(
                                                          color: Colors
                                                              .grey, // You can set the color here
                                                          width:
                                                              0.9, // You can set the width here
                                                        ),
                                                        borderRadius:
                                                            BorderRadius.circular(
                                                                5), // Set the border radius here
                                                      ),
                                                      child: Text(
                                                        rec_by_designation
                                                            .toUpperCase(),
                                                        style: TextStyle(
                                                            fontSize: 15),
                                                        textAlign:
                                                            TextAlign.center,
                                                      )),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Date'),
                                                  Container(
                                                      width: 100,
                                                      child:
                                                          customDatTimePicker(
                                                              '',
                                                              '',
                                                              'rec_date')),
                                                ],
                                              ),
                                            ]),
                                          ),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          const Align(
                                              alignment: Alignment.centerLeft,
                                              child: Text(
                                                'APPROVED BY:',
                                                style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              )),
                                          SingleChildScrollView(
                                            scrollDirection: Axis.horizontal,
                                            child: Row(children: [
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  const Text('Name'),
                                                  Container(
                                                    padding:
                                                        EdgeInsets.fromLTRB(
                                                            20, 0, 0, 0),
                                                    margin: const EdgeInsets
                                                        .fromLTRB(0, 10, 0, 0),
                                                    width: 250,
                                                    decoration: BoxDecoration(
                                                      border: Border.all(
                                                        color: Colors
                                                            .grey, // You can set the color here
                                                        width:
                                                            0.9, // You can set the width here
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5), // Set the border radius here
                                                    ),
                                                    child: SearchField(
                                                      itemHeight: 65,
                                                      hint: assessment
                                                          .approvedbyName,
                                                      suggestions: signatories
                                                          .map((Signatories
                                                                  signatories) =>
                                                              SearchFieldListItem(
                                                                  '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname}',
                                                                  item:
                                                                      signatories,
                                                                  child:
                                                                      ListTile(
                                                                    title: Text(
                                                                      '${signatories.firstname}  ${signatories.middlename}  ${signatories.lastname!}',
                                                                      overflow:
                                                                          TextOverflow
                                                                              .ellipsis,
                                                                      textAlign:
                                                                          TextAlign
                                                                              .center,
                                                                    ),
                                                                  )))
                                                          .toList(),

                                                      validator:
                                                          FormBuilderValidators
                                                              .required(
                                                                  errorText:
                                                                      "This field is required"),
                                                      searchStyle: TextStyle(),

                                                      ////agency suggestion tap
                                                      focusNode: apprvdByFocus,
                                                      suggestionState:
                                                          Suggestion.expand,
                                                      onSuggestionTap:
                                                          (appraised) {
                                                        setState(() {
                                                          approved_by =
                                                              "${appraised.item?.firstname} ${appraised.item?.middlename} ${appraised.item?.lastname}";
                                                          approved_by_designation =
                                                              appraised.item!
                                                                  .designation;
                                                        });
                                                        apprvdByFocus.unfocus();
                                                      },
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Designation'),
                                                  Container(
                                                      padding:
                                                          EdgeInsets.fromLTRB(
                                                              10, 15, 10, 10),
                                                      margin: const EdgeInsets
                                                          .fromLTRB(
                                                          0, 10, 0, 0),
                                                      width: 250,
                                                      height: 50,
                                                      decoration: BoxDecoration(
                                                        border: Border.all(
                                                          color: Colors
                                                              .grey, // You can set the color here
                                                          width:
                                                              0.9, // You can set the width here
                                                        ),
                                                        borderRadius:
                                                            BorderRadius.circular(
                                                                5), // Set the border radius here
                                                      ),
                                                      child: Text(
                                                        approved_by_designation
                                                            .toUpperCase(),
                                                        style: TextStyle(
                                                            fontSize: 15),
                                                        textAlign:
                                                            TextAlign.center,
                                                      )),
                                                ],
                                              ),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text('Date'),
                                                  Container(
                                                      width: 100,
                                                      child:
                                                          customDatTimePicker(
                                                              '',
                                                              '',
                                                              'approve_date')),
                                                ],
                                              ),
                                            ]),
                                          ),
                                          const SizedBox(
                                            height: 50,
                                          ),
                                          const Align(
                                              alignment: Alignment.centerLeft,
                                              child: Text(
                                                'MEMORANDA: ',
                                                style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              )),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          SizedBox(
                                              width: 500,
                                              height: 50,
                                              child: SearchField(
                                                itemHeight: 200,
                                                controller: memorandaController,
                                                suggestions: memoranda
                                                    .map(
                                                        (Memoranda memoranda) =>
                                                            SearchFieldListItem(
                                                              '${memoranda.memoranda}',
                                                              item:
                                                                  memoranda, // Change: Use individual Memoranda object
                                                              child: ListTile(
                                                                title: Text(
                                                                  '${memoranda.memoranda}',
                                                                  overflow:
                                                                      TextOverflow
                                                                          .visible,
                                                                ),
                                                              ),
                                                            ))
                                                    .toList(),
                                                validator: FormBuilderValidators
                                                    .required(
                                                        errorText:
                                                            "This field is required"),
                                                // searchInputDecoration:
                                                //     normalTextFieldStyle("Memoranda", "")
                                                //         .copyWith(
                                                //   suffixIcon:
                                                //       const Icon(Icons.arrow_drop_down),
                                                //   contentPadding: EdgeInsets.symmetric(
                                                //       vertical: 15.0, horizontal: 16.0),
                                                //   border: OutlineInputBorder(
                                                //     borderRadius: BorderRadius.circular(10.0),
                                                //     borderSide: BorderSide(
                                                //       color:
                                                //           Colors.grey, // Adjust border color
                                                //     ),
                                                //   ),
                                                //   focusedBorder: OutlineInputBorder(
                                                //     borderRadius: BorderRadius.circular(10.0),
                                                //     borderSide: BorderSide(
                                                //       color: Colors
                                                //           .blue, // Adjust focused border color
                                                //     ),
                                                //   ),
                                                // ),
                                                focusNode: focuss,
                                                suggestionState:
                                                    Suggestion.expand,
                                                suggestionDirection:
                                                    SuggestionDirection.up,
                                                onSuggestionTap: (memoranda) {
                                                  setState(() {
                                                    _memoranda =
                                                        memorandaController
                                                            .text;
                                                  });
                                                  focus.unfocus();
                                                },
                                              )),
                                          Container(
                                            alignment: Alignment.center,
                                            padding: EdgeInsets.all(10),
                                            child: Column(
                                              children: [
                                                TextField(
                                                  controller:
                                                      memorandaController,
                                                  keyboardType:
                                                      TextInputType.multiline,
                                                  maxLines: 7,
                                                  decoration: InputDecoration(
                                                    focusedBorder:
                                                        OutlineInputBorder(
                                                            borderSide: BorderSide(
                                                                width: 1,
                                                                color: Colors
                                                                    .redAccent)),
                                                    disabledBorder:
                                                        OutlineInputBorder(
                                                      borderSide:
                                                          const BorderSide(
                                                        width: 1,
                                                        color: Colors.grey,
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5),
                                                    ),
                                                    enabledBorder:
                                                        OutlineInputBorder(
                                                      borderSide:
                                                          const BorderSide(
                                                        color: Colors.grey,
                                                        width: 1,
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5),
                                                    ),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          const Align(
                                              alignment: Alignment.centerLeft,
                                              child: Text(
                                                'NOTE: ',
                                                style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              )),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          SizedBox(
                                              width: 400,
                                              height: 50,
                                              child: SearchField(
                                                itemHeight: 200,
                                                controller: noteController,
                                                suggestions: note
                                                    .map((Memoranda note) =>
                                                        SearchFieldListItem(
                                                          '${note.memoranda}',
                                                          item:
                                                              note, // Change: Use individual Memoranda object
                                                          child: ListTile(
                                                            title: Text(
                                                              '${note.memoranda}',
                                                              overflow:
                                                                  TextOverflow
                                                                      .visible,
                                                            ),
                                                          ),
                                                        ))
                                                    .toList(),
                                                validator: FormBuilderValidators
                                                    .required(
                                                        errorText:
                                                            "This field is required"),
                                                searchInputDecoration:
                                                    InputDecoration().copyWith(
                                                  suffixIcon: const Icon(
                                                      Icons.arrow_drop_down),
                                                ),
                                                focusNode: focus,
                                                suggestionState:
                                                    Suggestion.expand,
                                                suggestionDirection:
                                                    SuggestionDirection.up,
                                                onSuggestionTap: (memoranda) {
                                                  setState(() {
                                                    _notes =
                                                        noteController.text;
                                                  });
                                                  focus.unfocus();
                                                },
                                              )),
                                          Container(
                                            alignment: Alignment.center,
                                            padding: EdgeInsets.all(10),
                                            child: Column(
                                              children: [
                                                TextField(
                                                  controller: noteController,
                                                  keyboardType:
                                                      TextInputType.multiline,
                                                  maxLines: 7,
                                                  decoration: InputDecoration(
                                                    focusedBorder:
                                                        OutlineInputBorder(
                                                            borderSide: BorderSide(
                                                                width: 1,
                                                                color: Colors
                                                                    .redAccent)),
                                                    disabledBorder:
                                                        OutlineInputBorder(
                                                      borderSide:
                                                          const BorderSide(
                                                        width: 1,
                                                        color: Colors.grey,
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5),
                                                    ),
                                                    enabledBorder:
                                                        OutlineInputBorder(
                                                      borderSide:
                                                          const BorderSide(
                                                        color: Colors.grey,
                                                        width: 1,
                                                      ),
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              5),
                                                    ),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          const SizedBox(
                                            height: 30,
                                          ),
                                          SizedBox(
                                            width: MediaQuery.of(context)
                                                .size
                                                .width,
                                            child: ElevatedButton(
                                              style: ElevatedButton.styleFrom(
                                                  backgroundColor: primary,
                                                  foregroundColor: Colors.red),
                                              child: const SizedBox(
                                                width: 200,
                                                height: 50,
                                                child: Align(
                                                  alignment: Alignment.center,
                                                  child: Text(
                                                    'Save',
                                                    style: TextStyle(
                                                      color: Colors.white,
                                                    ),
                                                    textAlign: TextAlign.center,
                                                  ),
                                                ),
                                              ),
                                              onPressed: () {
                                                offlineBldgEditKey.currentState!
                                                    .save();
                                                var ass = PropertyAssessment(
                                                    id: 1,
                                                    bldgapprDetailsId:
                                                        widget.tempId,
                                                    assessedById: widget
                                                        .offlineProfile.id
                                                        .toString(),
                                                    assessedByName: widget
                                                        .offlineProfile
                                                        .firstName!,
                                                    dateCreated: "None",
                                                    dateModified: "None",
                                                    actualUse:
                                                        assessment.actualUse,
                                                    marketValue: '0.0',
                                                    assessmentLevel: '0.0',
                                                    assessedValue: "1.0",
                                                    taxable: isTaxable == true
                                                        ? '1'
                                                        : '0',
                                                    exempt: isExempt == true
                                                        ? '1'
                                                        : '0',
                                                    qtr: offlineBldgEditKey
                                                        .currentState!
                                                        .value['qtr'],
                                                    yr: offlineBldgEditKey
                                                        .currentState!
                                                        .value['yr'],
                                                    appraisedbyName: appraised_by == ""
                                                        ? assessment
                                                            .appraisedbyName
                                                        : appraised_by,
                                                    appraisedbyDate:
                                                        offlineBldgEditKey.currentState!.value['app_date'].toString(),
                                                    recommendapprName: rec_by == "" ? assessment.recommendapprName : rec_by,
                                                    recommendapprDate: offlineBldgEditKey.currentState!.value['rec_date'].toString(),
                                                    approvedbyName: approved_by == "" ? assessment.approvedbyName : approved_by,
                                                    approvedbyDate: offlineBldgEditKey.currentState!.value['approve_date'].toString(),
                                                    memoranda: _memoranda,
                                                    note: _notes,
                                                    swornstatementNo: offlineBldgEditKey.currentState!.value['sworn_statement'],
                                                    dateReceived: offlineBldgEditKey.currentState!.value['date_received'].toString(),
                                                    entryDateAssessment: offlineBldgEditKey.currentState!.value['date_of_entry'].toString(),
                                                    entryDateBy: "none",
                                                    genCode: '5th',
                                                    appraisedbyDesignation: appraised_by_designation == "" ? assessment.appraisedbyDesignation : appraised_by_designation,
                                                    approvedbyDesignation: approved_by_designation == "" ? assessment.approvedbyDesignation : approved_by_designation,
                                                    recommendapprDesignation: rec_by_designation == "" ? assessment.recommendapprDesignation : rec_by_designation);

                                                context
                                                    .read<
                                                        BldgAssessmentOfflineBloc>()
                                                    .add(UpdateBldgAssessment(
                                                        id: widget.tempId,
                                                        assessment: ass));

                                                widget.onSAve();
                                              },
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                        );
                      }
                      // if (state is MemorandaErrorState) {
                      //   return SomethingWentWrong(
                      //     message: state.error,
                      //     onpressed: () {
                      //       context
                      //           .read<MemorandaBloc>()
                      //           .add(const LoadMemoranda());
                      //     },
                      //   );
                      // }
                      return Container();
                    },
                  );
                }
                // if (state is SignatoriesErrorState) {
                //   return SomethingWentWrong(
                //     message: state.error,
                //     onpressed: () {
                //       context
                //           .read<SignatoriesBloc>()
                //           .add(const LoadSignatories());
                //     },
                //   );
                // }
                return Container();
              },
            );
          }
          // if (state is PropertyAssessmentEditErrorState) {
          //   return SomethingWentWrong(
          //     message: state.error,
          //     onpressed: () {
          //       context.read<PropertyAssessmentEditBloc>().add(
          //           LoadPropertyAssessmentEdit(
          //               assessmentsEdit: PropertyAssessmentEdit(),
          //               id: widget.tempId));
          //     },
          //   );
          // }
          return Container();
        },
      ),
    );
  }
}
