<?php $__env->startSection("title", env("APP_NAME") . " :: " . __("Lista de Repositórios")); ?>
<?php $__env->startSection('content'); ?>

    <div class="card shadow-sm">

        <?php $headLine = "<i class='fa-solid fa-box-archive'></i> " . __("Lista de Arquivos no Repositório"); ?>

        <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
            'headLine' => $headLine,
            'routeAdd' => 'admin.repositorio.create',
            'routeAddParams' => [],
            'nameAdd' => __('Novo Arquivo'),
            "permission" => "GERENCIADOR_DO_REPOSITORIO_DO_PORTAL",
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card-body">
            <?php echo $__env->make("errors.messageFlash", array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

            <?php
                $permissaoDetalhes = auth()->user()->getPermissaoDetalhes('GERENCIADOR_DO_REPOSITORIO_DO_PORTAL');
                $canEdit = $permissaoDetalhes['editar'] ?? false;
                $canDelete = $permissaoDetalhes['excluir'] ?? false;
            ?>

            <?php if (isset($component)) { $__componentOriginal0650541a119648223455610148c86d0b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal0650541a119648223455610148c86d0b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.tables._table','data' => ['thead' => [
                __('Arquivo'),
                __('Data de Publicação'),
                __('Título'),
                __('Sumário'),
                __('URL'),
                __('Status'),
            ],'pagination' => $repositories->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([
                __('Arquivo'),
                __('Data de Publicação'),
                __('Título'),
                __('Sumário'),
                __('URL'),
                __('Status'),
            ]),'pagination' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($repositories->links())]); ?>
                 <?php $__env->slot('body', null, []); ?> 
                    <?php $index = 0; ?>
                    <?php $__empty_1 = true; $__currentLoopData = $repositories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $repository): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <?php
                                    $extensoesImagem = ['jpg', 'jpeg', 'png', 'gif'];
                                    $extensao = pathinfo($repository->url, PATHINFO_EXTENSION);
                                ?>
                                <?php if(in_array(strtolower($extensao), $extensoesImagem)): ?>
                                    <?php echo $__env->make('components.tables._openPhoto', [
                                        'asset' => $repository->url,
                                        'index' => $index,
                                        'alt' => $repository->title,
                                        'title' => $repository->title,
                                        'text' => __('Visualizar arquivo'),
                                        'style' => 'width: 90px;'
                                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                <?php else: ?>
                                    <a href="<?php echo e(asset($repository->url)); ?>" class="text-primary" target="_blank" download>
                                        <i class="fa-solid fa-download"></i> <?php echo e(__('Baixar arquivo')); ?>

                                    </a>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php echo e(date("d/m/Y", strtotime($repository->created_at))); ?>

                            </td>
                            <td>
                                <?php echo e($repository->title); ?><br>
                                <?php if($canEdit): ?>
                                    <a class="text-warning text-decoration-none p-1 d-inline fs-5"
                                        href='<?php echo e(route("admin.repositorio.edit", $repository->id)); ?>'
                                        title="<?php echo e(__('Editar')); ?>">
                                        <span class="material-symbols-outlined" data-bs-toggle="tooltip" data-bs-placement="top"
                                            title="<?php echo e(__('Editar')); ?>">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </span>
                                    </a>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                                <?php if($canDelete): ?>
                                    <form class="del d-inline" action="<?php echo e(route("admin.repositorio.destroy", $repository->id)); ?>"
                                        method="post" onsubmit="return confirmDelete(this)">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('delete'); ?>
                                        <input type="hidden" name="page" value="<?php echo e(request()->input('page', 1)); ?>">
                                        <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 class="text-danger text-decoration-none border-0 bg-transparent fs-5" type="submit"
                                            title="<?php echo e(__('Excluir')); ?>">
                                            <span class="material-symbols-outlined" data-bs-toggle="tooltip" data-bs-placement="top"
                                                title="<?php echo e(__('Excluir')); ?>">
                                                <i class="fa-solid fa-trash"></i>
                                            </span>
                                        </button>
                                    </form>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td><?php echo e($repository->summary ?? '-'); ?></td>
                            <td>
                                <?php
                                    $fileUrl = asset($repository->url);
                                    $urlDisplay = strlen($fileUrl) > 40 ? substr($fileUrl, 0, 40) . '...' : $fileUrl;
                                ?>
                                <div class="d-flex align-items-center gap-2 flex-wrap">
                                    <a class="text-primary text-decoration-none"
                                       href="<?php echo e($fileUrl); ?>"
                                       target="_blank"
                                       title="<?php echo e(__('Abrir arquivo em nova aba')); ?>"
                                       rel="noopener noreferrer"
                                       data-bs-toggle="tooltip">
                                        <i class="fa-solid fa-external-link-alt"></i>
                                    </a>
                                    <a class="text-dark text-decoration-none d-inline fs-5 copy-url-btn"
                                       href="javascript:void(0);"
                                       onclick="copyRepositorioUrl('<?php echo e($fileUrl); ?>', this)"
                                       title="<?php echo e(__('Copiar URL do arquivo')); ?>"
                                       data-url="<?php echo e($fileUrl); ?>"
                                       data-bs-toggle="tooltip"
                                       style="cursor: pointer;">
                                        <i class="fa-solid fa-copy"></i>
                                    </a>
                                    <small class="text-muted" style="font-size: 0.7rem; word-break: break-all;">
                                        <span class="url-preview" title="<?php echo e($fileUrl); ?>" data-bs-toggle="tooltip"><?php echo e($urlDisplay); ?></span>
                                    </small>
                                </div>
                            </td>
                            <td>
                                <?php if($canEdit): ?>
                                    <form id="<?php echo e("checkStatus_" . $index); ?>"
                                        action="<?php echo e(route("admin.repositorio.status", $repository->id)); ?>" method="post">
                                        <?php echo csrf_field(); ?>
                                        <?php if($repository->status == "ATIVADO"): ?>
                                            <div class="form-check form-switch">
                                                <input type="hidden" name="checkStatus" value="DESATIVADO">
                                                <input class="form-check-input" type="checkbox" checked
                                                    onclick="javascript:$('#<?php echo e("checkStatus_" . $index); ?>').submit()">
                                            </div>
                                        <?php else: ?>
                                            <div class="form-check form-switch">
                                                <input type="hidden" name="checkStatus" value="ATIVADO">
                                                <input class="form-check-input" type="checkbox"
                                                    onclick="javascript:$('#<?php echo e("checkStatus_" . $index); ?>').submit()">
                                            </div>
                                        <?php endif; ?>
                                    </form>
                                <?php else: ?>
                                    <span class="badge <?php echo e($repository->status === 'ATIVADO' ? 'bg-success' : 'bg-secondary'); ?>">
                                        <?php echo e(__($repository->status === 'ATIVADO' ? 'Ativado' : 'Desativado')); ?>

                                    </span>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php $index++; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="6">
                                <p><?php echo e(__('Nenhum arquivo encontrado.')); ?></p>
                            </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('scripts'); ?>
        <script src="<?php echo e(asset('pmar/js/repositorio.js')); ?>"></script>
        <script>
            // Inicializa tooltips do Bootstrap
            document.addEventListener('DOMContentLoaded', function() {
                var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
                var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
                    return new bootstrap.Tooltip(tooltipTriggerEl);
                });

                // Exibe mensagem de sucesso vinda do sessionStorage
                var successMessage = sessionStorage.getItem('success_message');
                if (successMessage) {
                    // Remove a mensagem do sessionStorage
                    sessionStorage.removeItem('success_message');
                    
                    // Cria e exibe o alerta de sucesso
                    var alertDiv = document.createElement('div');
                    alertDiv.className = 'alert alert-success alert-dismissible fade show';
                    alertDiv.setAttribute('role', 'alert');
                    alertDiv.innerHTML = successMessage + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
                    
                    // Insere o alerta após o include do messageFlash
                    var cardBody = document.querySelector('.card-body');
                    var messageFlashContainer = cardBody.querySelector('.alert');
                    if (messageFlashContainer) {
                        messageFlashContainer.parentNode.insertBefore(alertDiv, messageFlashContainer.nextSibling);
                    } else {
                        cardBody.insertBefore(alertDiv, cardBody.firstChild);
                    }
                }
            });
        </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/repositorio/index.blade.php ENDPATH**/ ?>