<div class="space-y-5">
    <section class="rounded-lg border border-slate-200 bg-white p-5 shadow-soft dark:border-slate-800 dark:bg-slate-900">
        <div class="flex flex-col gap-4 xl:flex-row xl:items-center xl:justify-between">
            <div>
                <p class="text-xs font-semibold uppercase tracking-wide text-primary-600 dark:text-primary-300">Administracao</p>
                <h1 class="mt-1 text-2xl font-bold text-slate-950 dark:text-white">Configuracoes do Sistema</h1>
                <p class="mt-2 max-w-3xl text-sm leading-6 text-slate-600 dark:text-slate-400">Centralize parametros globais do portal, seguranca, arquivos, notificacoes e auditoria.</p>
            </div>

            <div class="flex flex-wrap gap-2">
                <button type="button" wire:click="restaurarPadrao" class="btn-secondary">
                    <x-heroicon name="arrow-path" class="h-5 w-5" />
                    Restaurar padrao
                </button>
                <button type="button" wire:click="salvar" class="btn-primary">
                    <x-heroicon name="check" class="h-5 w-5" />
                    Salvar configuracoes
                </button>
            </div>
        </div>
    </section>

    <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
        @foreach ($indicadores as $indicador)
            <div class="rounded-lg border border-slate-200 bg-white p-4 shadow-soft dark:border-slate-800 dark:bg-slate-900">
                <div class="flex items-center gap-3">
                    <span class="flex h-10 w-10 items-center justify-center rounded-lg bg-accent-100 text-accent-700 dark:bg-slate-800 dark:text-accent-300">
                        <x-heroicon :name="$indicador['icone']" class="h-5 w-5" />
                    </span>
                    <div class="min-w-0">
                        <p class="text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400">{{ $indicador['nome'] }}</p>
                        <p class="truncate text-sm font-bold text-slate-950 dark:text-white">{{ $indicador['valor'] }}</p>
                    </div>
                </div>
            </div>
        @endforeach
    </section>

    <section class="grid gap-5 xl:grid-cols-[280px_minmax(0,1fr)]">
        <aside class="rounded-lg border border-slate-200 bg-white p-3 shadow-soft dark:border-slate-800 dark:bg-slate-900">
            <nav class="space-y-1">
                @foreach ($abas as $id => $item)
                    <button type="button" wire:click="$set('aba', '{{ $id }}')" @class([
                        'flex w-full items-center gap-3 rounded-lg px-3 py-3 text-left text-sm font-semibold transition',
                        'bg-primary-50 text-primary-700 dark:bg-primary-950/70 dark:text-primary-200' => $aba === $id,
                        'text-slate-600 hover:bg-slate-100 hover:text-primary-700 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-primary-300' => $aba !== $id,
                    ])>
                        <span class="flex h-8 w-8 items-center justify-center rounded-lg bg-accent-50 text-accent-700 dark:bg-slate-800 dark:text-accent-300">
                            <x-heroicon :name="$item['icone']" class="h-5 w-5" />
                        </span>
                        {{ $item['nome'] }}
                    </button>
                @endforeach
            </nav>
        </aside>

        <form wire:submit.prevent="salvar" class="rounded-lg border border-slate-200 bg-white p-5 shadow-soft dark:border-slate-800 dark:bg-slate-900">
            @if ($aba === 'geral')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Geral</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Dados principais usados como base do portal.</p>
                </div>

                <div class="mt-5 grid gap-4 md:grid-cols-2">
                    <div>
                        <x-input-label for="nome_portal" value="Nome do portal" />
                        <input id="nome_portal" wire:model.defer="nome_portal" class="form-control mt-1">
                        <x-input-error :messages="$errors->get('nome_portal')" class="mt-2" />
                    </div>
                    <div>
                        <x-input-label for="empresa_nome" value="Nome da empresa" />
                        <input id="empresa_nome" wire:model.defer="empresa_nome" class="form-control mt-1">
                        <x-input-error :messages="$errors->get('empresa_nome')" class="mt-2" />
                    </div>
                    <div>
                        <x-input-label for="email_suporte" value="E-mail de suporte" />
                        <input id="email_suporte" wire:model.defer="email_suporte" type="email" class="form-control mt-1">
                        <x-input-error :messages="$errors->get('email_suporte')" class="mt-2" />
                    </div>
                    <div>
                        <x-input-label for="url_sistema" value="URL do sistema" />
                        <input id="url_sistema" wire:model.defer="url_sistema" class="form-control mt-1">
                        <x-input-error :messages="$errors->get('url_sistema')" class="mt-2" />
                    </div>
                    <div>
                        <x-input-label for="departamento_padrao_id" value="Departamento padrao" />
                        <select id="departamento_padrao_id" wire:model.defer="departamento_padrao_id" class="form-control mt-1">
                            <option value="">Sem departamento padrao</option>
                            @foreach ($departamentos as $departamento)
                                <option value="{{ $departamento->id }}">{{ $departamento->nome }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div>
                        <x-input-label for="fuso_horario" value="Fuso horario" />
                        <select id="fuso_horario" wire:model.defer="fuso_horario" class="form-control mt-1">
                            <option value="America/Sao_Paulo">America/Sao_Paulo</option>
                            <option value="UTC">UTC</option>
                        </select>
                    </div>
                </div>
            @elseif ($aba === 'identidade')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Identidade visual</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Base visual do portal. Logos e paleta avancada podem evoluir aqui depois.</p>
                </div>

                <div class="mt-5 grid gap-4 md:grid-cols-2">
                    <div>
                        <x-input-label for="tema_padrao" value="Tema padrao" />
                        <select id="tema_padrao" wire:model.defer="tema_padrao" class="form-control mt-1">
                            <option value="dark">Escuro</option>
                            <option value="light">Claro</option>
                        </select>
                    </div>
                    <div class="rounded-lg border border-slate-200 p-4 dark:border-slate-800">
                        <p class="text-sm font-bold text-slate-950 dark:text-white">Paleta atual</p>
                        <div class="mt-3 flex gap-2">
                            <span class="h-10 flex-1 rounded-lg bg-primary-700"></span>
                            <span class="h-10 flex-1 rounded-lg bg-slate-900"></span>
                            <span class="h-10 flex-1 rounded-lg bg-accent-400"></span>
                        </div>
                        <p class="mt-3 text-xs text-slate-500 dark:text-slate-400">Azul/grafite para superficies e verde Aquila para icones e destaques.</p>
                    </div>
                </div>
            @elseif ($aba === 'seguranca')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Seguranca</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Regras gerais de acesso e protecao do portal.</p>
                </div>

                <div class="mt-5 grid gap-4 md:grid-cols-2">
                    <label class="flex items-center gap-3 rounded-lg border border-slate-200 p-4 text-sm font-semibold text-slate-700 dark:border-slate-800 dark:text-slate-200">
                        <input wire:model.defer="cadastro_publico" type="checkbox" class="rounded border-slate-300 text-primary-600 focus:ring-primary-500">
                        Permitir cadastro publico
                    </label>
                    <label class="flex items-center gap-3 rounded-lg border border-slate-200 p-4 text-sm font-semibold text-slate-700 dark:border-slate-800 dark:text-slate-200">
                        <input wire:model.defer="exigir_email_verificado" type="checkbox" class="rounded border-slate-300 text-primary-600 focus:ring-primary-500">
                        Exigir e-mail verificado
                    </label>
                    <div>
                        <x-input-label for="tentativas_login" value="Tentativas de login" />
                        <input id="tentativas_login" wire:model.defer="tentativas_login" type="number" class="form-control mt-1">
                    </div>
                    <div>
                        <x-input-label for="sessao_minutos" value="Sessao em minutos" />
                        <input id="sessao_minutos" wire:model.defer="sessao_minutos" type="number" class="form-control mt-1">
                    </div>
                </div>
            @elseif ($aba === 'midia')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Arquivos e midia</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Limites usados como referencia para uploads da Wiki e futuros modulos.</p>
                </div>

                <div class="mt-5 grid gap-4 md:grid-cols-3">
                    <div>
                        <x-input-label for="limite_imagem_mb" value="Imagens (MB)" />
                        <input id="limite_imagem_mb" wire:model.defer="limite_imagem_mb" type="number" class="form-control mt-1">
                    </div>
                    <div>
                        <x-input-label for="limite_video_mb" value="Videos (MB)" />
                        <input id="limite_video_mb" wire:model.defer="limite_video_mb" type="number" class="form-control mt-1">
                    </div>
                    <div>
                        <x-input-label for="limite_documento_mb" value="Documentos (MB)" />
                        <input id="limite_documento_mb" wire:model.defer="limite_documento_mb" type="number" class="form-control mt-1">
                    </div>
                </div>

                <div class="mt-5 rounded-lg border border-slate-200 bg-slate-50 p-4 text-sm text-slate-600 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-300">
                    Storage local ativo em <span class="font-semibold">storage/app/public</span>. Videos da Wiki ja usam rota autenticada para visualizacao.
                </div>
            @elseif ($aba === 'notificacoes')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Notificacoes</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Preparacao para avisos internos e mensagens por e-mail.</p>
                </div>

                <div class="mt-5 space-y-4">
                    <label class="flex items-center gap-3 rounded-lg border border-slate-200 p-4 text-sm font-semibold text-slate-700 dark:border-slate-800 dark:text-slate-200">
                        <input wire:model.defer="notificacoes_email" type="checkbox" class="rounded border-slate-300 text-primary-600 focus:ring-primary-500">
                        Habilitar notificacoes por e-mail
                    </label>
                    <div>
                        <x-input-label for="email_remetente" value="E-mail remetente" />
                        <input id="email_remetente" wire:model.defer="email_remetente" type="email" class="form-control mt-1">
                    </div>
                    <div>
                        <x-input-label for="aviso_global" value="Aviso global" />
                        <textarea id="aviso_global" wire:model.defer="aviso_global" rows="4" class="form-control mt-1" placeholder="Mensagem operacional para exibicao futura no portal..."></textarea>
                    </div>
                </div>
            @elseif ($aba === 'auditoria')
                <div>
                    <h2 class="text-lg font-bold text-slate-950 dark:text-white">Auditoria</h2>
                    <p class="mt-1 text-sm text-slate-600 dark:text-slate-400">Politicas de rastreabilidade e retencao de logs.</p>
                </div>

                <div class="mt-5 grid gap-4 md:grid-cols-2">
                    <div>
                        <x-input-label for="retencao_auditoria_dias" value="Retencao dos logs (dias)" />
                        <input id="retencao_auditoria_dias" wire:model.defer="retencao_auditoria_dias" type="number" class="form-control mt-1">
                    </div>
                    <label class="flex items-center gap-3 rounded-lg border border-slate-200 p-4 text-sm font-semibold text-slate-700 dark:border-slate-800 dark:text-slate-200">
                        <input wire:model.defer="auditoria_logins" type="checkbox" class="rounded border-slate-300 text-primary-600 focus:ring-primary-500">
                        Auditar login e logout
                    </label>
                    <label class="flex items-center gap-3 rounded-lg border border-slate-200 p-4 text-sm font-semibold text-slate-700 dark:border-slate-800 dark:text-slate-200">
                        <input wire:model.defer="auditoria_wiki" type="checkbox" class="rounded border-slate-300 text-primary-600 focus:ring-primary-500">
                        Auditar eventos importantes da Wiki
                    </label>
                </div>
            @endif

            <div class="mt-6 flex justify-end gap-3 border-t border-slate-200 pt-5 dark:border-slate-800">
                <button type="button" wire:click="restaurarPadrao" class="btn-secondary">Restaurar padrao</button>
                <button type="submit" class="btn-primary">Salvar configuracoes</button>
            </div>
        </form>
    </section>
</div>
