<div class="mb-3">
    <input type="hidden" name="id" value="{{ old('id', $secretaria->id) }}">
    <input type="hidden" name="slug" value="{{ old('slug', $secretaria->slug) }}">
    <label for="type" class="form-label text-bold">Tipo de cadastro: <span class="span-admin-create">*</span></label>
    <select class="form-control @error('type') is-invalid @enderror" name="type" id="type" onchange="javascript:showHideSecretariaID(this.value)">
        @foreach(App\Enums\StructuresTypeStatusEnum::cases() as $types)
        @if($secretaria->type == $types->name)
                <option value="{{ $types->name }}" selected>{{ $types->value }}</option>
            @else
                <option value="{{ $types->name }}">{{ $types->value }}</option>
            @endif
        @endforeach
    </select>
    @error('type')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>
<div class="mb-3 @if(!in_array($secretaria->type, ["SECRETARIA_EXECUTIVA", "DIRETORIA", "SUPERINTENDENCIA"])) d-none @endif" id="secretariaDIV">
    <label for="type" class="form-label text-bold">Pertence a: <span class="span-admin-create">*</span></label>
    <select class="form-control" name="structure_id" id="structureID">
        <option value=""></option>
        @foreach($secretarias as $sec)
            @if($secretaria->structure_id == $sec->id)
                <option value="{{ $sec->id }}" selected>{{ $sec->name }}</option>
            @else
                <option value="{{ $sec->id }}">{{ $sec->name }}</option>
            @endif
        @endforeach
    </select>
</div>

<div class="mb-3">
    <label for="name" class="form-label text-bold">Nome do órgão: <span class="span-admin-create">*</span></label>
    <input type="text" class="form-control @error('name') is-invalid @enderror" name="name" id="name" autocomplete="off" value="{{ old('name', $secretaria->name) }}">
                            @error('name')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>

<div class="mb-3">
    <label for="abbreviation" class="form-label text-bold">Sigla do órgão: <span class="span-admin-create">*</span></label>
    <input type="text" class="form-control @error('abbreviation') is-invalid @enderror" name="abbreviation" id="abbreviation" autocomplete="off" value="{{ old('abbreviation', $secretaria->abbreviation) }}">
                            @error('abbreviation')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>

<div class="mb-3">
    <label for="phoneNumber" class="form-label text-bold">Telefone: <span class="span-admin-create">*</span></label>
    <input type="text" class="form-control @error('phoneNumber') is-invalid @enderror" name="phoneNumber" id="phoneNumber" autocomplete="off" value="{{ old('phoneNumber', $secretaria->phoneNumber) }}">
                            @error('phoneNumber')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>
<div class="mb-3">
    <img src="{{ asset($secretaria->banner) }}" class="img-fluid rounded-2 mb-3" width="300px"><br>
    <label for="banner" class="form-label text-bold">Banner da secretaria:</label>
    <input type="file" class="form-control" name="banner" id="banner" accept="image/jpeg,image/jpg,image/png,image/gif" />
</div>
<div class="mb-3 text-wrap">
    <label for="description" class="form-label text-bold">Informações do órgão: <span class="span-admin-create">*</span></label>
    <textarea class="form-control textarea-comments @error('description') is-invalid @enderror" name="description" id="description">{{ old('description', $secretaria->description) }}</textarea>
    @error('description')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>
<div class="mb-3">
    <label for="openingHours" class="form-label text-bold">Horários de funcionamento:</label>
    <input type="text" class="form-control @error('openingHours') is-invalid @enderror" name="openingHours" id="openingHours" autocomplete="off" value="{{ old('openingHours', $secretaria->openingHours) }}">
    @error('openingHours')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>
<div class="mb-3">
    <label for="serviceHours" class="form-label text-bold">Horários de atendimento:</label>
    <input type="text" class="form-control @error('serviceHours') is-invalid @enderror" name="serviceHours" id="serviceHours" autocomplete="off" value="{{ old('serviceHours', $secretaria->serviceHours) }}">
    @error('serviceHours')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>
@include('components.inputs._textarea', [
    'label' => __('Informações adicionais (página Fale Conosco)'),
    'name' => 'faleConoscoExtraInfo',
    'id' => 'faleConoscoExtraInfo',
    'rows' => 5,
    'required' => false,
    'height' => '400px',
    'class' => 'textarea-body',
    'style' => null,
    'value' => old('faleConoscoExtraInfo', $secretaria->faleConoscoExtraInfo),
])
<small class="text-muted d-block mb-3">{{ __('Campo opcional. Exibido na página Fale Conosco do órgão, entre o horário de atendimento e a localização, sem título.') }}</small>
@php $currentPageContentType = old('page_content_type', $secretaria->page_content_type ?? 'NOTICIAS'); @endphp
<div class="mb-3">
    <label for="page_content_type" class="form-label text-bold">{{ __('Tipo de conteúdo da página pública') }}: <span class="span-admin-create">*</span></label>
    <select class="form-control @error('page_content_type') is-invalid @enderror" name="page_content_type" id="page_content_type" onchange="toggleHtmlInfo(this.value)">
        <option value="NOTICIAS" {{ $currentPageContentType === 'NOTICIAS' ? 'selected' : '' }}>{{ __('Notícias') }}</option>
        <option value="HTML" {{ $currentPageContentType === 'HTML' ? 'selected' : '' }}>{{ __('HTML (Páginas)') }}</option>
        <option value="HTML_NOTICIAS" {{ $currentPageContentType === 'HTML_NOTICIAS' ? 'selected' : '' }}>{{ __('HTML + Notícias') }}</option>
    </select>
    <small class="text-muted">{{ __('Define o que é exibido no corpo da página pública deste órgão.') }}</small>
    @error('page_content_type')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>

<div id="htmlInfoEdit" class="@if(!in_array($currentPageContentType, ['HTML', 'HTML_NOTICIAS'])) d-none @endif">
    @if(isset($htmls) && $htmls->count() > 0)
        <div class="mb-3">
            <label for="html_page_id" class="form-label text-bold">{{ __('Página HTML a exibir') }}: <span class="span-admin-create">*</span></label>
            <select class="form-control @error('html_page_id') is-invalid @enderror" name="html_page_id" id="html_page_id">
                <option value="">{{ __('Selecione uma página...') }}</option>
                @foreach($htmls as $htmlItem)
                    <option value="{{ $htmlItem->id }}" {{ old('html_page_id', $secretaria->html_page_id) === $htmlItem->id ? 'selected' : '' }}>
                        {{ $htmlItem->title }}
                    </option>
                @endforeach
            </select>
            @error('html_page_id')
                <small class="text-danger text-bold">{{ $message }}</small>
            @enderror
            <small class="text-muted">
                {{ __('Apenas páginas HTML ativas vinculadas a este órgão são listadas.') }}
                <a href="{{ route('admin.htmls.index') }}" target="_blank" class="ms-1">
                    <i class="fa-solid fa-arrow-up-right-from-square fa-xs"></i> {{ __('Gerenciar páginas HTML') }}
                </a>
            </small>
        </div>
    @else
        <div class="alert alert-warning mb-3">
            <i class="fa-solid fa-triangle-exclamation me-1"></i>
            {!! __('Nenhuma página HTML ativa vinculada a este órgão. <a href="' . route('admin.htmls.create') . '" target="_blank">Clique aqui para criar uma</a> e vincule-a a este órgão.') !!}
        </div>
        <input type="hidden" name="html_page_id" value="">
    @endif
</div>

@php $currentPageContentOrder = old('page_content_order', $secretaria->page_content_order ?? 'HTML_FIRST'); @endphp
<div id="pageContentOrderDiv" class="mb-3 @if($currentPageContentType !== 'HTML_NOTICIAS') d-none @endif">
    <label for="page_content_order" class="form-label text-bold">{{ __('Ordem do conteúdo') }}:</label>
    <select class="form-control @error('page_content_order') is-invalid @enderror" name="page_content_order" id="page_content_order">
        <option value="HTML_FIRST" {{ $currentPageContentOrder === 'HTML_FIRST' ? 'selected' : '' }}>{{ __('HTML > Notícias') }}</option>
        <option value="NEWS_FIRST" {{ $currentPageContentOrder === 'NEWS_FIRST' ? 'selected' : '' }}>{{ __('Notícias > HTML') }}</option>
    </select>
    @error('page_content_order')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>

@php $currentNewsStructureId = old('news_structure_id', $secretaria->news_structure_id ?? ''); @endphp
<div id="newsStructureDiv" class="mb-3 @if($currentPageContentType === 'HTML') d-none @endif">
    <label for="news_structure_id" class="form-label text-bold">{{ __('Órgão fonte das notícias') }}:</label>
    <select class="form-control @error('news_structure_id') is-invalid @enderror" name="news_structure_id" id="news_structure_id">
        <option value="">{{ __('Este próprio órgão (padrão)') }}</option>
        @foreach($todasStructures as $str)
            @if($str->id !== $secretaria->id)
                <option value="{{ $str->id }}" {{ $currentNewsStructureId === $str->id ? 'selected' : '' }}>
                    {{ $str->name }} @if($str->abbreviation)({{ $str->abbreviation }})@endif
                </option>
            @endif
        @endforeach
    </select>
    @error('news_structure_id')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
    <small class="text-muted">{{ __('Se vazio, as notícias exibidas serão as vinculadas a este próprio órgão.') }}</small>
</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', $secretaria->status) === $status->name ? 'selected' : '' }}>
                {{ $status->value }}
            </option>
        @endforeach
    </select>
    @error('status')
        <small class="text-danger text-bold">{{ $message }}</small>
    @enderror
</div>

