import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:rkm/config/color_palette.dart';
import 'package:rkm/config/const_variable.dart';
import 'package:rkm/widgets/button_default.dart';
import 'package:rkm/widgets/title_containers.dart';
import '../../widgets/appbar_default.dart';
import '../../widgets/dropdown_with_subtitle.dart';
import '../../widgets/input_with_subtitle.dart';
import '../../widgets/onbackbutton.dart';
import '../../widgets/subtitle_appbar_citizen.dart';
import '../../widgets/switch_with_subtitle.dart';
class RegisterHomeScreen extends StatefulWidget {
  const RegisterHomeScreen({Key? key}) : super(key: key);

  @override
  State<RegisterHomeScreen> createState() => _RegisterHomeScreenState();
}

class _RegisterHomeScreenState extends State<RegisterHomeScreen> {

  var nameController = TextEditingController();
  var nameSocialController = TextEditingController();
  var renponsibleController = TextEditingController(text: 'NOME COMPLETO');
  var enterBrazilController = TextEditingController();
  var porterNaturalnessController = TextEditingController();
  var dateNaturalnessController = TextEditingController();
  var naturalnessController = TextEditingController(text: 'BRASILEIRO');
  var cityBirthController = TextEditingController();
  var cityController = TextEditingController();
  var searchCityBirthController = TextEditingController();
  var searchCityController = TextEditingController();
  var nameMotherController = TextEditingController();
  var nameFatherController = TextEditingController();
  var codIBGEController = TextEditingController();
  var maternityController = TextEditingController();
  var medicalRecordController = TextEditingController();
  var medicalRecordProvController = TextEditingController();
  var classificationProvController = TextEditingController();
  var plantsController = TextEditingController();
  var numberFamilyController = TextEditingController();
  var whatCompanyController = TextEditingController();
  var otherCondicionsController = TextEditingController();
  var cepController = TextEditingController();
  var numberController = TextEditingController();
  var complementController = TextEditingController();
  var referencePointController = TextEditingController();
  var responsibleRegisterController = TextEditingController();
  var unitProfessionalController = TextEditingController();
  var dataRegisterController = TextEditingController(text: '06/12/2022');
  var foneDDDController = TextEditingController();
  var foneController = TextEditingController();
  var mobileDDDController = TextEditingController();
  var mobileController = TextEditingController();
  var messageDDDController = TextEditingController();
  var messageController = TextEditingController();
  var emailController = TextEditingController();
  var observationController = TextEditingController();
  var CPFController = TextEditingController();
  var CNSController = TextEditingController();
  var voterController = TextEditingController();
  var RGController = TextEditingController();
  var RGComplementController = TextEditingController();
  var RGOrganController = TextEditingController();
  var RGDateController = TextEditingController();
  var numberCertificateController = TextEditingController();
  var nameCertificateController = TextEditingController();
  var bookCertificateController = TextEditingController();
  var sheetCertificateController = TextEditingController();
  var termCertificateController = TextEditingController();
  var dateCertificateController = TextEditingController();
  var CTPSController = TextEditingController();
  var numberCTPSController = TextEditingController();
  var PISController = TextEditingController();
  var NISController = TextEditingController();
  var incomeController = TextEditingController();
  var professionalController = TextEditingController();
  var controllerComfortable = TextEditingController();
  var dateDeathController = TextEditingController();
  var controllerResidents = TextEditingController();
  var controllerAmount = TextEditingController();

  String? selectTypeCertificate;
  String? selectCTPSUF;
  String? selectRGUF;
  String? selectTypeStreet;
  String? selectStreet;
  String? selectSubdivision;
  String? selectHeartDisease;
  String? selectKidneyProblem;
  String? selectLungProblem;
  String? selectCBO;
  String? selectZone;
  String? selectVillage;
  String? selectCountry;
  String? selectTypeHome;
  String? selectSituation;
  String? selectResidence;
  String? selectAcessHome;
  String? selectMaterialWall;
  String? selectWater;
  String? selectTreatmentWater;
  String? selectDestinyTrash;
  String? selectFormSanitaryDrainage;
  String? selectRural;
  String? selectSituationStreet;
  String? selectClassification;
  String? selectINE;
  String? selectMaritalStatus;
  String? selectBreed;
  String? selectCurse;
  String? selectScooling;
  String? selectWork;
  String? selectSexualOrientation;
  String? selectGender;
  String? selectWeight;
  String? selectDeficiency;
  String? selectKin;
  bool enableSpouse = false;
  bool enableAnimals = false;
  bool enableCats = false;
  bool enableDogs = false;
  bool enableBirds = false;
  bool enableOther = false;
  bool enableAccompaniedCompany = false;
  bool outOfArea = false;
  bool enableEnergy = false;
  bool statusRegister = true;
  bool renponsibleFamily = true;
  bool frequencySchool = false;
  bool enableFather = false;
  bool enableCityCard = false;
  bool enableBlocked = false;
  bool checkBoxNumber = false;
  String date = 'Data de Nascimento';

  escolherprazoInicio(BuildContext context) async {
    var pickDate = await showDatePicker(
        context: context,
        initialDate: DateTime.now(),
        firstDate: DateTime(2022),
        lastDate: DateTime(2025));
    if (pickDate != null) {
      setState(() {
        date = formatData(year: pickDate.year, month: pickDate.month, day: pickDate.day);
      });
    }
  }

  String formatData({int? year, int? month, int? day}) {
    DateTime data = DateTime(year!, month!, day!);
    String formattedDate = DateFormat('dd/MM/yyyy').format(data);
    return formattedDate;
  }

  @override
  Widget build(BuildContext context) {

    double heigth = MediaQuery.of(context).size.height;
    double width = MediaQuery.of(context).size.width;

    return WillPopScope(
      onWillPop: ()=> OnBackButton().onBackButton(context),
      child: Scaffold(
        appBar: AppBarDefault().appbar(context, 'RKM AB - Cadastro Domiciliar'),
        body: Container(
            height: double.infinity,
            width: double.infinity,
            decoration: ConstVariable().backgroundGradient,
            child: ListView(
                children: [
                  SubtitleAppbarCitizen(title: 3,edit: true),
                  Card(
                    margin: EdgeInsets.all(10),
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Column(
                        children: [
                          ButtonDefault(
                            onPressed: (){},
                            title: 'Alterar',
                            borderColor: ColorPalette.appBar,
                            background: ColorPalette.appBar,
                            textColor: ColorPalette.white,
                            width: double.infinity,
                          ),
                          ButtonDefault(
                            onPressed: ()=>Navigator.pop(context),
                            title: 'Cancelar',
                            borderColor: ColorPalette.blackButton,
                            background: ColorPalette.blackButton,
                            textColor: ColorPalette.white,
                            width: double.infinity,
                          )
                        ],
                      ),
                    ),
                  ),
                  Card(
                    margin: EdgeInsets.all(10),
                    child: Column(
                      children: [
                        TitleContainers(title: 'Condições de Moradia'),
                        Row(
                          children: [
                            Container(
                              height: heigth*0.5,
                              width: width*0.2,
                              child: Icon(Icons.home,size: 80,),
                            ),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.start,
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                DropdownWithSubtitle(
                                  list:['DOMICÍLIO'],
                                  widthSubtitle: width*0.7,
                                  subtitle: 'Tipo de Imóvel',
                                  hintDropdown: 'Tipo de Imóvel',
                                  select: selectSituation,
                                  widthDropdown:  width*0.7,
                                  widthContainerDropdown: width*0.6,
                                  onChanged: (value){
                                    setState(() {
                                      selectSituation = value!;
                                    });
                                  },
                                ),
                                DropdownWithSubtitle(
                                  list:[],
                                  widthSubtitle: width*0.7,
                                  subtitle: 'INE - Área / Microárea do Domicílio',
                                  hintDropdown:  'INE - Área / Microárea do Domicílio',
                                  select: selectTypeHome,
                                  widthDropdown:  width*0.7,
                                  widthContainerDropdown: width*0.6,
                                  onChanged: (value){
                                    setState(() {
                                      selectTypeHome = value!;
                                    });
                                  },
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Fora de área',
                                  value: outOfArea,
                                  onChanged:  (value){
                                    setState(() {
                                      // enableMother = value;
                                      // if(enableMother){
                                      //   nameMotherController.text = '';
                                      // }
                                    });
                                  },
                                ),
                                DropdownWithSubtitle(
                                  list:['PRÓPRIO'],
                                  widthSubtitle: width*0.7,
                                  subtitle: 'Situação',
                                  hintDropdown:  'Situação',
                                  select: selectTypeHome,
                                  widthDropdown:  width*0.7,
                                  widthContainerDropdown: width*0.6,
                                  onChanged: (value){
                                    setState(() {
                                      selectTypeHome = value!;
                                    });
                                  },
                                ),
                                DropdownWithSubtitle(
                                  list:['URBANO','RURAL'],
                                  widthSubtitle: width*0.7,
                                  subtitle: 'Localização',
                                  hintDropdown:  'Localização',
                                  select: selectSituation,
                                  widthDropdown:  width*0.7,
                                  widthContainerDropdown: width*0.6,
                                  onChanged: (value){
                                    setState(() {
                                      selectSituation = value!;
                                    });
                                  },
                                ),
                                DropdownWithSubtitle(
                                  list:['CASA'],
                                  widthSubtitle: width*0.7,
                                  subtitle: 'Tipo de Domicílio',
                                  hintDropdown:  'Tipo de Domicílio',
                                  select: selectResidence,
                                  widthDropdown:  width*0.7,
                                  widthContainerDropdown: width*0.6,
                                  onChanged: (value)=>setState(()=>selectResidence = value!)),
                                InputWithSubtitle(
                                  subtitle: 'Moradores',
                                  hintInput: 'Moradores',
                                  errorInput: 'Campo obrigatório',
                                  labelInput: 'Moradores',
                                  widthSubtitle: width*0.4,
                                  widthInput: width*0.7,
                                  controller: controllerResidents,
                                  onChanged: (v)=>setState((){}),
                                ),
                                InputWithSubtitle(
                                  subtitle: 'Cômodos',
                                  hintInput: 'Cômodos',
                                  errorInput: 'Campo obrigatório',
                                  labelInput: 'Cômodos',
                                  widthSubtitle: width*0.4,
                                  widthInput: width*0.7,
                                  controller: controllerComfortable,
                                  onChanged: (v)=>setState((){}),
                                ),
                                DropdownWithSubtitle(
                                    list:[],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Situação Rural',
                                    hintDropdown:  'Situação Rural',
                                    select: selectRural,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectRural = value!)
                                ),
                                DropdownWithSubtitle(
                                    list:['ASFALTO'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Tipo de Acesso ao Domicílio',
                                    hintDropdown:  'Tipo de Acesso ao Domicílio',
                                    select: selectAcessHome,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectAcessHome = value!)
                                ),
                                DropdownWithSubtitle(
                                    list:['ALVENARIA COM REVESTIMENTO'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Material Predominante - Parede',
                                    hintDropdown: 'Material Predominante - Parede',
                                    select: selectMaterialWall,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectMaterialWall = value!)
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Disponibilidade de Energia Elétroca',
                                  value: enableEnergy,
                                  onChanged:  (value)=>setState(()=>enableEnergy = value),
                                ),
                                DropdownWithSubtitle(
                                    list:['REDE ENCANADA ATÉ O DOMICÍLIO'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Abastecimento de Água',
                                    hintDropdown: 'Abastecimento de Água',
                                    select: selectWater,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectWater = value!)
                                ),
                                DropdownWithSubtitle(
                                    list:['FILTRAÇÃO'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Tratamento de Água',
                                    hintDropdown: 'Tratamento de Água',
                                    select: selectTreatmentWater,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectTreatmentWater = value!)
                                ),
                                DropdownWithSubtitle(
                                    list:['COLETADO'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Destino de Lixo',
                                    hintDropdown: 'Destino de Lixo',
                                    select: selectDestinyTrash,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectDestinyTrash = value!)
                                ),
                                DropdownWithSubtitle(
                                    list:['REDE COLETORA DE ESGOTO OU PLUVIAL'],
                                    widthSubtitle: width*0.7,
                                    subtitle: 'Forma de Escoamento Sanitário',
                                    hintDropdown: 'Forma de Escoamento Sanitário',
                                    select: selectFormSanitaryDrainage,
                                    widthDropdown:  width*0.7,
                                    widthContainerDropdown: width*0.6,
                                    onChanged: (value)=>setState(()=>selectFormSanitaryDrainage = value!)
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Animais',
                                  value: enableAnimals,
                                  onChanged:  (value)=>setState(()=>enableAnimals = value!),
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Quais - Gato',
                                  value: enableCats,
                                  onChanged:  (value)=>setState(()=>enableCats = value!),
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Quais - Cachorro',
                                  value: enableDogs,
                                  onChanged:  (value)=>setState(()=>enableDogs = value!),
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Quais - Pássaro',
                                  value: enableBirds,
                                  onChanged:  (value)=>setState(()=>enableBirds = value!),
                                ),
                                SwitchWithSubtitle(
                                  width: width*0.7,
                                  title: 'Quais - Outros',
                                  value: enableOther,
                                  onChanged:  (value)=>setState(()=>enableOther = value!),
                                ),
                                InputWithSubtitle(
                                    subtitle: 'Quantidade',
                                    hintInput: 'Quantidade',
                                    errorInput: 'Campo obrigatório',
                                    labelInput: 'Quantidade',
                                    widthSubtitle: width*0.4,
                                    widthInput: width*0.7,
                                    controller: controllerAmount,
                                  onChanged: (v)=>setState((){}),
                                ),
                              ],
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                  Card(
                    margin: EdgeInsets.all(10),
                    child: Column(
                      children: [
                        TitleContainers(title: 'Outros'),
                        Row(
                            children: [
                              Container(
                                height: heigth*0.4,
                                width: width*0.2,
                                child: Icon(Icons.business_center,size: 80,),
                              ),
                              Padding(
                                padding: const EdgeInsets.symmetric(horizontal: 10.0),
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  mainAxisSize: MainAxisSize.min,
                                  children: [
                                    InputWithSubtitle(
                                      controller: responsibleRegisterController,
                                      subtitle: 'Usuário responsável Pelo Cadastro',
                                      errorInput: 'Campo Obrigatório',
                                      labelInput: 'Usuário responsável Pelo Cadastro',
                                      widthInput: width*0.7,
                                      widthSubtitle: width*0.7,
                                      hintInput: 'Escreva aqui',
                                      onChanged: (v)=>setState((){}),
                                    ),
                                    InputWithSubtitle(
                                      controller: unitProfessionalController,
                                      subtitle: 'Unidade do Profissional',
                                      errorInput: 'Campo Obrigatório',
                                      labelInput: 'Unidade do Profissional',
                                      widthInput: width*0.7,
                                      widthSubtitle: width*0.7,
                                      hintInput: 'Escreva aqui',
                                      onChanged: (v)=>setState((){}),
                                    ),
                                    DropdownWithSubtitle(
                                        subtitle: 'CBO',
                                        select: selectCBO,
                                        widthDropdown: width*0.673,
                                        widthContainerDropdown: width*0.5,
                                        widthSubtitle: width*0.3,
                                        hintDropdown: 'CBO',
                                        onChanged: (value){
                                          setState(() {
                                            selectCBO = value;
                                          });
                                        },
                                        list: []
                                    ),
                                    DropdownWithSubtitle(
                                        subtitle: 'Código da Equipe',
                                        select: selectCBO,
                                        widthDropdown: width*0.672,
                                        widthContainerDropdown: width*0.5,
                                        widthSubtitle: width*0.3,
                                        hintDropdown: 'Código da Equipe',
                                        onChanged: (value){
                                          setState(() {
                                            selectCBO = value;
                                          });
                                        },
                                        list: ['INE - 0001558536 / Área 4 - Microárea: - ']
                                    ),
                                    InputWithSubtitle(
                                      controller: dataRegisterController,
                                      subtitle: 'Data do Cadastro',
                                      errorInput: 'Campo Obrigatório',
                                      labelInput: 'Data do Cadastro',
                                      widthInput: width*0.7,
                                      widthSubtitle: width*0.7,
                                      hintInput: 'Escreva aqui',
                                      enabled: false,
                                      onChanged: (v)=>setState((){}),
                                    ),
                                  ],
                                ),
                              ),
                            ]
                        ),
                      ],
                    ),
                  ),
                ]
            )
        ),
      ),
    );
  }
}
