<?php $__env->startSection('title', env('APP_NAME') . ' :: ' . __('Cronogramas')); ?>
<?php $__env->startPush('scripts'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('pmar/css/cronogramas.css')); ?>">
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>

<?php
    $listQuery = $filterParams ?? [];
    $canEdit = ($perm['editar'] ?? false);
    $canDelete = ($perm['excluir'] ?? false);
    $viewTab = $viewTab ?? 'table';
?>

<div id="cronogramas-dashboard-app"
     class="card shadow-sm border-0"
     data-csrf="<?php echo e(csrf_token()); ?>"
     data-can-edit="<?php echo e($canEdit ? '1' : '0'); ?>"
     data-can-delete="<?php echo e($canDelete ? '1' : '0'); ?>"
     data-url-projects-bulk-destroy="<?php echo e(route('admin.cronogramas.projetos.arquivados.destroy')); ?>"
     data-msg-confirm-archive-project="<?php echo e(__('Arquivar este projeto? Ele será movido para a aba Arquivados.')); ?>"
     data-msg-confirm-delete-project="<?php echo e(__('Tem certeza que deseja excluir? Esta ação não poderá ser desfeita.')); ?>"
     data-msg-confirm-bulk-delete="<?php echo e(__('Excluir permanentemente :count projeto(s) selecionado(s)? Esta ação não poderá ser desfeita.')); ?>"
     data-msg-selected-one="<?php echo e(__('1 selecionado')); ?>"
     data-msg-selected-many="<?php echo e(__(':count selecionados')); ?>"
     data-msg-saved="<?php echo e(__('Operação realizada com sucesso.')); ?>"
     data-msg-error="<?php echo e(__('Não foi possível concluir. Tente novamente.')); ?>">

    <?php $headLine = "<i class='fa-solid fa-chart-gantt'></i> " . e(__('Cronogramas')); ?>

    <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
        'headLine' => $headLine,
        'routeBack' => 'admin.dashboard',
        'routeBackParams' => [],
        'nameBack' => __('Voltar'),
        'routeAdd' => 'admin.cronogramas.projetos.create',
        'routeAddParams' => $listQuery,
        'nameAdd' => __('Novo projeto'),
        'permission' => 'GERENCIADOR_DE_CRONOGRAMAS',
    ], 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(); ?>

        <div class="row g-3 mb-4" role="region" aria-label="<?php echo e(__('Indicadores')); ?>">
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-primary bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-primary"><?php echo e($indicators['total_projects']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Total de projetos')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-info bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-info"><?php echo e($indicators['active_projects']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Em andamento')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-success bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-success"><?php echo e($indicators['completed_projects']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Concluídos')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-danger bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-danger"><?php echo e($indicators['overdue_projects']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Atrasados')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-secondary bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold"><?php echo e($indicators['avg_completion']); ?>%</div>
                        <div class="small text-muted"><?php echo e(__('Média de execução')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-warning bg-opacity-10 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-warning"><?php echo e($indicators['pending_activities']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Atividades pendentes')); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-4 col-lg-3">
                <div class="card border-0 bg-danger bg-opacity-25 h-100">
                    <div class="card-body text-center">
                        <div class="fs-4 fw-bold text-danger"><?php echo e($indicators['critical_activities']); ?></div>
                        <div class="small text-muted"><?php echo e(__('Atividades críticas')); ?></div>
                    </div>
                </div>
            </div>
        </div>

        <ul class="nav nav-tabs cr-view-tabs mb-3" role="tablist">
            <?php
                $tabs = [
                    'table' => ['icon' => 'fa-table-list', 'label' => __('Projetos')],
                    'archived' => ['icon' => 'fa-box-archive', 'label' => __('Arquivados'), 'badge' => $archivedCount ?? 0],
                ];
            ?>
            <?php $__currentLoopData = $tabs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <li class="nav-item" role="presentation">
                    <a class="nav-link <?php if($viewTab === $key): ?> active <?php endif; ?>"
                       href="<?php echo e(route('admin.cronogramas.dashboard', array_merge($listQuery, ['tab' => $key]))); ?>">
                        <i class="fa-solid <?php echo e($tab['icon']); ?>"></i> <?php echo e($tab['label']); ?>

                        <?php if(! empty($tab['badge'])): ?>
                            <span class="badge bg-secondary ms-1" id="cr-archived-projects-tab-badge"><?php echo e($tab['badge']); ?></span>
                        <?php endif; ?>
                    </a>
                </li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </ul>

        <form method="get" action="<?php echo e(route('admin.cronogramas.dashboard')); ?>" class="row g-2 mb-3" role="search">
            <input type="hidden" name="tab" value="<?php echo e($viewTab); ?>">
            <div class="col-md-3">
                <label class="form-label visually-hidden" for="flt_q"><?php echo e(__('Buscar')); ?></label>
                <input type="search" name="q" id="flt_q" class="form-control" value="<?php echo e(request('q')); ?>" placeholder="<?php echo e(__('Buscar projeto')); ?>">
            </div>
            <div class="col-md-2">
                <label class="form-label visually-hidden" for="flt_status"><?php echo e(__('Status')); ?></label>
                <select name="status" id="flt_status" class="form-select">
                    <option value=""><?php echo e(__('Todos')); ?></option>
                    <?php $__currentLoopData = \App\Enums\Accounts\Cronogramas\CronogramaProjectStatus::cases(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if($viewTab === 'table' && $st->value === 'archived'): ?>
                            <?php continue; ?>
                        <?php endif; ?>
                        <?php if($viewTab === 'archived' && $st->value !== 'archived'): ?>
                            <?php continue; ?>
                        <?php endif; ?>
                        <option value="<?php echo e($st->value); ?>" <?php if(request('status') === $st->value): echo 'selected'; endif; ?>><?php echo e($st->label()); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <input type="date" name="date_from" class="form-control" value="<?php echo e(request('date_from')); ?>" aria-label="<?php echo e(__('Data início (de)')); ?>">
            </div>
            <div class="col-md-2">
                <input type="date" name="date_to" class="form-control" value="<?php echo e(request('date_to')); ?>" aria-label="<?php echo e(__('Data fim (até)')); ?>">
            </div>
            <div class="col-md-2">
                <select name="sort" class="form-select" aria-label="<?php echo e(__('Ordenar')); ?>">
                    <option value="updated_at" <?php if(request('sort', 'updated_at') === 'updated_at'): echo 'selected'; endif; ?>><?php echo e(__('Última atualização')); ?></option>
                    <option value="name" <?php if(request('sort') === 'name'): echo 'selected'; endif; ?>><?php echo e(__('Nome')); ?></option>
                    <option value="completion_percent" <?php if(request('sort') === 'completion_percent'): echo 'selected'; endif; ?>><?php echo e(__('Progresso')); ?></option>
                    <option value="start_date" <?php if(request('sort') === 'start_date'): echo 'selected'; endif; ?>><?php echo e(__('Data início')); ?></option>
                </select>
            </div>
            <div class="col-md-1 d-flex align-items-end gap-2">
                <button type="submit" class="btn btn-primary"><?php echo e(__('Filtrar')); ?></button>
                <a class="btn btn-outline-secondary" href="<?php echo e(route('admin.cronogramas.dashboard', ['tab' => $viewTab])); ?>"><?php echo e(__('Limpar')); ?></a>
            </div>
        </form>

        <?php if($viewTab === 'table'): ?>
            <div class="table-responsive">
                <table class="table table-sm table-hover align-middle cr-table">
                    <thead>
                        <tr>
                            <th scope="col"><?php echo e(__('Projeto')); ?></th>
                            <th scope="col"><?php echo e(__('Status')); ?></th>
                            <th scope="col"><?php echo e(__('Progresso')); ?></th>
                            <th scope="col"><?php echo e(__('Início')); ?></th>
                            <th scope="col"><?php echo e(__('Término previsto')); ?></th>
                            <th scope="col"><?php echo e(__('Atividades')); ?></th>
                            <th scope="col" class="cr-table-actions"><?php echo e(__('Ações')); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $projects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $proj): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td>
                                    <a href="<?php echo e(route('admin.cronogramas.projetos.show', array_merge(['project' => $proj->id], $listQuery))); ?>">
                                        <?php echo e($proj->name); ?>

                                    </a>
                                </td>
                                <td>
                                    <span class="badge bg-secondary"><?php echo e(\App\Enums\Accounts\Cronogramas\CronogramaProjectStatus::tryFrom($proj->status)?->label()); ?></span>
                                </td>
                                <td>
                                    <div class="progress cr-table-progress">
                                        <div class="progress-bar cr-progress-bar-dynamic" role="progressbar" style="--cr-w: <?php echo e($proj->completion_percent); ?>%" aria-valuenow="<?php echo e($proj->completion_percent); ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                    </div>
                                    <small class="text-muted d-block"><?php echo e($proj->completion_percent); ?>%</small>
                                </td>
                                <td><?php echo e($proj->start_date?->format('d/m/Y') ?? '-'); ?></td>
                                <td><?php echo e($proj->planned_end_date?->format('d/m/Y') ?? '-'); ?></td>
                                <td><?php echo e($proj->activities_count); ?></td>
                                <td class="cr-table-actions text-nowrap">
                                    <div class="cr-table-actions-inner">
                                        <a class="btn btn-sm btn-outline-primary" href="<?php echo e(route('admin.cronogramas.projetos.show', array_merge(['project' => $proj->id], $listQuery))); ?>" title="<?php echo e(__('Abrir')); ?>">
                                            <i class="fa-solid fa-folder-open"></i>
                                        </a>
                                        <?php if($viewTab === 'table' && $proj->status !== 'archived'): ?>
                                            <a class="btn btn-sm btn-outline-info"
                                               href="<?php echo e(route('admin.cronogramas.projetos.public.open', array_merge(['project' => $proj->id], $listQuery))); ?>"
                                               target="_blank"
                                               rel="noopener"
                                               title="<?php echo e(__('Visualização Pública')); ?>">
                                                <i class="fa-solid fa-eye" aria-hidden="true"></i>
                                                <span class="visually-hidden"><?php echo e(__('Visualização Pública')); ?></span>
                                            </a>
                                        <?php endif; ?>
                                        <?php if($canEdit && !in_array($proj->status, ['archived', 'closed'])): ?>
                                            <a class="btn btn-sm btn-outline-secondary" href="<?php echo e(route('admin.cronogramas.projetos.edit', array_merge(['project' => $proj->id], $listQuery))); ?>" title="<?php echo e(__('Editar')); ?>">
                                                <i class="fa-solid fa-pen"></i>
                                            </a>
                                            <form method="post"
                                                  action="<?php echo e(route('admin.cronogramas.projetos.arquivar', $proj)); ?>"
                                                  class="d-inline cr-form-archive-project">
                                                <?php echo csrf_field(); ?>
                                                <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $listQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                                <button type="submit" class="btn btn-sm btn-outline-warning" title="<?php echo e(__('Arquivar')); ?>">
                                                    <i class="fa-solid fa-box-archive"></i>
                                                </button>
                                            </form>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="text-center text-muted py-4"><?php echo e(__('Nenhum projeto encontrado.')); ?></td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

            <div class="d-flex justify-content-center mt-3">
                <?php echo e($projects->links()); ?>

            </div>
        <?php else: ?>
            <p class="small text-muted"><?php echo e(__('Projetos arquivados podem ser restaurados ou excluídos permanentemente.')); ?></p>

            <?php if(empty($archivedRows)): ?>
                <div class="text-center text-muted py-5 border rounded">
                    <i class="fa-solid fa-box-archive fa-2x mb-2 d-block"></i>
                    <?php echo e(__('Nenhum projeto arquivado.')); ?>

                </div>
            <?php else: ?>
                <?php if($canDelete): ?>
                    <div class="d-flex flex-wrap align-items-center gap-2 mb-3">
                        <button type="button"
                                class="btn btn-sm btn-outline-danger"
                                id="cr-btn-bulk-delete-archived-projects"
                                disabled>
                            <i class="fa-solid fa-trash" aria-hidden="true"></i>
                            <?php echo e(__('Excluir selecionados')); ?>

                            <span class="badge bg-danger ms-1 d-none" id="cr-archived-projects-selected-count">0</span>
                        </button>
                        <small class="text-muted" id="cr-archived-projects-selection-hint" aria-live="polite"></small>
                    </div>
                <?php endif; ?>
                <div class="table-responsive">
                    <table class="table table-sm table-hover align-middle cr-table" id="cr-archived-projects-table">
                        <thead class="table-light">
                            <tr>
                                <?php if($canDelete): ?>
                                    <th scope="col" class="cr-table-check-col">
                                        <input type="checkbox"
                                               class="form-check-input"
                                               id="cr-archived-projects-select-all"
                                               title="<?php echo e(__('Selecionar todos desta página')); ?>"
                                               aria-label="<?php echo e(__('Selecionar todos desta página')); ?>">
                                    </th>
                                <?php endif; ?>
                                <th scope="col"><?php echo e(__('Projeto')); ?></th>
                                <th scope="col"><?php echo e(__('Status')); ?></th>
                                <th scope="col"><?php echo e(__('Progresso')); ?></th>
                                <th scope="col"><?php echo e(__('Início')); ?></th>
                                <th scope="col"><?php echo e(__('Término previsto')); ?></th>
                                <th scope="col"><?php echo e(__('Atividades')); ?></th>
                                <th scope="col"><?php echo e(__('Arquivado em')); ?></th>
                                <th scope="col" class="cr-table-actions"><?php echo e(__('Ações')); ?></th>
                            </tr>
                        </thead>
                        <tbody id="cr-archived-projects-tbody">
                            <?php $__currentLoopData = $archivedRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr data-project-id="<?php echo e($row['id']); ?>">
                                    <?php if($canDelete): ?>
                                        <td>
                                            <input type="checkbox"
                                                   class="form-check-input cr-archived-project-check"
                                                   value="<?php echo e($row['id']); ?>"
                                                   aria-label="<?php echo e(__('Selecionar projeto :name', ['name' => $row['name']])); ?>">
                                        </td>
                                    <?php endif; ?>
                                    <td><?php echo e($row['name']); ?></td>
                                    <td><span class="badge bg-secondary"><?php echo e($row['status_label']); ?></span></td>
                                    <td>
                                        <div class="progress cr-table-progress">
                                            <div class="progress-bar cr-progress-bar-dynamic" role="progressbar" style="--cr-w: <?php echo e($row['completion_percent']); ?>%" aria-valuenow="<?php echo e($row['completion_percent']); ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                        </div>
                                        <small class="text-muted d-block"><?php echo e($row['completion_percent']); ?>%</small>
                                    </td>
                                    <td><?php echo e($row['start_date'] ?? '-'); ?></td>
                                    <td><?php echo e($row['planned_end_date'] ?? '-'); ?></td>
                                    <td><?php echo e($row['activities_count']); ?></td>
                                    <td class="small text-nowrap text-muted"><?php echo e($row['archived_at'] ?? '-'); ?></td>
                                    <td class="cr-table-actions text-nowrap">
                                        <div class="cr-table-actions-inner">
                                            <a class="btn btn-sm btn-outline-primary"
                                               href="<?php echo e(route('admin.cronogramas.projetos.show', array_merge(['project' => $row['id']], $listQuery))); ?>"
                                               title="<?php echo e(__('Abrir')); ?>">
                                                <i class="fa-solid fa-folder-open"></i>
                                            </a>
                                            <?php if($canEdit): ?>
                                                <form method="post"
                                                      action="<?php echo e(route('admin.cronogramas.projetos.desarquivar', $row['id'])); ?>"
                                                      class="d-inline">
                                                    <?php echo csrf_field(); ?>
                                                    <?php echo $__env->make('components.cronogramas.persist-query', ['params' => array_merge($listQuery, ['tab' => 'archived'])], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                                    <button type="submit" class="btn btn-sm btn-outline-success" title="<?php echo e(__('Desarquivar')); ?>">
                                                        <i class="fa-solid fa-box-open"></i>
                                                    </button>
                                                </form>
                                            <?php endif; ?>
                                            <?php if($canDelete): ?>
                                                <button type="button"
                                                        class="btn btn-sm btn-outline-danger cr-btn-delete-archived-project"
                                                        data-project-id="<?php echo e($row['id']); ?>"
                                                        data-url="<?php echo e(route('admin.cronogramas.projetos.destroy', $row['id'])); ?>"
                                                        title="<?php echo e(__('Excluir permanentemente')); ?>">
                                                    <i class="fa-solid fa-trash"></i>
                                                </button>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
                <?php if($projects->total() > 0): ?>
                    <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mt-3">
                        <small class="text-muted">
                            <?php echo e(__('Mostrando :from-:to de :total projeto(s) arquivado(s)', [
                                'from' => $projects->firstItem(),
                                'to' => $projects->lastItem(),
                                'total' => $projects->total(),
                            ])); ?>

                        </small>
                        <?php if($projects->hasPages()): ?>
                            <div class="cr-pagination"><?php echo e($projects->links()); ?></div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>
    </div>
</div>

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

<?php $__env->startPush('after-scripts'); ?>
    <script src="<?php echo e(asset('pmar/js/cronogramas-dashboard.js')); ?>?v=<?php echo e(filemtime(public_path('pmar/js/cronogramas-dashboard.js'))); ?>"></script>
<?php $__env->stopPush(); ?>

<?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/cronogramas/dashboard.blade.php ENDPATH**/ ?>