<?php $__env->startSection('title', env('APP_NAME') . ' :: ' . __('Legislação')); ?>

<?php $__env->startPush('scripts'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('pmar/css/admin/legislacao/index.css')); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <?php echo $__env->make('errors.messageFlash', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <div class="card shadow-sm border-0">
        <?php $headLine = "<i class='fa-solid fa-scale-balanced'></i> " . __('Legislação municipal'); ?>
        <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
            'headLine'         => __($headLine),
            'routeBack'        => 'admin.dashboard',
            'routeBackParams'  => [],
            'nameBack'         => __('Voltar'),
            'routeAdd'         => 'admin.legislacao.create',
            'routeAddParams'   => $filterParams,
            'nameAdd'          => __('Nova legislação'),
            'permission'       => 'GERENCIADOR_DE_LEGISLACAO',
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card-body p-0">

            
            <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_LEGISLACAO')['visualizar']): ?>
                <div class="leg-nav-bar d-flex flex-wrap gap-2 mt-3">
                    <a href="<?php echo e(route('admin.legislacao.portarias.index')); ?>" class="btn btn-outline-primary btn-sm">
                        <i class="fa-solid fa-file-signature me-1" aria-hidden="true"></i><?php echo e(__('Portarias')); ?>

                    </a>
                    <a href="<?php echo e(route('admin.legislacao.cadastros.index', ['aba' => 'tipos'] + $filterParams)); ?>"
                        class="btn btn-outline-secondary btn-sm">
                        <i class="fa-solid fa-tags me-1" aria-hidden="true"></i><?php echo e(__('Tipos')); ?>

                    </a>
                    <a href="<?php echo e(route('admin.legislacao.cadastros.index', ['aba' => 'categorias'] + $filterParams)); ?>"
                        class="btn btn-outline-secondary btn-sm">
                        <i class="fa-solid fa-folder me-1" aria-hidden="true"></i><?php echo e(__('Categorias')); ?>

                    </a>
                    <a href="<?php echo e(route('admin.legislacao.cadastros.index', ['aba' => 'cargos'] + $filterParams)); ?>"
                        class="btn btn-outline-secondary btn-sm">
                        <i class="fa-solid fa-id-badge me-1" aria-hidden="true"></i><?php echo e(__('Cargos')); ?>

                    </a>
                    <a href="<?php echo e(route('admin.legislacao.cadastros.index', ['aba' => 'autores'] + $filterParams)); ?>"
                        class="btn btn-outline-secondary btn-sm">
                        <i class="fa-solid fa-user me-1" aria-hidden="true"></i><?php echo e(__('Autores')); ?>

                    </a>
                </div>
            <?php endif; ?>

            <div class="p-3 p-md-4">

                
                <form method="get" action="<?php echo e(route('admin.legislacao.index')); ?>" class="leg-filter-panel mb-4">
                    <?php if(request()->filled('sort_by')): ?>
                        <input type="hidden" name="sort_by" value="<?php echo e(request('sort_by')); ?>">
                    <?php endif; ?>
                    <?php if(request()->filled('sort_dir')): ?>
                        <input type="hidden" name="sort_dir" value="<?php echo e(request('sort_dir')); ?>">
                    <?php endif; ?>
                    <div class="d-flex justify-content-end mb-3">
                        <span class="badge bg-primary leg-results-badge">
                            <i class="fa-solid fa-scale-balanced me-1" aria-hidden="true"></i>
                            <?php echo e(__('Registros encontrados')); ?>:
                            <strong><?php echo e(number_format($legislacoes->total(), 0, ',', '.')); ?></strong>
                        </span>
                    </div>
                    <div class="row g-3 align-items-end">
                        <div class="col-12 col-sm-6 col-lg-2">
                            <label for="leg-filtro-ano" class="form-label">
                                <i class="fa-solid fa-calendar-days me-1 text-muted" aria-hidden="true"></i><?php echo e(__('Ano de publicação')); ?>

                            </label>
                            <select id="leg-filtro-ano" name="ano" class="form-select">
                                <option value=""><?php echo e(__('Todos')); ?></option>
                                <?php $__currentLoopData = $anos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ano): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($ano); ?>" <?php if((string) $anoSelecionado === (string) $ano): echo 'selected'; endif; ?>><?php echo e($ano); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-12 col-sm-6 col-lg-3">
                            <label for="leg-filtro-tipo" class="form-label">
                                <i class="fa-solid fa-tags me-1 text-muted" aria-hidden="true"></i><?php echo e(__('Tipo')); ?>

                            </label>
                            <select id="leg-filtro-tipo" name="tipo" class="form-select">
                                <option value=""><?php echo e(__('Todos')); ?></option>
                                <?php $__currentLoopData = $tipos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tipo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($tipo->id_tipo_legislacao); ?>"
                                        <?php if((string) ($filterParams['tipo'] ?? '') === (string) $tipo->id_tipo_legislacao): echo 'selected'; endif; ?>>
                                        <?php echo e($tipo->ds_tipo_legislacao); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-12 col-sm-6 col-lg-3">
                            <label for="leg-filtro-status" class="form-label">
                                <i class="fa-solid fa-circle-check me-1 text-muted" aria-hidden="true"></i><?php echo e(__('Status')); ?>

                            </label>
                            <select id="leg-filtro-status" name="status" class="form-select">
                                <option value=""><?php echo e(__('Todos')); ?></option>
                                <?php $__currentLoopData = $statusOpcoes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $valor => $rotulo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($valor); ?>"
                                        <?php if((string) ($filterParams['status'] ?? '') === (string) $valor): echo 'selected'; endif; ?>>
                                        <?php echo e($rotulo); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-12 col-lg-4">
                            <label for="leg-filtro-q" class="form-label">
                                <i class="fa-solid fa-magnifying-glass me-1 text-muted" aria-hidden="true"></i><?php echo e(__('Buscar')); ?>

                            </label>
                            <input id="leg-filtro-q" type="text" class="form-control" name="q"
                                value="<?php echo e($filterParams['q'] ?? ''); ?>"
                                placeholder="<?php echo e(__('Número ou ementa…')); ?>"
                                maxlength="255"
                                autocomplete="off">
                        </div>
                    </div>
                    <div class="leg-filter-actions d-flex flex-wrap justify-content-end align-items-center gap-2 mt-3">
                        <button class="btn btn-outline-success" type="submit">
                            <i class="fa-solid fa-filter me-1" aria-hidden="true"></i><?php echo e(__('Filtrar')); ?>

                        </button>
                        <a href="<?php echo e(route('admin.legislacao.index', ['ano' => '', 'tipo' => '', 'status' => '', 'q' => ''])); ?>"
                           class="btn btn-outline-secondary"><?php echo e(__('Limpar')); ?></a>
                    </div>
                </form>

                
                <div class="leg-table-section">
                <div class="row">
                    <div class="col-12">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover table-striped align-middle text-center">
                                <thead class="table-light">
                                    <tr>
                                        <th>#</th>
                                        <th>
                                            <?php echo $__env->make('components.legislacao._listagem_sort_link', [
                                                'route' => 'admin.legislacao.index',
                                                'column' => 'tipo',
                                                'label' => __('Tipo'),
                                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </th>
                                        <th>
                                            <?php echo $__env->make('components.legislacao._listagem_sort_link', [
                                                'route' => 'admin.legislacao.index',
                                                'column' => 'nr_legislacao',
                                                'label' => __('Nº'),
                                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </th>
                                        <th>
                                            <?php echo $__env->make('components.legislacao._listagem_sort_link', [
                                                'route' => 'admin.legislacao.index',
                                                'column' => 'ds_ementa',
                                                'label' => __('Ementa'),
                                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </th>
                                        <th>
                                            <?php echo $__env->make('components.legislacao._listagem_sort_link', [
                                                'route' => 'admin.legislacao.index',
                                                'column' => 'dt_publicacao',
                                                'label' => __('Publicação'),
                                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </th>
                                        <th><?php echo e(__('BO')); ?></th>
                                        <th><?php echo e(__('PDF')); ?></th>
                                        <th>
                                            <?php echo $__env->make('components.legislacao._listagem_sort_link', [
                                                'route' => 'admin.legislacao.index',
                                                'column' => 'cd_status',
                                                'label' => __('Status'),
                                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </th>
                                        <th><?php echo e(__('Ações')); ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                        <?php $index = $legislacoes->firstItem(); ?>
                        <?php $__empty_1 = true; $__currentLoopData = $legislacoes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                
                                <td class="leg-idx"><?php echo e($index); ?></td>

                                
                                <td>
                                    <?php if($item->tipo->ds_tipo_legislacao ?? false): ?>
                                        <span class="badge-tipo"><?php echo e($item->tipo->ds_tipo_legislacao); ?></span>
                                    <?php else: ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>

                                
                                <td title="<?php echo e($item->ds_ementa); ?>">
                                    <span class="leg-nr"><?php echo e($item->nr_legislacao); ?></span>
                                </td>

                                
                                <td class="leg-ementa-cell">
                                    <span class="leg-ementa d-block">
                                        <?php echo e(\Illuminate\Support\Str::limit($item->ds_ementa ?? '', 60)); ?>

                                    </span>
                                </td>

                                
                                <td class="leg-date">
                                    <?php if($item->dt_publicacao): ?>
                                        <?php echo e($item->dt_publicacao->format('d/m/Y')); ?>

                                    <?php else: ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>

                                
                                <td class="leg-bo-cell">
                                    <?php
                                        $temBoPrincipal  = (bool) $item->boletim;
                                        $temBoRetificacao = $item->retificacoes->contains(fn ($r) => (bool) $r->boletim);
                                    ?>

                                    <?php if($item->boletim): ?>
                                        <div class="mb-1">
                                            <?php echo $__env->make('components.legislacao._boletimNumeroLink', ['boletim' => $item->boletim], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                        </div>
                                    <?php endif; ?>

                                    <?php $__currentLoopData = $item->retificacoes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ret): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if($ret->boletim): ?>
                                            <div class="d-flex flex-wrap align-items-center gap-1 <?php if(! $loop->first): ?> mt-1 <?php endif; ?>">
                                                <span class="badge rounded-pill bg-warning-subtle text-dark small">
                                                    <?php echo e((int) $ret->cd_tipo === 1 ? __('Errata') : __('Republicação')); ?>

                                                </span>
                                                <?php echo $__env->make('components.legislacao._boletimNumeroLink', ['boletim' => $ret->boletim], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                            </div>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    <?php if(! $temBoPrincipal && ! $temBoRetificacao): ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>

                                
                                <td>
                                    <?php if($item->public_pdf_url): ?>
                                        <a href="<?php echo e($item->public_pdf_url); ?>" target="_blank" rel="noopener noreferrer"
                                           class="btn btn-sm btn-outline-danger">
                                            <i class="fa-solid fa-file-pdf" aria-hidden="true"></i>
                                        </a>
                                    <?php else: ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>

                                
                                <td>
                                    <?php if((int) $item->cd_status === 1): ?>
                                        <span class="badge-status badge-status-review"><?php echo e(__('Aguardando revisão')); ?></span>
                                    <?php elseif((int) $item->cd_status === 2): ?>
                                        <span class="badge-status badge-status-pending"><?php echo e(__('Pendente')); ?></span>
                                    <?php else: ?>
                                        <span class="badge-status badge-status-published"><?php echo e(__('Publicado')); ?></span>
                                    <?php endif; ?>
                                </td>

                                
                                <td>
                                    <div class="leg-actions d-flex justify-content-center gap-2">
                                        <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_LEGISLACAO')['editar']): ?>
                                            <a class="btn btn-sm btn-warning"
                                               href="<?php echo e(route('admin.legislacao.edit', [$item->id_legislacao] + $filterParams)); ?>"
                                               title="<?php echo e(__('Editar')); ?>">
                                                <i class="fa-solid fa-pen-to-square" aria-hidden="true"></i>
                                            </a>
                                        <?php endif; ?>
                                        <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_LEGISLACAO')['excluir']): ?>
                                            <form class="d-inline"
                                                  action="<?php echo e(route('admin.legislacao.destroy', $item->id_legislacao)); ?>"
                                                  method="post"
                                                  onsubmit="return confirmDelete(this)">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('delete'); ?>
                                                <?php $__currentLoopData = $filterParams; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($value !== null && $value !== ''): ?>
                                                        <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <input type="hidden" name="confirm"
                                                    value="<?php echo e(__('* Este registro será excluído e esta ação não poderá ser desfeita, deseja continuar?')); ?>">
                                                <button type="submit" class="btn btn-sm btn-danger" title="<?php echo e(__('Excluir')); ?>">
                                                    <i class="fa-solid fa-trash" aria-hidden="true"></i>
                                                </button>
                                            </form>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                            <?php $index++; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr class="leg-empty">
                                <td colspan="9" class="text-center">
                                    <i class="fa-solid fa-scale-balanced leg-empty-icon" aria-hidden="true"></i>
                                    <?php echo e(__('Nenhum registro encontrado.')); ?>

                                </td>
                            </tr>
                        <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="col-12 my-3">
                        <div class="d-flex justify-content-center">
                            <?php echo $legislacoes->links(); ?>

                        </div>
                    </div>
                </div>
                </div>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin.theme', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/portal/resources/views/admin/legislacao/index.blade.php ENDPATH**/ ?>