import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/offline/offline_passo/land/land_property_owner_bloc/land_property_owner_bloc.dart';
import 'package:unit2/screens/offline/passo/land/add/add_land.dart';

import '../../../../../model/passo/land_property_owner.dart';
import '../../../../../widgets/passo/custom_button.dart';
import '../../../../../widgets/passo/custom_formBuilder_fields.dart';

class LandPropertyOwnerInfoOffline extends StatefulWidget {
  Function NextBtn;
  LandPropertyOwnerInfoOffline(this.NextBtn);
  @override
  _LandPropertyOwnerInfoOffline createState() =>
      _LandPropertyOwnerInfoOffline();
}

class _LandPropertyOwnerInfoOffline
    extends State<LandPropertyOwnerInfoOffline> {
  final transaction_codes = ['New', 'Revision'];
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Padding(
      padding: const EdgeInsets.all(15.0),
      child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              margin:
                  const EdgeInsets.only(left: 0, top: 20, right: 0, bottom: 10),
              child: const Text('PROPERTY OWNER INFO',
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
                  textAlign: TextAlign.left),
            ),
            const SizedBox(height: 15),
            customDropDownField(
                "Transaction Code", "", "transaction_code", transaction_codes),
            customTextField(
                "ARP No./ TD No.", "", "td_no", TextInputType.number),
            customTextField("Owner", "", "owner", TextInputType.text),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                      flex: 1,
                      child: customTextField(
                          "PIN", "", "pin", TextInputType.number)),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "TIN", "", "tin", TextInputType.number))
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: customTextField("OCT/TCT CLOA No.", "", "cloa_no",
                        TextInputType.number),
                  ),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customDatTimePicker("Dated", "", "dated"))
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: customTextField(
                        "Survey No.", "", "survey_no", TextInputType.number),
                  ),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "Lot No.", "", "lot_no", TextInputType.number)),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "Blk", "", "blk", TextInputType.number)),
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: customTextField(
                        "Address", "", "address", TextInputType.text),
                  ),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "Tel No.", "", "tel_no", TextInputType.number))
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: customTextField("Administrator/Beneficial User", "",
                        "admin", TextInputType.text),
                  ),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "TIN", "", "admin_tin", TextInputType.number))
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: customTextField(
                        "Address", "", "admin_address", TextInputType.text),
                  ),
                  const SizedBox(width: 10.0),
                  Expanded(
                      // optional flex property if flex is 1 because the default flex is 1
                      flex: 1,
                      child: customTextField(
                          "Tel No.", "", "admin_telno", TextInputType.number))
                ]),
            SizedBox(
              height: 30,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                CustomButton(
                  icon: const Icon(Icons.chevron_right, color: Colors.white),
                  onPressed: () {
                    context.read<LandPropertyOwnerBloc>().add(
                        AddLandPropertyOwner(
                            id: 1,
                            transCode: landKeyOffline
                                .currentState!.value['transaction_code']
                                .toString(),
                            tdn: landKeyOffline.currentState!.value['td_no'] ??
                                '',
                            cloaNo:
                                landKeyOffline.currentState!.value['cloa_no'] ??
                                    '',
                            dated: landKeyOffline.currentState!.value['dated']
                                .toString(),
                            assessedById: "1",
                            assessedByName: "cyril",
                            dateCreated: landKeyOffline
                                .currentState!.value['dated']
                                .toString(),
                            dateModified: landKeyOffline
                                .currentState!.value['dated']
                                .toString(),
                            pin: landKeyOffline.currentState!.value['pin'],
                            surveyNo:
                                landKeyOffline.currentState!.value['survey_no'],
                            lotNo: landKeyOffline.currentState!.value['lot_no'],
                            blkNo: landKeyOffline.currentState!.value['blk'],
                            owner: landKeyOffline.currentState!.value['owner'],
                            address:
                                landKeyOffline.currentState!.value['address'],
                            telno: landKeyOffline.currentState!.value['tel_no'],
                            tin: landKeyOffline.currentState!.value['tin'],
                            adminUser:
                                landKeyOffline.currentState!.value['admin'],
                            adminAddress: landKeyOffline
                                .currentState!.value['admin_address'],
                            adminTin:
                                landKeyOffline.currentState!.value['admin_tin'],
                            // faasType: "LAND",
                            adminTelno: landKeyOffline
                                .currentState!.value['admin_telno'],
                            faasType: 'Land'));

                    widget.NextBtn();
                  },
                )
              ],
            ),
            const SizedBox(
              height: 20,
            ),
          ]),
    ));
  }
}
