<form action="{{ route('admin.cadastroDeAmbulantes.ambulantes.representanteLegalStore', $ambulante->id) }}" method="post" enctype="multipart/form-data" autocomplete="off">

    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        
                        <div class="mb-3 p-5 bg-secondary text-white rounded">
                            <h1>{{ $ambulante->proprietario->firstName }} {{ $ambulante->proprietario->lastName }}</h1>
                            <p class="text-white">CPF: {{ $ambulante->proprietario->cpf }}</p>
                            <p class="text-white">Telefone: {{ $ambulante->proprietario->phoneNumber }}</p>
                            <p class="text-white">Email: {{ $ambulante->proprietario->email }}</p>
                        </div>
                        
                        <div class="form-check">
                            @php $checkRepresentanteLegal = ($ambulante->representanteLegal_id == "" || $ambulante->representanteLegal_id == null) ? NULL : $ambulante->representanteLegal_id @endphp
                            <input class="form-check-input" type="checkbox" name="checkRepresentanteLegal" id="checkRepresentanteLegal" {{ old('checkRepresentanteLegal', $checkRepresentanteLegal) ? 'checked' : '' }}>
                            <label class="form-check-label" for="checkRepresentanteLegal">
                                Declaro autorizar esta pessoa a atuar como meu representante no comércio ambulante.
                            </label>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container my-3">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Representante legal do comércio ambulante</h5>
                        <div class="container">
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        @csrf
                                        @method('POST')
                                        <input type="hidden" name="userId" id="userId" value="{{ old('userId', $representante?->id ?? NULL) }}"/>
                                        <input type="hidden" name="domicilioRepresentanteLegal" id="domicilioRepresentanteLegal" value="{{ old("domicilioRepresentanteLegal", $endereco?->domicilio ?? "OUTROS") }}"/>
                                        <input type="hidden" name="papersRepresentanteLegal" id="papersRepresentanteLegal" value="{{ old("papersRepresentanteLegal", $representante?->papers ?? "EDIT") }}"/>
                                        <input type="hidden" name="permissionRepresentanteLegal" id="permissionRepresentanteLegal" value="{{ old("permissionRepresentanteLegal", $representante?->permission ?? "GUEST") }}"/>
                                        <input type="hidden" name="passwordRepresentanteLegal" id="passwordRepresentanteLegal" value="{{ old("passwordRepresentanteLegal", $representante?->password ?? "mudar123") }}"/>
                                        <label for="fullNameRepresentanteLegal" class="form-label text-bold">Nome completo: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('fullNameRepresentanteLegal') is-invalid @enderror" name="fullNameRepresentanteLegal" id="fullNameRepresentanteLegal" autocomplete="off" value="{{ old('fullNameRepresentanteLegal', $representante?->id ? $representante->firstName . " " . $representante->lastName : NULL ) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('fullNameRepresentanteLegal')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="cpfRepresentanteLegal" class="form-label text-bold">CPF: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('cpfRepresentanteLegal') is-invalid @enderror" name="cpfRepresentanteLegal" id="cpfRepresentanteLegal" value="{{ old('cpfRepresentanteLegal', $representante->cpf ?? NULL ) }}" oninput="javascript:aplicarMascaraCPF(this)" autocomplete="off">
                                    @error('cpfRepresentanteLegal')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="phoneNumberRepresentanteLegal" class="form-label text-bold">Telefone: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('phoneNumberRepresentanteLegal') is-invalid @enderror" name="phoneNumberRepresentanteLegal" id="phoneNumberRepresentanteLegal" value="{{ old('phoneNumberRepresentanteLegal', $representante->phoneNumber ?? NULL) }}" oninput="aplicarMascaraTelefone(this)" autocomplete="off">
                                        @error('phoneNumberRepresentanteLegal')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="emailRepresentanteLegal" class="form-label text-bold">Email: <span class="span-admin-create">*</span></label>
                                        <input type="emailRepresentanteLegal" class="form-control @error('emailRepresentanteLegal') is-invalid @enderror" name="emailRepresentanteLegal" id="emailRepresentanteLegal" value="{{ old('emailRepresentanteLegal', $representante->email ?? NULL) }}" oninput="this.value = this.value.toLowerCase()" autocomplete="off">
                                    @error('emailRepresentanteLegal')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="photoRepresentanteLegal" class="form-label text-bold">Foto:</label>
                                        <input type="file" class="form-control @error('photoRepresentanteLegal') is-invalid @enderror" name="photoRepresentanteLegal" id="photoRepresentanteLegal" accept="image/jpeg,image/jpg,image/png,image/gif" />
                                        @error('photoRepresentanteLegal')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5 pt-3">
                                    @if(isset($representante->id))
                                        <div style="width: 90px;">
                                        @include('components.tables._openPhoto',[
                                            'asset' => $representante->photo,
                                            'alt' => $representante->firstName . " " . $representante->lastName,
                                            'title' => $representante->firstName . " " . $representante->lastName,
                                            'text' => 'Visualizar foto',
                                            'index' => 3,
                                        ])
                                        </div>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="container my-3">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Endereço do representante legal</h5>
                        <div class="container address">
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="cepRepresentanteLegal" class="form-label">CEP <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control cep @error('cepRepresentanteLegal') is-invalid @enderror" name="cepRepresentanteLegal" id="cepRepresentanteLegal" oninput="aplicarMascaraCEP(this)" autocomplete="off" value="{{ old('cepRepresentanteLegal', $endereco->cep ?? NULL) }}">
                                        @error('cepRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="logradouroRepresentanteLegal" class="form-label">Logradouro <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control logradouro @error('logradouroRepresentanteLegal') is-invalid @enderror" name="logradouroRepresentanteLegal" id="logradouroRepresentanteLegal" value="{{ old('logradouroRepresentanteLegal', $endereco->logradouro ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('logradouroRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="numeroRepresentanteLegal" class="form-label">Número</label>
                                        <input type="text" class="form-control numero @error('numeroRepresentanteLegal') is-invalid @enderror" name="numeroRepresentanteLegal" id="numero" value="{{ old('numeroRepresentanteLegal', $endereco->numero ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('numeroRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="complementoRepresentanteLegal" class="form-label">Complemento</label>
                                        <input type="text" class="form-control complemento @error('complementoRepresentanteLegal') is-invalid @enderror" name="complementoRepresentanteLegal" id="complementoRepresentanteLegal" value="{{ old('complementoRepresentanteLegal', $endereco->complemento ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('complementoRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="cidadeRepresentanteLegal" class="form-label">Cidade <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control cidade @error('cidadeRepresentanteLegal') is-invalid @enderror" name="cidadeRepresentanteLegal" id="cidadeRepresentanteLegal" value="{{ old('cidadeRepresentanteLegal', $endereco->cidade ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('cidadeRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="bairroRepresentanteLegal" class="form-label">Bairro <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control bairro @error('bairroRepresentanteLegal') is-invalid @enderror" name="bairroRepresentanteLegal" id="bairroRepresentanteLegal" value="{{ old('bairroRepresentanteLegal', $endereco->bairro ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('bairroRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="ufRepresentanteLegal" class="form-label">UF <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control uf @error('ufRepresentanteLegal') is-invalid @enderror" list="optionsSiglasRepresentanteLegal" name="ufRepresentanteLegal" id="ufRepresentanteLegal" maxlength="2" value="{{ old('ufRepresentanteLegal', $endereco->uf ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        <datalist id="optionsSiglasRepresentanteLegal">
                                            <option value="AC"></option>
                                            <option value="AL"></option>
                                            <option value="AP"></option>
                                            <option value="AM"></option>
                                            <option value="BA"></option>
                                            <option value="CE"></option>
                                            <option value="DF"></option>
                                            <option value="ES"></option>
                                            <option value="GO"></option>
                                            <option value="MA"></option>
                                            <option value="MT"></option>
                                            <option value="MS"></option>
                                            <option value="MG"></option>
                                            <option value="PA"></option>
                                            <option value="PB"></option>
                                            <option value="PR"></option>
                                            <option value="PE"></option>
                                            <option value="PI"></option>
                                            <option value="RJ"></option>
                                            <option value="RN"></option>
                                            <option value="RS"></option>
                                            <option value="RO"></option>
                                            <option value="RR"></option>
                                            <option value="SC"></option>
                                            <option value="SP"></option>
                                            <option value="SE"></option>
                                            <option value="TO"></option>
                                          </datalist>
                                        @error('ufRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="latitudeRepresentanteLegal" class="form-label">Latitude <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control latitude @error('latitudeRepresentanteLegal') is-invalid @enderror bg-light" name="latitudeRepresentanteLegal" id="latitudeRepresentanteLegal" value="{{ old('latitudeRepresentanteLegal', $endereco->latitude ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('latitudeRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="longitudeRepresentanteLegal" class="form-label">Longitude <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control longitude @error('longitudeRepresentanteLegal') is-invalid @enderror bg-light" name="longitudeRepresentanteLegal" id="longitudeRepresentanteLegal" value="{{ old('longitudeRepresentanteLegal', $endereco->longitude ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('longitudeRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="comprovanteRepresentanteLegal" class="form-label text-bold">Comprovante de endereço:</label>
                                        <input type="file" class="form-control comprovante @error('comprovanteRepresentanteLegal') is-invalid @enderror" name="comprovanteRepresentanteLegal" id="comprovanteRepresentanteLegal" accept="image/jpeg,image/jpg,image/png,image/gif,.pdf" />
                                        @error('comprovanteRepresentanteLegal')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    @if(isset($endereco->id))
                                        <div style="width: 90px;">
                                        @include('components.tables._openPhotoAndPdf',[
                                            'asset' => $endereco->comprovante,
                                            'alt' => "Comprovante de " . $representante->firstName . " " . $representante->lastName,
                                            'title' => "Comprovante de " . $representante->firstName . " " . $representante->lastName,
                                            'text' => 'Visualizar foto',
                                            'index' => 4,
                                        ])
                                        </div>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="d-flex justify-content-between mt-4">
        <a class="btn btn-outline-secondary" href="{{ route("admin.cadastroDeAmbulantes.ambulantes.proprietarioEdit", $ambulante->id ) }}">
            <i class="fa-solid fa-arrow-left-long"></i> Anterior
        </a>
        <button class="btn btn-primary d-inline" type="submit">
            <i class="fa-solid fa-user-plus"></i> Salvar e Prosseguir
        </button>
    </div>
</form>