@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Atualizar endereço de {$user->name} sob CPF nº {$user->cpf}")
@section('content')

    <form action="{{ route('admin.contas.enderecos.update', [$user->id, $endereco->id]) }}" method="post" enctype="multipart/form-data">
        <div class="container mt-4">
            <div class="row">
                <div class="col-12">
                    <div class="card shadow">

                        @php $headLine = "<i class='fa-solid fa-location-dot'></i> Atualizar endereço de <strong>{$user->name}</strong> sob CPF nº <strong>{$user->cpf}</strong>"; @endphp

                        @include('components.buttons._headLineButtonsBackAdd', [
                            'headLine' => __($headLine),
                            'routeBack' => 'admin.contas.enderecos.index',
                            'routeBackParams' => [$user->id], 
                            'nameBack' => __("Voltar"),
                            "permission" => "SYSADMIN",
                        ])

                        <div class="card-body">
                            @csrf
                            @method('patch')
                            @include("errors.messageFlash")

                            <div class="mb-3">

                                @include('components.inputs._selectType', [
                                        "for" => "domicilio",
                                        "label" => "Tipo de domicilio",
                                        "name" => "domicilio",
                                        "required" => true,
                                        "readonly" => false,
                                        "options" => collect(App\Enums\StatusDomicilio::cases())
                                            ->mapWithKeys(fn($status) => [$status->name => $status->value])
                                            ->toArray(),
                                        "selected" => old('domicilio', $endereco->domicilio ?? ''),
                                        "placeholder" => "Selecione o status...",
                                        "small" => "Informe o status atual do usuário.",
                                        "onchange" => null
                                    ])
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo CEP -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "CEP",
                                        "name" => "cep",
                                        "id" => "zipCode",
                                        "required" => true,
                                        "type" => null,
                                        "old" => old('cep', $endereco->cep),
                                        "oninput" => "javascript:aplicarMascaraCEP(this)",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                            </div>
                            <div class="mb-3">
                                <!-- Campo Logradouro -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "Logradouro",
                                        "name" => "logradouro",
                                        "id" => "street",
                                        "required" => true,
                                        "type" => null,
                                        "old" => old('logradouro', $endereco->logradouro),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo Número -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "Número",
                                        "name" => "numero",
                                        "id" => "numero",
                                        "required" => false,
                                        "type" => null,
                                        "old" => old('numero', $endereco->numero),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                                
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo Complemento -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "Complemento",
                                        "name" => "complemento",
                                        "id" => "complemento",
                                        "required" => false,
                                        "type" => null,
                                        "old" => old('complemento', $endereco->complemento),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                                
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo Cidade -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "Cidade",
                                        "name" => "cidade",
                                        "id" => "city",
                                        "required" => true,
                                        "type" => null,
                                        "old" => old('cidade', $endereco->cidade),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                                
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo Bairro -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "Bairro",
                                        "name" => "bairro",
                                        "id" => "neighborhood",
                                        "required" => true,
                                        "type" => null,
                                        "old" => old('bairro', $endereco->bairro),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                    ])
                                
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo UF -->
                                    @include('components.inputs._inputType',[
                                        "for" => null,
                                        "label" => "UF",
                                        "name" => "uf",
                                        "id" => "state",
                                        "required" => true,
                                        "type" => null,
                                        "old" => old('uf', $endereco->uf),
                                        "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                        "readonly" => false,
                                        "small" => null,
                                        "listName" => "estadosBrasileiros",
                                        "arrayList" => [
                                            'AC', 'AL', 'AM', 'AP', 'BA', 'CE', 'DF', 'ES', 'GO',
                                            'MA', 'MG', 'MS', 'MT', 'PA', 'PB', 'PE', 'PI', 'PR',
                                            'RJ', 'RN', 'RO', 'RR', 'RS', 'SC', 'SE', 'SP', 'TO'
                                        ],
                                    ])
                                
                            </div>
                            <hr/>

                            <div class="mb-3">
                                <!-- Campo Comprovante -->
                                        @include('components.inputs._inputType',[
                                            "for" => null,
                                            "label" => "Comprovante",
                                            "name" => "comprovante",
                                            "id" => null,
                                            "required" => false,
                                            "type" => 'file',
                                            "old" => null,
                                            "oninput" => null,
                                            "readonly" => true,
                                            "small" => null,
                                            "accept" => 'image/jpeg,image/jpg,image/png,image/gif,.pdf',
                                        ])
                            </div>
                            <div class="mb-3">
                                
                                <!-- Campo Status -->
                                    @include('components.inputs._selectType', [
                                        "for" => "status",
                                        "label" => "Status",
                                        "name" => "status",
                                        "required" => true,
                                        "readonly" => false,
                                        "options" => collect(App\Enums\StatusEnum::cases())
                                            ->mapWithKeys(fn($status) => [$status->name => $status->value])
                                            ->toArray(),
                                        "selected" => old('status', $endereco->status ?? ''),
                                        "placeholder" => "Selecione o status...",
                                        "small" => "Informe o status atual do usuário.",
                                        "onchange" => null
                                    ])
                                
                            </div>
                            <div class="mb-3">
                                <hr>

                                <div class="col-sm-12 col-md-3 d-flex justify-content-start align-self-center">
                                <!-- Map Modal -->
                                    @include('components.modal._mapModal',[
                                        "label" => "Clique no mapa e escolha um determinado ponto",
                                    ])
                                </div>

                                <hr/>

                                <div class="col-12">
                                <!-- Campo Latitude -->
                                    @include('components.inputs._inputType',[
                                                "for" => null,
                                                "label" => "Latitude",
                                                "name" => "latitude",
                                                "id" => null,
                                                "required" => true,
                                                "type" => null,
                                                "old" => old('latitude', $endereco->latitude),
                                                "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                                "readonly" => false,
                                                "small" => null,
                                            ])
                                </div>
                                <div class="col-12">
                                <!-- Campo Longitude -->
                                    @include('components.inputs._inputType',[
                                                "for" => null,
                                                "label" => "Longitude",
                                                "name" => "longitude",
                                                "id" => null,
                                                "required" => true,
                                                "type" => null,
                                                "old" => old('longitude', $endereco->longitude),
                                                "oninput" => "javascript:this.value = this.value.toUpperCase()",
                                                "readonly" => false,
                                                "small" => null,
                                            ])
                                </div>

                                <hr>
                            </div>
                            <div class="mb-3">
                                @include('components.buttons._backAndSend', [
                                        'textBack' => 'Voltar', 
                                        'textSend' => 'Cadastrar', 
                                        'routeBack' => 'admin.contas.enderecos.index',
                                        'backId' => [$user->id]
                                    ]
                                )
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

@endsection