<?php $__env->startSection('title', env('APP_NAME') . ' :: ' . __('Contratos')); ?>

<?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">
        <?php $headLine = "<i class='fa-solid fa-file-contract'></i> " . __('Contratos'); ?>
        <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __($headLine),
            'routeBack' => 'admin.dashboard',
            'routeBackParams' => [],
            'nameBack' => __('Voltar'),
            'routeAdd' => 'admin.contratos.create',
            'routeAddParams' => request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']),
            'nameAdd' => __('Novo contrato'),
            'permission' => 'GERENCIADOR_DE_CONTRATOS',
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card-body">
            <form method="get" class="row g-3 mb-3">
                <div class="col-12 col-lg-4">
                    <label class="form-label"><?php echo e(__('Buscar')); ?></label>
                    <input type="text" class="form-control" name="q" value="<?php echo e(request('q')); ?>" placeholder="<?php echo e(__('Número, processo ou título')); ?>">
                </div>
                <div class="col-12 col-md-4 col-lg-2">
                    <label class="form-label"><?php echo e(__('Ano')); ?></label>
                    <select class="form-select" name="ano">
                        <option value=""><?php echo e(__('Todos')); ?></option>
                        <?php $__currentLoopData = $anosDisponiveis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ano): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($ano); ?>" <?php if((string) request('ano') === (string) $ano): echo 'selected'; endif; ?>><?php echo e($ano); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-12 col-md-4 col-lg-3">
                    <label class="form-label"><?php echo e(__('Modalidade')); ?></label>
                    <select class="form-select" name="con_modalidade">
                        <option value=""><?php echo e(__('Todas')); ?></option>
                        <?php $__currentLoopData = \App\Models\Contratos\Contrato::MODALIDADES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($key); ?>" <?php if((string) request('con_modalidade') === (string) $key): echo 'selected'; endif; ?>><?php echo e(__($label)); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-12 col-md-4 col-lg-3">
                    <label class="form-label"><?php echo e(__('Status')); ?></label>
                    <select class="form-select" name="con_status">
                        <option value=""><?php echo e(__('Todos')); ?></option>
                        <?php $__currentLoopData = \App\Models\Contratos\Contrato::STATUS; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($key); ?>" <?php if((string) request('con_status') === (string) $key): echo 'selected'; endif; ?>><?php echo e(__($label)); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-12 d-flex justify-content-end gap-2">
                    <a href="<?php echo e(route('admin.contratos.index')); ?>" class="btn btn-outline-secondary px-4"><?php echo e(__('Limpar filtros')); ?></a>
                    <button class="btn btn-success px-4" type="submit"><?php echo e(__('Filtrar')); ?></button>
                </div>
            </form>

            <?php
                $formatDate = static function ($date): string {
                    if (empty($date)) {
                        return '-';
                    }

                    if ($date instanceof \Carbon\CarbonInterface) {
                        return $date->format('d/m/Y');
                    }
 
                    $dateString = (string) $date;

                    if (preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $dateString)) {
                        return $dateString;
                    }

                    try {
                        return \Illuminate\Support\Carbon::parse($dateString)->format('d/m/Y');
                    } catch (\Throwable $exception) {
                        return '-';
                    }
                };
            ?>

            <?php if (isset($component)) { $__componentOriginal0650541a119648223455610148c86d0b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal0650541a119648223455610148c86d0b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.tables._table','data' => ['thead' => [__('Modalidade'), __('Número'), __('Ano'), __('Título'), __('Dt Início'), __('Dt Fim'), __('Anexos'), __('Dt Publicação'), __('Criado por'), __('Editado por'), __('Ações')],'pagination' => $registros->links()]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('tables._table'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['thead' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute([__('Modalidade'), __('Número'), __('Ano'), __('Título'), __('Dt Início'), __('Dt Fim'), __('Anexos'), __('Dt Publicação'), __('Criado por'), __('Editado por'), __('Ações')]),'pagination' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($registros->links())]); ?>
                 <?php $__env->slot('body', null, []); ?> 
                    <?php $__empty_1 = true; $__currentLoopData = $registros; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $registro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($registro->modalidade_label ?: '-'); ?></td>
                            <td><?php echo e($registro->con_numero ?: '-'); ?></td>
                            <td><?php echo e($registro->con_ano ?: '-'); ?></td>
                            <td><?php echo e($registro->con_titulo); ?></td>
                            <td><?php echo e($formatDate($registro->con_dataini)); ?></td>
                            <td><?php echo e($formatDate($registro->con_datafim)); ?></td>
                            <td><?php echo e($registro->arquivos->count()); ?></td>
                            <td><?php echo e($formatDate($registro->con_datapub)); ?></td>
                            <td class="text-center">
                                <?php if($registro->criadoPor): ?>
                                    <span data-bs-toggle="tooltip"
                                          data-bs-placement="top"
                                          data-bs-title="<?php echo e($registro->criadoPor->name); ?> - <?php echo e($registro->criadoPor->matriculation ?: __('Sem matrícula')); ?>"
                                          class="text-secondary fs-5">
                                        <i class="fa-solid fa-circle-user"></i>
                                    </span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if($registro->editadoPor): ?>
                                    <span data-bs-toggle="tooltip"
                                          data-bs-placement="top"
                                          data-bs-title="<?php echo e($registro->editadoPor->name); ?> - <?php echo e($registro->editadoPor->matriculation ?: __('Sem matrícula')); ?>"
                                          class="text-secondary fs-5">
                                        <i class="fa-solid fa-circle-user"></i>
                                    </span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="d-flex justify-content-center gap-2">
                                    <a class="btn btn-sm btn-secondary" href="<?php echo e(route('admin.contratos.show', [$registro->id_contrato] + request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']))); ?>">
                                        <i class="fa-solid fa-eye"></i>
                                    </a>
                                    <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_CONTRATOS')['editar']): ?>
                                        <a class="btn btn-sm btn-warning" href="<?php echo e(route('admin.contratos.edit', [$registro->id_contrato] + request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']))); ?>">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </a>
                                        <a class="btn btn-sm btn-primary" href="<?php echo e(route('admin.contratos.arquivos', [$registro->id_contrato] + request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']))); ?>">
                                            <i class="fa-solid fa-file-lines"></i>
                                        </a>
                                    <?php endif; ?>
                                    <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_CONTRATOS')['excluir']): ?>
                                        <form class="d-inline" action="<?php echo e(route('admin.contratos.destroy', $registro->id_contrato)); ?>" method="post" onsubmit="return confirmDelete(this)">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('delete'); ?>
                                            <?php $__currentLoopData = request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
                                            <?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">
                                                <i class="fa-solid fa-trash"></i>
                                            </button>
                                        </form>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="11" class="text-center"><?php echo e(__('Nenhum registro encontrado.')); ?></td>
                        </tr>
                    <?php endif; ?>
                 <?php $__env->endSlot(); ?>
             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal0650541a119648223455610148c86d0b)): ?>
<?php $attributes = $__attributesOriginal0650541a119648223455610148c86d0b; ?>
<?php unset($__attributesOriginal0650541a119648223455610148c86d0b); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal0650541a119648223455610148c86d0b)): ?>
<?php $component = $__componentOriginal0650541a119648223455610148c86d0b; ?>
<?php unset($__componentOriginal0650541a119648223455610148c86d0b); ?>
<?php endif; ?>
        </div>
    </div>
<?php $__env->startPush('after-scripts'); ?>
    <script src="<?php echo e(asset('pmar/js/admin/contratos/index.js')); ?>"></script>
<?php $__env->stopPush(); ?>
<?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/contratos/index.blade.php ENDPATH**/ ?>