@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: ' . __('Nova Unidade Organizacional'))

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

    <div class="card shadow-sm">

        @php $headLine = "<i class='fa-solid fa-sitemap'></i> " . __('Nova Unidade Organizacional'); @endphp
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine'        => __($headLine),
            'routeBack'       => 'admin.unidadesOrganizacionais.index',
            'routeBackParams' => request()->only(['q', 'structure_id', 'status', 'page']),
            'nameBack'        => __('Voltar'),
            'permission'      => 'GERENCIADOR_DE_UNIDADES_ORGANIZACIONAIS',
        ])

        <div class="card-body">
            <form method="post" action="{{ route('admin.unidadesOrganizacionais.store') }}">
                @csrf

                @foreach(request()->only(['q', 'structure_id', 'status', 'page']) as $key => $value)
                    @if($value)
                        <input type="hidden" name="{{ $key }}" value="{{ $value }}">
                    @endif
                @endforeach

                <div class="row">
                    <div class="col-sm-12 col-md-6">
                        @include('components.inputs._selectType', [
                            'for'         => 'structure_id',
                            'label'       => __('Secretaria'),
                            'name'        => 'structure_id',
                            'id'          => 'structureSelect',
                            'required'    => false,
                            'readonly'    => false,
                            'placeholder' => __('Selecione a secretaria (opcional)...'),
                            'options'     => $secretarias->mapWithKeys(
                                fn($s) => [$s->id => "{$s->abbreviation} — {$s->name}"]
                            )->toArray(),
                            'selected'    => old('structure_id'),
                            'small'       => __('Opcional. Secretaria à qual esta unidade pertence.'),
                        ])
                    </div>
                    <div class="col-sm-12 col-md-6">
                        @include('components.inputs._inputType', [
                            'for'      => null,
                            'label'    => __('Sigla'),
                            'name'     => 'abbreviation',
                            'id'       => null,
                            'required' => true,
                            'type'     => null,
                            'old'      => old('abbreviation'),
                            'oninput'  => "javascript:this.value = this.value.toUpperCase().replace(/[^A-Z0-9\/\-]/g, '')",
                            'readonly' => false,
                            'small'    => __('Ex.: CTSIS, DTIC, SADT. Será convertida para maiúsculas automaticamente.'),
                        ])
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 col-md-8">
                        @include('components.inputs._inputType', [
                            'for'      => null,
                            'label'    => __('Nome da Unidade'),
                            'name'     => 'name',
                            'id'       => null,
                            'required' => true,
                            'type'     => null,
                            'old'      => old('name'),
                            'oninput'  => null,
                            'readonly' => false,
                            'small'    => __('Ex.: Coordenação Técnica de Sistemas Informatizados.'),
                        ])
                    </div>
                    <div class="col-sm-12 col-md-4">
                        @include('components.inputs._selectType', [
                            'for'         => 'status',
                            'label'       => __('Status'),
                            'name'        => 'status',
                            'required'    => true,
                            'readonly'    => false,
                            'placeholder' => __('Selecione o status...'),
                            'options'     => collect(App\Enums\StatusEnum::cases())
                                ->mapWithKeys(fn($s) => [$s->name => $s->value])
                                ->toArray(),
                            'selected'    => old('status', 'ATIVADO'),
                            'small'       => null,
                        ])
                    </div>
                </div>

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