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

<?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-folder-open'></i> " . __('Arquivos do Contrato'); ?>
        <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __($headLine),
            'routeBack' => 'admin.contratos.index',
            'routeBackParams' => request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']),
            'nameBack' => __('Voltar'),
            'permission' => 'GERENCIADOR_DE_CONTRATOS',
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card-body">
            <form method="post" action="<?php echo e(route('admin.contratos.arquivos.store', [$contrato->id_contrato] + request()->only(['q', 'ano', 'con_modalidade', 'con_status', 'page']))); ?>" enctype="multipart/form-data" class="mb-4">
                <?php echo csrf_field(); ?>
                <?php $__currentLoopData = ['q', 'ano', 'con_modalidade', 'con_status', 'page']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filterKey): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php if(request()->filled($filterKey)): ?>
                        <input type="hidden" name="<?php echo e($filterKey); ?>" value="<?php echo e(request($filterKey)); ?>">
                    <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <div class="row g-2 align-items-end">
                    <div class="col-md-4">
                        <label class="form-label"><?php echo e(__('Arquivo')); ?></label>
                        <input type="file" name="arquivo" class="form-control" required>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label"><?php echo e(__('Número')); ?></label>
                        <input type="text" name="arq_numero" maxlength="50" class="form-control">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label"><?php echo e(__('Título')); ?></label>
                        <input type="text" name="arq_titulo" maxlength="200" class="form-control">
                    </div>
                    <div class="col-md-1">
                        <label class="form-label"><?php echo e(__('Início')); ?></label>
                        <input type="text" name="arq_dataini" maxlength="10" class="form-control" data-mask-date placeholder="<?php echo e(__('dd/mm/aaaa')); ?>">
                    </div>
                    <div class="col-md-1">
                        <label class="form-label"><?php echo e(__('Fim')); ?></label>
                        <input type="text" name="arq_datafim" maxlength="10" class="form-control" data-mask-date placeholder="<?php echo e(__('dd/mm/aaaa')); ?>">
                    </div>
                    <div class="col-md-1">
                        <button class="btn btn-success w-100" type="submit"><?php echo e(__('Adicionar')); ?></button>
                    </div>
                </div>
            </form>

            <?php if (isset($component)) { $__componentOriginal0650541a119648223455610148c86d0b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal0650541a119648223455610148c86d0b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.tables._table','data' => ['thead' => ['#', __('Título'), __('Número'), __('Arquivo'), __('Vigência'), __('Ações')]]] + (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(['#', __('Título'), __('Número'), __('Arquivo'), __('Vigência'), __('Ações')])]); ?>
                 <?php $__env->slot('body', null, []); ?> 
                    <?php $index = 1; ?>
                    <?php $__empty_1 = true; $__currentLoopData = $contrato->arquivos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $arquivo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($index); ?></td>
                            <td><?php echo e($arquivo->arq_titulo ?: '-'); ?></td>
                            <td><?php echo e($arquivo->arq_numero ?: '-'); ?></td>
                            <td>
                                <?php if($arquivo->arq_arquivo): ?>
                                    <a href="<?php echo e($arquivo->arquivo_url); ?>" target="_blank"><?php echo e(basename($arquivo->arq_arquivo)); ?></a>
                                <?php else: ?>
                                    -
                                <?php endif; ?>
                            </td>
                            <td><?php echo e(($arquivo->arq_dataini ?: '-') . ' - ' . ($arquivo->arq_datafim ?: '-')); ?></td>
                            <td class="text-center">
                                <div class="d-flex justify-content-center gap-1">
                                    <button type="button"
                                            class="btn btn-sm btn-warning"
                                            data-bs-toggle="modal"
                                            data-bs-target="#modal-editar-arquivo"
                                            data-action="<?php echo e(route('admin.contratos.arquivos.update', [$contrato->id_contrato, $arquivo->id_arquivo])); ?>"
                                            data-titulo="<?php echo e($arquivo->arq_titulo); ?>"
                                            data-numero="<?php echo e($arquivo->arq_numero); ?>"
                                            data-dataini="<?php echo e($arquivo->arq_dataini); ?>"
                                            data-datafim="<?php echo e($arquivo->arq_datafim); ?>"
                                            data-filename="<?php echo e(basename((string) $arquivo->arq_arquivo)); ?>"
                                            title="<?php echo e(__('Editar')); ?>"
                                            aria-label="<?php echo e(__('Editar arquivo')); ?>">
                                        <i class="fa-solid fa-pen-to-square"></i>
                                    </button>
                                    <form class="d-inline" action="<?php echo e(route('admin.contratos.arquivos.destroy', [$contrato->id_contrato, $arquivo->id_arquivo])); ?>" method="post" onsubmit="return confirmDelete(this)">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('delete'); ?>
                                        <?php $__currentLoopData = ['q', 'ano', 'con_modalidade', 'con_status', 'page']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filterKey): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php if(request()->filled($filterKey)): ?>
                                                <input type="hidden" name="<?php echo e($filterKey); ?>" value="<?php echo e(request($filterKey)); ?>">
                                            <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <input type="hidden" name="confirm" value="<?php echo e(__('* Este arquivo 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')); ?>" aria-label="<?php echo e(__('Excluir arquivo')); ?>">
                                            <i class="fa-solid fa-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                        <?php $index++; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="6" class="text-center"><?php echo e(__('Nenhum arquivo vinculado.')); ?></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>

    <!-- Modal: Editar Arquivo -->
    <div class="modal fade" id="modal-editar-arquivo" tabindex="-1"
         aria-labelledby="modal-editar-arquivo-label" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modal-editar-arquivo-label">
                        <i class="fa-solid fa-pen-to-square me-2"></i><?php echo e(__('Editar Arquivo')); ?>

                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<?php echo e(__('Fechar')); ?>"></button>
                </div>
                <form id="edit-arq-form" method="post" enctype="multipart/form-data" action="#">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PUT'); ?>
                    <?php $__currentLoopData = ['q', 'ano', 'con_modalidade', 'con_status', 'page']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filterKey): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if(request()->filled($filterKey)): ?>
                            <input type="hidden" name="<?php echo e($filterKey); ?>" value="<?php echo e(request($filterKey)); ?>">
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <div class="modal-body">
                        <div class="row g-3">
                            <div class="col-md-8">
                                <label class="form-label fw-semibold" for="edit-arq-titulo"><?php echo e(__('Título')); ?></label>
                                <input type="text" id="edit-arq-titulo" name="arq_titulo"
                                       maxlength="200" class="form-control">
                            </div>
                            <div class="col-md-4">
                                <label class="form-label fw-semibold" for="edit-arq-numero"><?php echo e(__('Número')); ?></label>
                                <input type="text" id="edit-arq-numero" name="arq_numero"
                                       maxlength="50" class="form-control">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold" for="edit-arq-dataini"><?php echo e(__('Data de Início')); ?></label>
                                <input type="text" id="edit-arq-dataini" name="arq_dataini"
                                       maxlength="10" class="form-control" data-mask-date
                                       placeholder="<?php echo e(__('dd/mm/aaaa')); ?>">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold" for="edit-arq-datafim"><?php echo e(__('Data de Fim')); ?></label>
                                <input type="text" id="edit-arq-datafim" name="arq_datafim"
                                       maxlength="10" class="form-control" data-mask-date
                                       placeholder="<?php echo e(__('dd/mm/aaaa')); ?>">
                            </div>
                            <div class="col-12">
                                <label class="form-label fw-semibold" for="edit-arq-file"><?php echo e(__('Substituir arquivo')); ?> <span class="text-muted fw-normal">(<?php echo e(__('opcional')); ?>)</span></label>
                                <input type="file" id="edit-arq-file" name="arquivo" class="form-control">
                                <div class="form-text mt-1">
                                    <i class="fa-solid fa-file me-1 text-secondary"></i>
                                    <?php echo e(__('Arquivo atual:')); ?>

                                    <span id="edit-arq-filename" class="fw-semibold text-body"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer modal-footer-arquivos">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                            <?php echo e(__('Cancelar')); ?>

                        </button>
                        <button type="submit" class="btn btn-warning">
                            <i class="fa-solid fa-floppy-disk me-1"></i><?php echo e(__('Salvar alterações')); ?>

                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('pmar/js/admin/contratos/arquivos.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/arquivos.blade.php ENDPATH**/ ?>