@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: ' . __('Editar correção da portaria'))

@section('content')
    @include('errors.messageFlash')

    <div class="card shadow-sm">
        @php $headLine = "<i class='fa-solid fa-pen-to-square'></i> " . __('Correção na portaria'); @endphp
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __($headLine),
            'routeBack' => 'admin.legislacao.portarias.edit',
            'routeBackParams' => ['portaria' => $portaria->id_portaria] + ($filterParams ?? []),
            'nameBack' => __('Voltar'),
            'permission' => 'GERENCIADOR_DE_LEGISLACAO',
        ])

        <div class="card-body">
            <form method="post"
                action="{{ route('admin.legislacao.portarias.retificacoes.update', [$portaria, $retificacao] + ($filterParams ?? [])) }}">
                @csrf
                @method('put')
                <div class="row g-3">
                    <div class="col-md-4">
                        <label class="form-label">{{ __('Tipo') }}</label>
                        <select name="cd_tipo" class="form-select" required>
                            <option value="1" @selected((int) old('cd_tipo', $retificacao->cd_tipo) === 1)>{{ __('Errata') }}</option>
                            <option value="2" @selected((int) old('cd_tipo', $retificacao->cd_tipo) === 2)>{{ __('Republicação') }}</option>
                        </select>
                    </div>
                    <div class="col-md-8">
                        <label class="form-label">{{ __('Boletim oficial') }}</label>
                        @php
                            $prBoSelId = old('id_boletim_oficial', $retificacao->id_boletim_oficial ?? '');
                            $prBoSelLabel = $retificacao->boletim ? $retificacao->boletim->nr_bo : '';
                        @endphp
                        <select name="id_boletim_oficial" id="portaria_retificacao_boletim" class="form-select js-legislacao-boletim-api" required
                            data-api-url="{{ route('api.boletinsOficiais') }}"
                            data-placeholder="{{ __('Selecione') }}"
                            data-selected-id="{{ $prBoSelId }}"
                            data-selected-label="{{ e($prBoSelLabel) }}">
                            <option value="">{{ __('Selecione') }}</option>
                        </select>
                    </div>
                    <div class="col-12">
                        <label class="form-label">{{ __('Descrição') }}</label>
                        <textarea name="ds_descricao" class="form-control" rows="4">{{ old('ds_descricao', $retificacao->ds_descricao) }}</textarea>
                    </div>
                </div>
                <div class="mt-4 d-flex justify-content-end">
                    <button type="submit" class="btn btn-success px-4">
                        <i class="fa-solid fa-floppy-disk me-1" aria-hidden="true"></i>{{ __('Salvar') }}
                    </button>
                </div>
            </form>
        </div>
    </div>
@endsection

@push('after-scripts')
    <script src="{{ asset('pmar/js/admin/legislacao-boletim-api-select.js') }}" defer></script>
@endpush
