@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Editar Ponto Focal")
@section('content')

    <form action="{{ route('admin.pontosFocais.update', $pontoFocal->id) }}" method="post">
        <div class="container py-3">
            <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="mb-0">Editar Ponto Focal</h5>
                        </div>
                        <div class="card-body">
                            @csrf
                            @method('PUT')
                            @include("errors.messageFlash")

                            <div class="mb-3">
                                <label for="structure_id" class="form-label text-bold">Instituição: <span class="span-admin-create">*</span></label>
                                <select class="form-control @error('structure_id') is-invalid @enderror" name="structure_id" id="structure_id" required>
                                    <option value="">Selecione uma instituição</option>
                                    
                                    @if($gabinetes->count() > 0)
                                        <optgroup label="Gabinetes">
                                            @foreach($gabinetes as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                    @if($secretarias->count() > 0)
                                        <optgroup label="Secretarias">
                                            @foreach($secretarias as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                    @if($executivas->count() > 0)
                                        <optgroup label="Secretarias Executivas">
                                            @foreach($executivas as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                    @if($autarquias->count() > 0)
                                        <optgroup label="Autarquias e Fundações">
                                            @foreach($autarquias as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                    @if($superintendencias->count() > 0)
                                        <optgroup label="Superintendências">
                                            @foreach($superintendencias as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                    @if($diretorias->count() > 0)
                                        <optgroup label="Diretorias">
                                            @foreach($diretorias as $instituicao)
                                                <option value="{{ $instituicao->id }}" {{ (old('structure_id', $pontoFocal->structure_id) == $instituicao->id) ? 'selected' : '' }}>
                                                    {{ $instituicao->name }}@if($instituicao->abbreviation) ({{ $instituicao->abbreviation }})@endif
                                                </option>
                                            @endforeach
                                        </optgroup>
                                    @endif
                                    
                                </select>
                                @error('structure_id')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <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', $pontoFocal->nome) }}" required>
                                @error('nome')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="matricula" class="form-label text-bold">Matrícula: <span class="span-admin-create">*</span></label>
                                <input type="text" class="form-control @error('matricula') is-invalid @enderror" name="matricula" id="matricula" autocomplete="off" value="{{ old('matricula', $pontoFocal->matricula) }}" required>
                                @error('matricula')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="telefone_ramal" class="form-label text-bold">Telefone/Ramal:</label>
                                <input type="text" class="form-control @error('telefone_ramal') is-invalid @enderror" name="telefone_ramal" id="telefone_ramal" autocomplete="off" value="{{ old('telefone_ramal', $pontoFocal->telefone_ramal) }}">
                                @error('telefone_ramal')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="email" class="form-label text-bold">E-mail:</label>
                                <input type="email" class="form-control @error('email') is-invalid @enderror" name="email" id="email" autocomplete="off" value="{{ old('email', $pontoFocal->email) }}">
                                @error('email')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="observacao" class="form-label text-bold">Observação:</label>
                                <textarea class="form-control @error('observacao') is-invalid @enderror" name="observacao" id="observacao" rows="4">{{ old('observacao', $pontoFocal->observacao) }}</textarea>
                                @error('observacao')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            @include('components.buttons._backAndSend', [
                                    'textBack' => 'Voltar', 
                                    'textSend' => 'Atualizar', 
                                    'routeBack' => 'admin.pontosFocais.index'
                                ]
                            )
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

@endsection

