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: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/model/passo/sworn_statement.dart';
import 'package:unit2/screens/offline/passo/building/edit/edit_building.dart';
import 'package:unit2/theme-data.dart/colors.dart';

import '../../../../../bloc/offline/offline_passo/building/swornstatement/sworn_statement_bloc.dart';
import '../../../../../model/offline/offline_profile.dart';
import '../../../../../model/passo/memoranda.dart';
import '../../../../../model/passo/property_assessment.dart';
import '../../../../../model/passo/signatories.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;
  bool isOwner = false;
  bool isRepresentative = 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'];
  final civilStatus = ["Single", "Married", "Divorced", "Separated", "Widowed"];

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

  @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<SwornStatementBloc, SwornStatementState>(
            listener: (context, state) {
          // TODO: implement listener
        }, builder: (context, state) {
          if (state is SpecificSwornStatementLoaded) {
            final sworn = state.swornStatement;
            return 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() ??
                                            '',
                                    'r_fname': sworn.fname ?? '',
                                    'r_mname': sworn.mname ?? '',
                                    'r_lname': sworn.lname ?? '',
                                    'r_civilStatus':
                                        sworn.civilStatus?.toString() ?? '',
                                    'r_citizenship': sworn.citizenship ?? ''
                                  },
                                  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: 20,
                                                ),
                                                Row(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment
                                                          .spaceAround,
                                                  children: [
                                                    Row(
                                                      children: [
                                                        const Text('Owner'),
                                                        Checkbox(
                                                          checkColor:
                                                              Colors.white,
                                                          value: isOwner,
                                                          onChanged:
                                                              (bool? value) {
                                                            setState(() {
                                                              isOwner = value!;
                                                            });
                                                          },
                                                        )
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        const Text(
                                                            'Representative'),
                                                        Checkbox(
                                                          checkColor:
                                                              Colors.white,
                                                          value:
                                                              isRepresentative,
                                                          onChanged:
                                                              (bool? value) {
                                                            setState(() {
                                                              isRepresentative =
                                                                  value!;
                                                            });
                                                          },
                                                        )
                                                      ],
                                                    ),
                                                  ],
                                                ),
                                                const SizedBox(
                                                  height: 10,
                                                ),
                                                Row(
                                                  children: [
                                                    Expanded(
                                                      child: customTextField(
                                                          'First Name',
                                                          '',
                                                          'r_fname',
                                                          TextInputType.text),
                                                    ),
                                                    const SizedBox(
                                                      width: 10,
                                                    ),
                                                    Expanded(
                                                      child: customTextField(
                                                          'Middle Name',
                                                          '',
                                                          'r_mname',
                                                          TextInputType.text),
                                                    ),
                                                    const SizedBox(
                                                      width: 10,
                                                    ),
                                                    Expanded(
                                                      child: customTextField(
                                                          'Last Name',
                                                          '',
                                                          'r_lname',
                                                          TextInputType.text),
                                                    )
                                                  ],
                                                ),
                                                const SizedBox(
                                                  height: 10,
                                                ),
                                                Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceEvenly,
                                                    children: <Widget>[
                                                      Expanded(
                                                        flex: 1,
                                                        child:
                                                            customDropDownField(
                                                                "Civil Status",
                                                                "",
                                                                "r_civilStatus",
                                                                civilStatus),
                                                      ),
                                                      const SizedBox(
                                                          width: 10.0),
                                                      Expanded(
                                                        // optional flex property if flex is 1 because the default flex is 1
                                                        flex: 1,
                                                        child: customTextField(
                                                            "Citizenship",
                                                            "",
                                                            'r_citizenship',
                                                            TextInputType.text),
                                                      ),
                                                    ]),
                                                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));

                                                      var sworn =
                                                          SwornStatement(
                                                        bldgapprDetailsId:
                                                            widget.tempId,
                                                        fname: isRepresentative
                                                            ? offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'r_fname']
                                                            : offlineBldgEditKey
                                                                .currentState!
                                                                .value['fname'],
                                                        mname: isRepresentative
                                                            ? offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'r_mname']
                                                            : offlineBldgEditKey
                                                                .currentState!
                                                                .value['mname'],
                                                        lname: isRepresentative
                                                            ? offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'r_lname']
                                                            : offlineBldgEditKey
                                                                .currentState!
                                                                .value['lname'],
                                                        citizenship: isRepresentative
                                                            ? offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'r_citizenship']
                                                            : offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'citizenship'],
                                                        civilStatus: isRepresentative
                                                            ? offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'r_civilStatus']
                                                            : offlineBldgEditKey
                                                                    .currentState!
                                                                    .value[
                                                                'civil_status'],
                                                        genCode: '5TH',
                                                      );
                                                      context
                                                          .read<
                                                              SwornStatementBloc>()
                                                          .add(
                                                            UpdateSwornStatement(
                                                                id: widget
                                                                    .tempId,
                                                                sworn: sworn),
                                                          );

                                                      widget.onSAve();
                                                    },
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              );
                            }

                            return Container();
                          },
                        );
                      }

                      return Container();
                    },
                  );
                }

                return Container();
              },
            );
          }
          return Container();
        }));
  }
}
