import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:intl/intl.dart';
import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/passo/bulding/property_appraisal_edit/property_appraisal_edit_bloc.dart';
import 'package:unit2/bloc/passo/bulding/property_assessment_edit/property_assessment_edit_bloc.dart';
import 'package:unit2/bloc/passo/memoranda/memoranda_bloc.dart';
import 'package:unit2/bloc/passo/signatories/signatories_bloc.dart';
import 'package:unit2/model/passo/memoranda.dart';
import 'package:unit2/model/passo/property_appraisal.dart';
import 'package:unit2/model/passo/property_appraisal_edit.dart';
import 'package:unit2/model/passo/property_assessment_edit.dart';
import 'package:unit2/model/passo/signatories.dart';
import 'package:unit2/screens/passo/Building/add_building.dart';
import 'package:unit2/screens/passo/Building/edit_building/property_owner_info.dart';
import 'package:unit2/theme-data.dart/btn-style.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/theme-data.dart/form-style.dart';
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/error_state.dart';

import '../../../../model/passo/general_description.dart';

class PropertyAssessmentEditPage extends StatefulWidget {
  int tempId;
  PropertyAssessmentEditPage(this.tempId);
  @override
  _PropertyAssessmentEditPage createState() => _PropertyAssessmentEditPage();
}

class _PropertyAssessmentEditPage extends State<PropertyAssessmentEditPage> {
  double assessment_level = 0;
  bool isTaxable = false;
  bool isExempt = false;
  String _memoranda = '';
  final focus = FocusNode();

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

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

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<PropertyAssessmentEditBloc, PropertyAssessmentEditState>(
      builder: (context, state) {
        if (state is PropertyAssessmentEditLoaded) {
          final assessment = state.assessmentsEdit;
          return BlocConsumer<SignatoriesBloc, SignatoriesState>(
            listener: (context, state) {
              // TODO: implement listener
            },
            builder: (context, state) {
              if (state is SignatoriesLoaded) {
                final signatories = state.signatories;

                return BlocConsumer<MemorandaBloc, MemorandaState>(
                  listener: (context, state) {
                    // TODO: implement listener
                  },
                  builder: (context, state) {
                    if (state is MemorandaLoaded) {
                      return FormBuilder(
                        key: keys,
                        initialValue: {
                          'qtr': assessment.qtr.toString(),
                          'yr': assessment.qtr.toString(),
                          // 'appraised_by': assessment.appraisedbyName,
                          'app_date': assessment.appraisedbyDate.toString(),
                          // 'rec_approval': assessment.recommendapprName,
                          'rec_date': assessment.recommendapprDate.toString(),
                          // 'apprvd_by': assessment.approvedbyName,
                          'memoranda': assessment.memoranda,
                          'sworn_statement': assessment.swornstatementNo,
                          'date_received': assessment.dateReceived.toString(),
                          'date_of_entry':
                              assessment.entryDateAssessment.toString(),
                          'by': assessment.entryDateBy
                        },
                        enabled: true,
                        onChanged: () {
                          keys.currentState!.save();
                          debugPrint(keys.currentState!.value.toString());
                        },
                        autovalidateMode: AutovalidateMode.disabled,
                        skipDisabled: true,
                        child: Expanded(
                          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(
                                  flex: 3,
                                  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 :',
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold),
                                            ),
                                            const SizedBox(
                                              height: 20,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.spaceAround,
                                              children: [
                                                const Text('Qtr.'),
                                                SizedBox(
                                                  width: 70,
                                                  height: 25,
                                                  child: FormBuilderTextField(
                                                    name: 'qtr',
                                                    validator:
                                                        FormBuilderValidators
                                                            .compose([]),
                                                  ),
                                                ),
                                                const SizedBox(
                                                  width: 20,
                                                ),
                                                const Text('Yr.'),
                                                SizedBox(
                                                  width: 70,
                                                  height: 25,
                                                  child: FormBuilderTextField(
                                                    name: 'yr',
                                                    validator:
                                                        FormBuilderValidators
                                                            .compose([]),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 30,
                                        ),
                                        Align(
                                          alignment: Alignment.centerLeft,
                                          child: Text(
                                            'APPRAISED/ASSESSED BY:',
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold),
                                            textAlign: TextAlign.start,
                                          ),
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceAround,
                                          children: [
                                            Column(
                                              children: [
                                                SizedBox(
                                                  width: 200,
                                                  child: FormBuilderDropdown<
                                                          Signatories>(
                                                      name: 'appraised_by',
                                                      decoration:
                                                          InputDecoration(
                                                        labelText: assessment
                                                            .appraisedbyName!,
                                                        labelStyle:
                                                            const TextStyle(
                                                                color: Colors
                                                                    .black),
                                                      ),
                                                      autofocus: false,
                                                      items: signatories
                                                          .map((signatories) =>
                                                              DropdownMenuItem(
                                                                value:
                                                                    signatories,
                                                                child: Text(
                                                                    '${signatories.firstname} ${signatories.middlename} ${signatories.lastname}'),
                                                              ))
                                                          .toList()),
                                                ),
                                                Text('Name'),
                                              ],
                                            ),
                                            const SizedBox(
                                              width: 15,
                                            ),
                                            Column(
                                              children: [
                                                SizedBox(
                                                  width: 100,
                                                  child:
                                                      FormBuilderDateTimePicker(
                                                    name: 'app_date',
                                                    initialEntryMode:
                                                        DatePickerEntryMode
                                                            .calendarOnly,
                                                    initialValue:
                                                        DateTime.now(),
                                                    inputType: InputType.date,

                                                    initialTime:
                                                        const TimeOfDay(
                                                            hour: 8, minute: 0),
                                                    // locale: const Locale.fromSubtags(languageCode: 'fr'),
                                                  ),
                                                ),
                                                Text('Date'),
                                              ],
                                            ),
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 30,
                                        ),
                                        const Align(
                                            alignment: Alignment.centerLeft,
                                            child: Text(
                                              'RECOMMENDING APPROVAL:',
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold),
                                            )),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceAround,
                                          children: [
                                            Column(
                                              children: [
                                                SizedBox(
                                                  width: 200,
                                                  child: FormBuilderDropdown<
                                                          Signatories>(
                                                      name: 'rec_approval',
                                                      decoration:
                                                          InputDecoration(
                                                        labelText: assessment
                                                            .recommendapprName!,
                                                        labelStyle:
                                                            const TextStyle(
                                                                color: Colors
                                                                    .black),
                                                      ),
                                                      autofocus: false,
                                                      items: signatories
                                                          .map((signatories) =>
                                                              DropdownMenuItem(
                                                                value:
                                                                    signatories,
                                                                child: Text(
                                                                    '${signatories.firstname} ${signatories.middlename} ${signatories.lastname}'),
                                                              ))
                                                          .toList()),
                                                ),
                                                Text('Name'),
                                              ],
                                            ),
                                            const SizedBox(
                                              width: 15,
                                            ),
                                            Column(
                                              children: [
                                                SizedBox(
                                                  width: 100,
                                                  child:
                                                      FormBuilderDateTimePicker(
                                                    name: 'rec_date',
                                                    initialEntryMode:
                                                        DatePickerEntryMode
                                                            .calendarOnly,
                                                    initialValue:
                                                        DateTime.now(),
                                                    inputType: InputType.date,

                                                    initialTime:
                                                        const TimeOfDay(
                                                            hour: 8, minute: 0),
                                                    // locale: const Locale.fromSubtags(languageCode: 'fr'),
                                                  ),
                                                ),
                                                Text('Date'),
                                              ],
                                            ),
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 30,
                                        ),
                                        const Align(
                                            alignment: Alignment.centerLeft,
                                            child: Text(
                                              'APPROVED BY:',
                                              style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                              ),
                                            )),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: [
                                            Column(
                                              children: [
                                                SizedBox(
                                                  width: 200,
                                                  child: FormBuilderDropdown<
                                                          Signatories>(
                                                      name: 'apprvd_by',
                                                      autofocus: false,
                                                      decoration:
                                                          InputDecoration(
                                                        labelText: assessment
                                                            .approvedbyName!,
                                                        labelStyle:
                                                            const TextStyle(
                                                                color: Colors
                                                                    .black),
                                                      ),
                                                      items: signatories
                                                          .map((signatories) =>
                                                              DropdownMenuItem(
                                                                value:
                                                                    signatories,
                                                                child: Text(
                                                                    '${signatories.firstname} ${signatories.middlename} ${signatories.lastname}'),
                                                              ))
                                                          .toList()),
                                                ),
                                                Text('Name'),
                                              ],
                                            ),
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 50,
                                        ),
                                        const Align(
                                            alignment: Alignment.centerLeft,
                                            child: Text(
                                              'MEMORANDA: ',
                                              style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                              ),
                                            )),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        SizedBox(
                                            width: 500,
                                            height: 100,
                                            child: SearchField(
                                              itemHeight: 70,

                                              suggestions: state.memorada
                                                  .map((Memoranda memoranda) =>
                                                      SearchFieldListItem(
                                                        '${memoranda.memoranda}',
                                                        item:
                                                            memoranda, // Change: Use individual Memoranda object
                                                        child: ListTile(
                                                          title: Text(
                                                            '${memoranda.memoranda}',
                                                            overflow:
                                                                TextOverflow
                                                                    .ellipsis,
                                                          ),
                                                        ),
                                                      ))
                                                  .toList(),
                                              validator: FormBuilderValidators
                                                  .required(
                                                      errorText:
                                                          "This field is required"),
                                              // searchInputDecoration:
                                              //     normalTextFieldStyle(
                                              //             "Memoranda", "")
                                              //         .copyWith(
                                              //   suffixIcon: const Icon(
                                              //       Icons.arrow_drop_down),
                                              // ),
                                              // focusNode: focus,
                                              suggestionState:
                                                  Suggestion.expand,
                                              onSuggestionTap: (memoranda) {
                                                setState(() {
                                                  _memoranda = memoranda
                                                      .item!.memoranda!;
                                                });
                                                focus.unfocus();
                                              },
                                            )),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text('Sworn Statement No. :'),
                                            SizedBox(
                                              width: 150,
                                              height: 20,
                                              child: FormBuilderTextField(
                                                name: 'sworn_statement',
                                                decoration: InputDecoration(),
                                                validator: FormBuilderValidators
                                                    .compose([]),
                                              ),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text('Date Received:'),
                                            SizedBox(
                                              width: 150,
                                              height: 20,
                                              child: FormBuilderDateTimePicker(
                                                name: 'date_received',
                                                initialEntryMode:
                                                    DatePickerEntryMode
                                                        .calendarOnly,
                                                initialValue: DateTime.now(),
                                                inputType: InputType.date,

                                                initialTime: const TimeOfDay(
                                                    hour: 8, minute: 0),
                                                // locale: const Locale.fromSubtags(languageCode: 'fr'),
                                              ),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text(
                                                'Date of Entry in the Rec. of Ass. :'),
                                            SizedBox(
                                              width: 100,
                                              height: 20,
                                              child: FormBuilderDateTimePicker(
                                                name: 'date_of_entry',
                                                initialEntryMode:
                                                    DatePickerEntryMode
                                                        .calendarOnly,
                                                initialValue: DateTime.now(),
                                                inputType: InputType.date,

                                                initialTime: const TimeOfDay(
                                                    hour: 8, minute: 0),
                                                // locale: const Locale.fromSubtags(languageCode: 'fr'),
                                              ),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text('By:'),
                                            SizedBox(
                                              width: 150,
                                              height: 20,
                                              child: FormBuilderTextField(
                                                name: 'by',
                                                decoration: InputDecoration(),
                                                validator: FormBuilderValidators
                                                    .compose([]),
                                              ),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 30,
                                        ),
                                        SizedBox(
                                          width:
                                              MediaQuery.of(context).size.width,
                                          child: ElevatedButton(
                                            style: ElevatedButton.styleFrom(
                                                backgroundColor: primary,
                                                foregroundColor: Colors.red),
                                            child: SizedBox(
                                              width: 200,
                                              height: 50,
                                              child: Align(
                                                alignment: Alignment.center,
                                                child: Text(
                                                  'Save',
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                  ),
                                                  textAlign: TextAlign.center,
                                                ),
                                              ),
                                            ),
                                            onPressed: () {
                                              final List<PropertyAssessmentEdit>
                                                  propertyAssessments = [];

                                              PropertyAssessmentEdit ass =
                                                  PropertyAssessmentEdit(
                                                id: 1,
                                                bldgapprDetailsId: 440,
                                                actualUse: assessment.actualUse,
                                                marketValue: '0.0',
                                                assessmentLevel: '0.0',
                                                assessedValue: "1.0",
                                                taxable: isTaxable,
                                                exempt: isExempt,
                                                qtr: int.parse(keys
                                                    .currentState!
                                                    .value['qtr']),
                                                yr: int.parse(keys
                                                    .currentState!.value['yr']),
                                                appraisedbyName: keys
                                                        .currentState!
                                                        .value['appraised_by']
                                                        .firstname +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['appraised_by']
                                                        .middlename +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['appraised_by']
                                                        .lastname,
                                                appraisedbyDate: keys
                                                    .currentState!
                                                    .value['app_date'],
                                                recommendapprName: keys
                                                        .currentState!
                                                        .value['rec_approval']
                                                        .firstname +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['rec_approval']
                                                        .middlename +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['rec_approval']
                                                        .lastname,
                                                recommendapprDate: keys
                                                    .currentState!
                                                    .value['rec_date'],
                                                approvedbyName: keys
                                                        .currentState!
                                                        .value['apprvd_by']
                                                        .firstname +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['apprvd_by']
                                                        .middlename +
                                                    ' ' +
                                                    keys
                                                        .currentState!
                                                        .value['apprvd_by']
                                                        .lastname,
                                                memoranda: _memoranda,
                                                swornstatementNo: keys
                                                    .currentState!
                                                    .value['sworn_statement'],
                                                dateReceived: keys.currentState!
                                                    .value['date_received'],
                                                entryDateAssessment: keys
                                                    .currentState!
                                                    .value['date_of_entry'],
                                                entryDateBy: keys
                                                    .currentState!.value['by'],
                                              );

                                              propertyAssessments.add(ass);

                                              context.read<
                                                  PropertyAssessmentEditBloc>()
                                                ..add(
                                                    UpdatePropertyAssessmentEdit(
                                                        assessmentsEdit:
                                                            propertyAssessments[
                                                                0]));
                                            },
                                          ),
                                        ),
                                      ],
                                    ),
                                  ))
                            ],
                          ),
                        ),
                      );
                    }
                    return Container();
                  },
                );
              }
              return Container();
            },
          );
        }
        if (state is PropertyAssessmentEditErrorState) {
          return SomethingWentWrong(
            message: onError,
            onpressed: () {
              context.read<PropertyAssessmentEditBloc>().add(
                  LoadPropertyAssessmentEdit(
                      assessmentsEdit: PropertyAssessmentEdit(),
                      id: widget.tempId));
            },
          );
        }
        return Container();
      },
    );
  }
}
