@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Editar Parques e Jardins")
@section('content')

    <form action="{{ route('admin.parquesJardins.update', $parque->id) }}" method="post" enctype="multipart/form-data">
        <div class="container mt-4">
            <div class="row">
                <div class="col-12">
                    <div class="card shadow">
                        <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center mb-3">
                            <h5 class="my-2">Editar Parques e Jardins</h5>
                        </div>    
                        <div class="card-body">
                            @csrf
                            @method('PUT')
                            @include("errors.messageFlash")

                            <div class="mb-3">
                                <label for="type" class="form-label text-bold">Pertence a: <span
                                        class="span-admin-create">*</span></label>
                                <select class="form-control @error('structure_id') is-invalid @enderror" name="structure_id"
                                    id="structureID">
                                    @foreach($secretarias as $secretaria)
                                        <option value="{{ $secretaria->id }}" {{ old('structure_id', $parque->structure_id ?? '') == $secretaria->id ? 'selected' : '' }}>
                                            {{ $secretaria->name }} ({{ $secretaria->abbreviation }})
                                        </option>
                                    @endforeach
                                </select>
                                @error('structure_id')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>


                            <div class="mb-3">
                                <label for="foto" class="form-label text-bold">Foto principal:</label>
                                <input type="file" class="form-control" name="foto" id="foto"
                                    accept="image/jpeg,image/jpg,image/png,image/gif" />
                            </div>
                            <hr />

                            <div class="mb-3">
                                <label for="nome" class="form-label text-bold">Nome: <span
                                        class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('nome') is-invalid @enderror" name="nome"
                                    id="nome" autocomplete="off" value="{{ old('nome', $parque->nome) }}">
                                @error('nome')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>
                            
                            @php
                            
                                $array_categorias = [
                                    "Áreas Verdes e Corredores Ecológicos Urbanos",
                                    "Calçadões e Espaços de Convivência",
                                    "Complexos Esportivos",
                                    "Horto",
                                    "Jardins Públicos e Canteiros",
                                    "Mirante",
                                    "Monumentos, Bustos e Espaços Culturais em Áreas Verdes",
                                    "Orlas Urbanizadas à Beira-Mar",
                                    "Parquinhos e Espaços de Recreação Infantil",
                                    "Parques Urbanos",
                                    "Praças Públicas",
                                    "UPRV (Unidade de Processamento de Resíduos Verdes)",
                                ];
                            @endphp

                            <div class="mb-3">
                                <label for="type" class="form-label text-bold">Categoria: <span class="span-admin-create">*</span></label>
                                <select class="form-control" name="categorias" id="categorias">
                                    @for($i=0;$i<sizeof($array_categorias);$i++)
                                        <option value="{{ $array_categorias[$i] }}" {{ old('categorias', $parque->categorias) == $array_categorias[$i] ? 'selected' : '' }}>{{ $array_categorias[$i] }}</option>
                                    @endfor
                                </select>
                            </div>
                            
                            <div class="mb-3">
                                <label for="telefone" class="form-label text-bold">Telefone: </label>
                                <input type="text" class="form-control @error('telefone') is-invalid @enderror"
                                    name="telefone" id="telefone" autocomplete="off"
                                    value="{{ old('telefone', $parque->telefone) }}">
                                @error('telefone')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="email" class="form-label text-bold">Email: </label>
                                <input type="email" class="form-control @error('email') is-invalid @enderror" name="email"
                                    id="email" autocomplete="off" value="{{ old('email', $parque->email) }}">
                                @error('email')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>


                            <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', $parque->endereco->domicilio ?? '') == $status->name ? 'selected' : '' }}>
                                            {{ $status->value }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('domicilio')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="lei" class="form-label">Lei </label>
                                <input type="text" class="form-control @error('lei') is-invalid @enderror" name="lei" id="lei" value="{{ old('lei', $parque->lei) }}" autocomplete="off">
                                @error('lei')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="area" class="form-label">Área </label>
                                <input type="text" class="form-control @error('area') is-invalid @enderror" name="area" id="area" value="{{ old('area', $parque->area) }}" autocomplete="off">
                                @error('area')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="perimetro" class="form-label">Perímetro </label>
                                <input type="text" class="form-control @error('perimetro') is-invalid @enderror" name="perimetro" id="perimetro" value="{{ old('perimetro', $parque->perimetro) }}" autocomplete="off">
                                @error('perimetro')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="cep" class="form-label">CEP <span class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('cep') is-invalid @enderror" name="cep"
                                    id="zipCode" oninput="aplicarMascaraCEP(this)" autocomplete="off"
                                    value="{{ old('cep', $parque->endereco->cep) }}" required>
                                @error('cep')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="logradouro" class="form-label">Logradouro <span
                                        class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('logradouro') is-invalid @enderror"
                                    name="logradouro" id="street" autocomplete="off"
                                    value="{{ old('logradouro', $parque->endereco->logradouro) }}">
                                @error('logradouro')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="numero" class="form-label">Número</label>
                                <input type="text" class="form-control @error('numero') is-invalid @enderror" name="numero"
                                    id="numero" value="{{ old('numero', $parque->endereco->numero) }}">
                                @error('numero')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="complemento" class="form-label">Complemento</label>
                                <input type="text" class="form-control" name="complemento" id="complemento"
                                    value="{{ old('complemento', $parque->endereco->complemento) }}">
                            </div>
                            <div class="mb-3">
                                <label for="cidade" class="form-label">Cidade <span
                                        class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('cidade') is-invalid @enderror" name="cidade"
                                    id="city" autocomplete="off" value="{{ old('cidade', $parque->endereco->cidade) }}">
                                @error('cidade')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="bairro" class="form-label">Bairro <span
                                        class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('bairro') is-invalid @enderror" name="bairro"
                                    id="neighborhood" autocomplete="off"
                                    value="{{ old('bairro', $parque->endereco->bairro) }}">
                                @error('bairro')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="uf" class="form-label">UF <span class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('uf') is-invalid @enderror" name="uf"
                                    id="state" maxlength="2" autocomplete="off"
                                    value="{{ old('uf', $parque->endereco->uf) }}">
                                @error('uf')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="latitude" class="form-label">Latitude </label>
                                <input type="text" class="form-control @error('latitude') is-invalid @enderror" name="latitude" id="latitude" value="{{ old('latitude', $parque->endereco->latitude) }}" autocomplete="off">
                                @error('latitude')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="longitude" class="form-label">Longitude </label>
                                <input type="text" class="form-control @error('longitude') is-invalid @enderror" name="longitude" id="longitude" value="{{ old('longitude', $parque->endereco->longitude) }}" autocomplete="off">
                                @error('longitude')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>
                            <div class="mb-3">
                                <label for="informacoes" class="form-label text-bold">Informações:</label>
                                <textarea class="form-control textarea-body @error('informacoes') is-invalid @enderror"
                                    style="height: 400px" name="informacoes"
                                    id="informacoes">{{ old('informacoes', $parque->informacoes) }}</textarea>
                                @error('informacoes')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>
                            
                            <div class="mb-3">
                                <div class="list-group mb-3">
                                    <a class="list-group-item list-group-item-action active" aria-current="true">
                                        <h5 class="mb-1">* Atributos do Parque</h5>
                                        <small onclick="javascript:selectAllCheckboxParquesJardins(this)"
                                        class="text-warning" style="cursor: pointer">* selecionar todos os atributos</small>
                                    </a>
                                    <div class="list-group-item list-group-item-action">
                                        <div class="mb-1" id="checkboxParquesJardins">
                                            @foreach(App\Enums\StatusAtributosParquesJardins::cases() as $status)
                                                <div class="form-check">
                                                    <input class="form-check-input" type="checkbox" name="atributos[]" value="{{ $status->name }}" id="{{ Str::slug($status->value) }}" @if(in_array($status->name, $atributos)) checked @endif>
                                                    <label class="form-check-label" for="{{ $status->value }}">
                                                        {{ $status->value }}
                                                    </label>
                                                </div>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                            </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', $parque->status) === $status->name ? 'selected' : '' }}>
                                            {{ $status->value }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('status')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>
                            @include('components.buttons._backAndSend', [
                                    'textBack' => 'Voltar', 
                                    'textSend' => 'Atualizar', 
                                    'routeBack' => 'admin.parquesJardins.index'
                                ]
                            )
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

@endsection