<form action="{{ $ambulante?->id ? route('admin.cadastroDeAmbulantes.ambulantes.proprietarioUpdate', $ambulante?->id) : route('admin.cadastroDeAmbulantes.ambulantes.proprietarioStore') }}" 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">
                        <h5 class="card-title">Proprietário 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', $proprietario?->id ?? NULL) }}"/>
                                        <input type="hidden" name="domicilioProprietario" id="domicilioProprietario" value="{{ old('domicilioProprietario', $endereco?->domicilio ?? "OUTROS") }}"/>
                                        <input type="hidden" name="papersProprietario" id="papersProprietario" value="{{ old('papersProprietario', $proprietario?->papers ?? "EDIT") }}"/>
                                        <input type="hidden" name="permissionProprietario" id="permissionProprietario" value="{{ old('permissionProprietario', $proprietario?->permission ?? "GUEST") }}"/>
                                        <input type="hidden" name="passwordProprietario" id="passwordProprietario" value="{{ old('passwordProprietario', $proprietario?->password ?? "mudar123") }}"/>
                                        <label for="fullNameProprietario" class="form-label text-bold">Nome completo: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('fullNameProprietario') is-invalid @enderror" name="fullNameProprietario" id="fullNameProprietario" value="{{ old('fullNameProprietario', $proprietario?->id ? $proprietario->firstName . " " . $proprietario->lastName : NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                    @error('fullNameProprietario')
                                            <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="cpfProprietario" class="form-label text-bold">CPF: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('cpfProprietario') is-invalid @enderror" name="cpfProprietario" id="cpfProprietario" value="{{ formatCnpjCpf(old('cpfProprietario', $proprietario?->cpf ?? session("cpfTmp", NULL) ) ) }}" oninput="javascript:aplicarMascaraCPF(this)" autocomplete="off">
                                    @error('cpfProprietario')
                                            <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="phoneNumberProprietario" class="form-label text-bold">Telefone: <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control @error('phoneNumberProprietario') is-invalid @enderror" name="phoneNumberProprietario" id="phoneNumberProprietario" value="{{ old('phoneNumberProprietario', $proprietario?->phoneNumber ?? NULL) }}" oninput="aplicarMascaraTelefone(this)" autocomplete="off">
                                    @error('phoneNumberProprietario')
                                            <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="emailProprietario" class="form-label text-bold">Email: <span class="span-admin-create">*</span></label>
                                        <input type="emailProprietario" class="form-control @error('emailProprietario') is-invalid @enderror" name="emailProprietario" id="emailProprietario" value="{{ old('emailProprietario', $proprietario?->email ?? NULL) }}" oninput="this.value = this.value.toLowerCase()" autocomplete="off">
                                    @error('emailProprietario')
                                            <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="photoProprietario" class="form-label text-bold">Foto:</label>
                                        <input type="file" class="form-control @error('photoProprietario') is-invalid @enderror" name="photoProprietario" id="photoProprietario" accept="image/jpeg,image/jpg,image/png,image/gif" />
                                    @error('photoProprietario')
                                            <small class="text-danger text-bold">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    @if(isset($proprietario->id))
                                        <div style="width: 90px;">
                                        @include('components.tables._openPhoto',[
                                            'asset' => $proprietario->photo,
                                            'alt' => $proprietario->firstName . " " . $proprietario->lastName,
                                            'title' => $proprietario->firstName . " " . $proprietario->lastName,
                                            'text' => 'Visualizar foto',
                                            'index' => 1,
                                        ])
                                        </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 responsável</h5>
                        <div class="container address">
                            <div class="row">
                                <div class="col-sm-12 col-md-7">
                                    <div class="mb-3">
                                        <label for="cepProprietario" class="form-label">CEP <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control cep @error('cepProprietario') is-invalid @enderror" name="cepProprietario" id="cepProprietario" oninput="aplicarMascaraCEP(this)" autocomplete="off" value="{{ old('cepProprietario', $endereco?->cep ?? NULL) }}" autocomplete="off">
                                        @error('cepProprietario')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="logradouroProprietario" class="form-label">Logradouro <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control logradouro @error('logradouroProprietario') is-invalid @enderror" name="logradouroProprietario" id="logradouroProprietario" value="{{ old('logradouroProprietario', $endereco?->logradouro ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('logradouroProprietario')
                                            <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="numeroProprietario" class="form-label">Número</label>
                                        <input type="text" class="form-control numero @error('numeroProprietario') is-invalid @enderror" name="numeroProprietario" id="numeroProprietario" value="{{ old('numeroProprietario', $endereco?->numero ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('numeroProprietario')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="complementoProprietario" class="form-label">Complemento</label>
                                        <input type="text" class="form-control complemento @error('complementoProprietario') is-invalid @enderror" name="complementoProprietario" id="complementoProprietario" value="{{ old('numeroProprietario', $endereco?->complemento ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('complementoProprietario')
                                            <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="cidadeProprietario" class="form-label">Cidade <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control cidade @error('cidadeProprietario') is-invalid @enderror" name="cidadeProprietario" id="cidadeProprietario" value="{{ old('cidadeProprietario', $endereco?->cidade ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('cidadeProprietario')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="bairroProprietario" class="form-label">Bairro <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control bairro @error('bairroProprietario') is-invalid @enderror" name="bairroProprietario" id="bairroProprietario" value="{{ old('bairroProprietario', $endereco?->bairro ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('bairroProprietario')
                                            <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="ufProprietario" class="form-label">UF <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control uf @error('ufProprietario') is-invalid @enderror" list="optionsSiglasProprietario" name="ufProprietario" id="ufProprietario" maxlength="2" value="{{ old('ufProprietario', $endereco?->uf ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        <datalist id="optionsSiglasProprietario">
                                            <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('ufProprietario')
                                            <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="latitudeProprietario" class="form-label">Latitude <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control latitude @error('latitudeProprietario') is-invalid @enderror bg-light" name="latitudeProprietario" id="latitudeProprietario" value="{{ old('latitudeProprietario', $endereco?->latitude ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('latitudeProprietario')
                                            <small class="text-danger">{{ $message }}</small>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-sm-12 col-md-5">
                                    <div class="mb-3">
                                        <label for="longitudeProprietario" class="form-label">Longitude <span class="span-admin-create">*</span></label>
                                        <input type="text" class="form-control longitude @error('longitudeProprietario') is-invalid @enderror bg-light" name="longitudeProprietario" id="longitudeProprietario" value="{{ old('longitudeProprietario', $endereco?->longitude ?? NULL) }}" oninput="this.value = this.value.toUpperCase()" autocomplete="off">
                                        @error('longitudeProprietario')
                                            <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="comprovanteProprietario" class="form-label text-bold">Comprovante de endereço:</label>
                                        <input type="file" class="form-control comprovante @error('comprovanteProprietario') is-invalid @enderror" name="comprovanteProprietario" id="comprovanteProprietario" accept="image/jpeg,image/jpg,image/png,image/gif,.pdf" />
                                        @error('comprovanteProprietario')
                                            <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 " . $proprietario->firstName . " " . $proprietario->lastName,
                                                'title' => "Comprovante de " . $proprietario->firstName . " " . $proprietario->lastName,
                                                'text' => 'Visualizar foto',
                                                'index' => 2,
                                            ])
                                        </div>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="d-flex justify-content-end mt-4">
        <div>
            <button class="btn btn-danger me-2 d-inline" type="button"
                    onclick="window.location.href='{{ route('admin.cadastroDeAmbulantes.ambulantes.index') }}'">
                <i class="fa-solid fa-xmark"></i> Cancelar
            </button>
            <button class="btn btn-primary d-inline" type="submit">
                <i class="fa-solid fa-user-plus"></i> Salvar e Prosseguir
            </button>
        </div>
    </div>
</form>