@php
  $isEdit = isset($conselho);
@endphp

@if(isset($isAdmin) && $isAdmin)
  <div class="mb-3">
    <label for="structure_id" class="form-label text-bold">{{ __('Secretaria') }} <span class="span-admin-create">*</span></label>
    <select name="structure_id" id="structure_id" class="form-select @error('structure_id') is-invalid @enderror">
      @foreach($structures as $s)
        <option value="{{ $s->id }}" {{ old('structure_id', $structureId ?? ($conselho->structure_id ?? null)) === $s->id ? 'selected' : '' }}>{{ $s->name }}</option>
      @endforeach
    </select>
    @error('structure_id')
      <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
  </div>
@else
  <input type="hidden" name="structure_id" value="{{ $structureId ?? ($conselho->structure_id ?? '') }}">
  <div class="mb-3">
    <label class="form-label text-bold">{{ __('Secretaria') }}</label>
    <input type="text" class="form-control" value="{{ ($structures->first()->name ?? '') }}" readonly>
  </div>
@endif

<div class="mb-3">
  <label for="foto" class="form-label text-bold">{{ __('Foto do conselho:') }}</label>
  <input type="file" class="form-control" name="foto" id="foto" accept="image/jpeg,image/jpg,image/png,image/gif" />
  @error('foto')
    <small class="text-danger text-bold">{{ $message }}</small>
  @enderror
  <hr/>
</div>

@include('components.inputs._inputType', ['label'=>__('Nome do conselho'),'name'=>'nome','required'=>true,'old'=> ($conselho->nome ?? '')])

@include('components.inputs._inputType', ['label'=>__('Telefone'),'name'=>'telefone','id'=>'telefone','required'=>true,'old'=> ($conselho->telefone ?? ''), 'oninput'=>'aplicarMascaraTelefone(this)'])

@include('components.inputs._inputType', ['label'=>__('Email'),'name'=>'email','id'=>'email','required'=>true,'old'=> ($conselho->email ?? ''), 'oninput'=>'this.value = this.value.toLowerCase()'])

<div class="mb-3">
  <label for="domicilio" class="form-label text-bold">{{ __('Tipo de imóvel') }} <span class="span-admin-create">*</span></label>
  <select class="form-control @error('domicilio') is-invalid @enderror" name="domicilio" id="domicilio">
      @foreach(App\Enums\StatusDomicilio::cases() as $status)
          <option value="{{ $status->name }}" {{ old('domicilio', $conselho->endereco->domicilio ?? '') == $status->name ? 'selected' : '' }}>
              {{ $status->value }}
          </option>
      @endforeach
  </select>
  @error('domicilio')
      <small class="text-danger text-bold">{{ $message }}</small>
  @enderror
</div>

@include('components.inputs._inputType', ['label'=>__('CEP'),'name'=>'cep','id'=>'zipCode','required'=>true,'old'=> ($conselho->endereco->cep ?? ''), 'oninput'=>'aplicarMascaraCEP(this)', 'onchange'=>'buscarEnderecoViaCEP(this.value)'])
@include('components.inputs._inputType', ['label'=>__('Logradouro'),'name'=>'logradouro','id'=>'street','required'=>true,'old'=> ($conselho->endereco->logradouro ?? '')])
@include('components.inputs._inputType', ['label'=>__('Número'),'name'=>'numero','old'=> ($conselho->endereco->numero ?? '')])
@include('components.inputs._inputType', ['label'=>__('Complemento'),'name'=>'complemento','old'=> ($conselho->endereco->complemento ?? '')])
@include('components.inputs._inputType', ['label'=>__('Cidade'),'name'=>'cidade','id'=>'city','required'=>true,'old'=> ($conselho->endereco->cidade ?? '')])
@include('components.inputs._inputType', ['label'=>__('Bairro'),'name'=>'bairro','id'=>'neighborhood','required'=>true,'old'=> ($conselho->endereco->bairro ?? '')])
@include('components.inputs._inputType', ['label'=>__('UF'),'name'=>'uf','id'=>'state','required'=>true,'old'=> ($conselho->endereco->uf ?? '')])
@include('components.inputs._inputType', ['label'=>__('Latitude'),'name'=>'latitude','id'=>'latitude','old'=> ($conselho->endereco->latitude ?? '')])
@include('components.inputs._inputType', ['label'=>__('Longitude'),'name'=>'longitude','id'=>'longitude','old'=> ($conselho->endereco->longitude ?? '')])

@include('components.inputs._textarea', ['label'=>__('Informações:'),'name'=>'informacoes','value'=> ($conselho->informacoes ?? ''), 'class'=>'textarea-body'])

<div class="mb-3">
  <label for="transparencia" class="form-label text-bold">{{ __('Sobre este conselho no Portal da Transparência:') }} <span class="span-admin-create">*</span></label>
  <select class="form-control @error('transparencia') is-invalid @enderror" name="transparencia" id="transparencia">
      <option value="Sim, exibir este conselho no Portal da Transparência" {{ old('transparencia', $conselho->transparencia ?? 'Não exibir este conselho no Portal da Transparência') == 'Sim, exibir este conselho no Portal da Transparência' ? 'selected' : '' }}>
          {{ __('Sim, exibir este conselho no Portal da Transparência') }}
      </option>
      <option value="Não exibir este conselho no Portal da Transparência" {{ old('transparencia', $conselho->transparencia ?? 'Não exibir este conselho no Portal da Transparência') == 'Não exibir este conselho no Portal da Transparência' ? 'selected' : '' }}>
          {{ __('Não exibir este conselho no Portal da Transparência') }}
      </option>
  </select>
  @error('transparencia')
      <small class="text-danger text-bold">{{ $message }}</small>
  @enderror
</div>

<div class="mb-3">
  <label for="status" class="form-label text-bold">{{ __('Status:') }} <span class="span-admin-create">*</span></label>
  <select class="form-control @error('status') is-invalid @enderror" name="status" id="status">
      @foreach(App\Enums\StatusEnum::cases() as $status)
          <option value="{{ $status->name }}" {{ old('status', $conselho->status ?? 'ATIVADO') == $status->name ? 'selected' : '' }}>{{ $status->value }}</option>
      @endforeach
  </select>
  @error('status')
      <small class="text-danger text-bold">{{ $message }}</small>
  @enderror
</div>
