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

<?php
    $filterQuery = $filterParams ?? [];
    // Query para links de aba: filtros do dashboard sem tab/paginação de outras visões.
    $tabLinkQuery = collect($filterQuery)->except(['tab', 'ap', 'arp', 'tp', 'cp', 'hp'])->all();
    // Apenas os filtros da lista de atividades, para que o Export reflita o que está filtrado.
    $exportFilterParams = collect($filterQuery)
        ->filter(fn ($value, $key) => str_starts_with((string) $key, 'f_'))
        ->all();
    $canAdd = $perm['adicionar'] && ! $readOnly;
    $canEdit = $perm['editar'] && ! $readOnly;
    $canDelete = $perm['excluir'] && ! $readOnly;

    // Linhas da página atual (subatividade com recuo quando possui parent_id).
    $orderedRows = collect($tableRows)->map(fn ($row) => [
        'row' => $row,
        'depth' => empty($row['parent_id']) ? 0 : 1,
    ]);
    $showDragReorder = $canEdit && ($allowTableReorder ?? true);
    $perPageOptions = $perPageOptions ?? config('cronogramas.per_page_options', [20, 50, 100, 250, 500]);
    $currentPerPage = $currentPerPage ?? ($perPageOptions[0] ?? 20);
    $sortOptions = $sortOptions ?? ['manual' => __('Ordem manual')];
    $activitySort = $activitySort ?? 'code';
    $activityDir = $activityDir ?? 'desc';
?>

<div id="cronogramas-app"
     class="card shadow-sm border-0"
     data-project-id="<?php echo e($project->id); ?>"
     data-read-only="<?php echo e($readOnly ? '1' : '0'); ?>"
     data-can-add="<?php echo e($canAdd ? '1' : '0'); ?>"
     data-can-edit="<?php echo e($canEdit ? '1' : '0'); ?>"
     data-can-delete="<?php echo e($canDelete ? '1' : '0'); ?>"
     data-allow-reorder="<?php echo e(($showDragReorder ?? false) ? '1' : '0'); ?>"
     data-csrf="<?php echo e(csrf_token()); ?>"
     data-current-tab="<?php echo e($viewTab); ?>"
     data-url-activity-store="<?php echo e(route('admin.cronogramas.atividades.store', $project)); ?>"
     data-url-activity-update="<?php echo e(route('admin.cronogramas.atividades.update', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activity-show="<?php echo e(route('admin.cronogramas.atividades.show', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activity-inline="<?php echo e(route('admin.cronogramas.atividades.inline', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activity-reorder="<?php echo e(route('admin.cronogramas.atividades.reorder', $project)); ?>"
     data-url-activities-data="<?php echo e(route('admin.cronogramas.atividades.data', $project)); ?>"
     data-url-activity-archive="<?php echo e(route('admin.cronogramas.atividades.arquivar', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activity-restore="<?php echo e(route('admin.cronogramas.atividades.restaurar', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activity-destroy="<?php echo e(route('admin.cronogramas.atividades.destroy', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-activities-bulk-destroy="<?php echo e(route('admin.cronogramas.atividades.arquivadas.destroy', $project)); ?>"
     data-url-project-destroy="<?php echo e(route('admin.cronogramas.projetos.destroy', $project)); ?>"
     data-url-dashboard="<?php echo e(route('admin.cronogramas.dashboard', ['tab' => 'archived'])); ?>"
     data-msg-confirm-delete-project="<?php echo e(__('Tem certeza que deseja excluir? Esta ação não poderá ser desfeita.')); ?>"
     data-url-comment-store="<?php echo e(route('admin.cronogramas.comentarios.store', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-comment-destroy="<?php echo e(route('admin.cronogramas.comentarios.destroy', ['project' => $project->id, 'activity' => '__ACTIVITY__', 'comment' => '__COMMENT__'])); ?>"
     data-url-attachment-store="<?php echo e(route('admin.cronogramas.atividades.attachments', ['project' => $project->id, 'activity' => '__ACTIVITY__'])); ?>"
     data-url-attachment-destroy="<?php echo e(route('admin.cronogramas.atividades.attachments.destroy', ['project' => $project->id, 'activity' => '__ACTIVITY__', 'attachment' => '__ATTACHMENT__'])); ?>"
     data-url-attachment-download="<?php echo e(route('admin.cronogramas.atividades.attachments.download', ['project' => $project->id, 'activity' => '__ACTIVITY__', 'attachment' => '__ATTACHMENT__'])); ?>"
     data-msg-saved="<?php echo e(__('Salvo com sucesso.')); ?>"
     data-msg-error="<?php echo e(__('Não foi possível salvar. Tente novamente.')); ?>"
     data-msg-loading="<?php echo e(__('Carregando...')); ?>"
     data-msg-no-comments="<?php echo e(__('Nenhum comentário ainda.')); ?>"
     data-msg-no-attachments="<?php echo e(__('Nenhum anexo ainda.')); ?>"
     data-msg-no-history="<?php echo e(__('Sem histórico.')); ?>"
     data-msg-confirm-delete-comment="<?php echo e(__('Excluir este comentário?')); ?>"
     data-msg-confirm-delete-attachment="<?php echo e(__('Excluir este anexo?')); ?>"
     data-msg-confirm-archive-activity="<?php echo e(__('Arquivar esta atividade? Ela será movida para a aba Arquivadas.')); ?>"
     data-msg-confirm-delete-activity="<?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 atividade(s) selecionada(s)? Esta ação não poderá ser desfeita.')); ?>"
     data-label-delete-selected="<?php echo e(__('Excluir selecionadas')); ?>"
     data-label-select-all-archived="<?php echo e(__('Selecionar todas desta página')); ?>"
     data-msg-selected-one="<?php echo e(__('1 selecionada')); ?>"
     data-msg-selected-many="<?php echo e(__(':count selecionadas')); ?>"
     data-msg-confirm-restore-activity="<?php echo e(__('Restaurar esta atividade para a lista ativa?')); ?>"
     data-msg-archived="<?php echo e(__('Arquivada em')); ?>"
     data-label-archive="<?php echo e(__('Arquivar')); ?>"
     data-label-restore="<?php echo e(__('Restaurar')); ?>"
     data-msg-no-archived="<?php echo e(__('Nenhuma atividade arquivada.')); ?>"
     data-msg-no-search-results="<?php echo e(__('Nenhuma atividade encontrada.')); ?>"
     data-msg-search-count="<?php echo e(__(':visible de :total atividade(s)')); ?>"
     data-label-clear-search="<?php echo e(__('Limpar busca')); ?>"
     data-label-download="<?php echo e(__('Baixar')); ?>"
     data-label-delete="<?php echo e(__('Excluir')); ?>"
     data-label-remove="<?php echo e(__('Remover')); ?>"
     data-msg-gantt-resize-col="<?php echo e(__('Arraste para ajustar a largura da coluna')); ?>"
     data-msg-gantt-resize-row="<?php echo e(__('Arraste para ajustar a altura das linhas')); ?>">

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

    <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
        'headLine' => $headLine,
        'routeBack' => 'admin.cronogramas.dashboard',
        'routeBackParams' => $filterQuery,
        'nameBack' => __('Voltar'),
        '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-3 align-items-stretch">
            <div class="col-lg-7">
                <div class="d-flex flex-wrap align-items-center gap-2 mb-2">
                    <span class="badge <?php echo e($project->isReadOnly() ? 'bg-dark' : 'bg-primary'); ?>">
                        <?php echo e(\App\Enums\Accounts\Cronogramas\CronogramaProjectStatus::tryFrom($project->status)?->label()); ?>

                    </span>
                    <span class="small text-muted"><i class="fa-regular fa-calendar"></i> <?php echo e(__('Início')); ?>: <?php echo e($project->start_date?->format('d/m/Y') ?? '-'); ?></span>
                    <span class="small text-muted"><i class="fa-regular fa-calendar-check"></i> <?php echo e(__('Término previsto')); ?>: <?php echo e($project->planned_end_date?->format('d/m/Y') ?? '-'); ?></span>
                </div>
                <?php if($project->description): ?>
                    <p class="text-muted mb-2"><?php echo e($project->description); ?></p>
                <?php endif; ?>
                <div class="progress cr-progress-h-sm" role="progressbar" aria-label="<?php echo e(__('Progresso do projeto')); ?>" aria-valuenow="<?php echo e($project->completion_percent); ?>" aria-valuemin="0" aria-valuemax="100">
                    <div class="progress-bar bg-success cr-progress-bar-dynamic" id="cr-project-progress" style="--cr-w: <?php echo e($project->completion_percent); ?>%;"></div>
                </div>
                <small class="text-muted"><span id="cr-project-progress-label"><?php echo e($project->completion_percent); ?></span>% <?php echo e(__('concluído')); ?></small>
            </div>
            <div class="col-lg-5">
                <div class="row g-2 text-center">
                    <div class="col-4">
                        <div class="border rounded py-2 h-100">
                            <div class="fw-bold" id="cr-stat-total"><?php echo e($projectStats['total_count'] ?? 0); ?></div>
                            <div class="small text-muted"><?php echo e(__('Atividades')); ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="border rounded py-2 h-100">
                            <div class="fw-bold text-success" id="cr-stat-completed"><?php echo e($projectStats['completed_count'] ?? 0); ?></div>
                            <div class="small text-muted"><?php echo e(__('Concluídas')); ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="border rounded py-2 h-100">
                            <div class="fw-bold text-danger" id="cr-stat-overdue"><?php echo e($projectStats['overdue_count'] ?? 0); ?></div>
                            <div class="small text-muted"><?php echo e(__('Atrasadas')); ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        
        <?php
            $pdfViews = [
                'table'    => ['icon' => 'fa-table-list', 'label' => __('Tabela')],
                'gantt'    => ['icon' => 'fa-chart-gantt', 'label' => __('Gantt')],
                'timeline' => ['icon' => 'fa-timeline', 'label' => __('Linha do tempo')],
            ];
            $canEditProject = $perm['editar'] && ! $project->isReadOnly();
            $canUnarchiveProject = $perm['editar'] && $project->status === 'archived';
            $canDeleteProject = $perm['excluir'] && $project->status === 'archived';
            $hasProjectActions = $canEditProject || $canUnarchiveProject || $canDeleteProject;
        ?>
        <div class="d-flex flex-wrap align-items-center gap-2 mb-3 p-2 border rounded bg-light cr-project-toolbar"
             role="toolbar" aria-label="<?php echo e(__('Ações do projeto')); ?>">

            
            <div class="dropdown">
                <button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="<?php echo e(__('Exportar e imprimir')); ?>">
                    <i class="fa-solid fa-file-export"></i> <?php echo e(__('Exportar')); ?>

                </button>
                <ul class="dropdown-menu shadow-sm">
                    <li><h6 class="dropdown-header"><i class="fa-solid fa-eye me-1"></i> <?php echo e(__('Visualizar PDF')); ?></h6></li>
                    <?php $__currentLoopData = $pdfViews; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pdfType => $pdfView): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li>
                            <a class="dropdown-item"
                               href="<?php echo e(route('admin.cronogramas.projetos.export.pdf', array_merge(['project' => $project->id, 'type' => $pdfType], $exportFilterParams))); ?>"
                               target="_blank"
                               rel="noopener"
                               title="<?php echo e(__('Visualizar :view em PDF', ['view' => $pdfView['label']])); ?>">
                                <i class="fa-solid <?php echo e($pdfView['icon']); ?> me-2 text-muted"></i><?php echo e($pdfView['label']); ?>

                            </a>
                        </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <li><hr class="dropdown-divider"></li>
                    <li><h6 class="dropdown-header"><i class="fa-solid fa-download me-1"></i> <?php echo e(__('Baixar')); ?></h6></li>
                    <?php $__currentLoopData = $pdfViews; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pdfType => $pdfView): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li>
                            <a class="dropdown-item"
                               href="<?php echo e(route('admin.cronogramas.projetos.export.pdf', array_merge(['project' => $project->id, 'type' => $pdfType, 'download' => 1], $exportFilterParams))); ?>"
                               title="<?php echo e(__('Baixar :view em PDF', ['view' => $pdfView['label']])); ?>">
                                <i class="fa-solid fa-file-pdf me-2 text-danger"></i><?php echo e(__('PDF')); ?> - <?php echo e($pdfView['label']); ?>

                            </a>
                        </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <li>
                        <a class="dropdown-item" href="<?php echo e(route('admin.cronogramas.projetos.export.excel', $project)); ?>" title="<?php echo e(__('Exportar Excel')); ?>">
                            <i class="fa-solid fa-file-excel me-2 text-success"></i><?php echo e(__('Excel')); ?>

                        </a>
                    </li>
                </ul>
            </div>

            <?php if($project->status !== 'archived'): ?>
                <a class="btn btn-outline-info btn-sm"
                   href="<?php echo e(route('admin.cronogramas.projetos.public.open', array_merge(['project' => $project->id], $filterQuery))); ?>"
                   target="_blank"
                   rel="noopener"
                   title="<?php echo e(__('Visualização Pública')); ?>">
                    <i class="fa-solid fa-eye"></i> <?php echo e(__('Visualização Pública')); ?>

                </a>
            <?php endif; ?>

            
            <?php if($hasProjectActions): ?>
                <div class="d-flex flex-wrap align-items-center gap-2 ms-auto">
                    <?php if($canEditProject): ?>
                        <a class="btn btn-primary btn-sm" href="<?php echo e(route('admin.cronogramas.projetos.edit', array_merge(['project' => $project->id], $filterQuery))); ?>"><i class="fa-solid fa-pen"></i> <?php echo e(__('Editar projeto')); ?></a>
                        <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.arquivar', $project)); ?>" class="d-inline">
                            <?php echo csrf_field(); ?>
                            <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                            <button type="submit" class="btn btn-outline-warning btn-sm"><i class="fa-solid fa-box-archive"></i> <?php echo e(__('Arquivar')); ?></button>
                        </form>
                        <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.encerrar', $project)); ?>" class="d-inline" onsubmit="return confirm('<?php echo e(__('Encerrar o projeto? Ele ficará somente leitura.')); ?>')">
                            <?php echo csrf_field(); ?>
                            <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                            <button type="submit" class="btn btn-outline-danger btn-sm"><i class="fa-solid fa-flag-checkered"></i> <?php echo e(__('Encerrar')); ?></button>
                        </form>
                    <?php endif; ?>

                    <?php if($canUnarchiveProject): ?>
                        <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.desarquivar', $project)); ?>" class="d-inline">
                            <?php echo csrf_field(); ?>
                            <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                            <button type="submit" class="btn btn-outline-success btn-sm"><i class="fa-solid fa-box-open"></i> <?php echo e(__('Desarquivar')); ?></button>
                        </form>
                    <?php endif; ?>

                    <?php if($canDeleteProject): ?>
                        <button type="button"
                                class="btn btn-outline-danger btn-sm cr-btn-delete-project"
                                data-url="<?php echo e(route('admin.cronogramas.projetos.destroy', $project)); ?>"
                                title="<?php echo e(__('Excluir permanentemente')); ?>">
                            <i class="fa-solid fa-trash"></i> <?php echo e(__('Excluir projeto')); ?>

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

        <?php if($readOnly): ?>
            <div class="alert alert-info d-flex align-items-center gap-2" role="alert">
                <i class="fa-solid fa-lock"></i>
                <?php if($project->status === 'archived'): ?>
                    <?php echo e(__('Projeto arquivado: somente leitura. Use Desarquivar para voltar a editar.')); ?>

                <?php else: ?>
                    <?php echo e(__('Projeto encerrado: somente leitura.')); ?>

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

        <?php if($project->status !== 'archived' && ($perm['editar'] ?? false)): ?>
            <div class="card border-0 bg-light mb-3">
                <div class="card-body py-2 px-3">
                    <div class="d-flex flex-wrap align-items-center gap-2">
                        <span class="small fw-semibold text-muted">
                            <i class="fa-solid fa-link" aria-hidden="true"></i> <?php echo e(__('Link público executivo')); ?>

                        </span>
                        <?php if($project->public_share_enabled && ! empty($publicShareUrl)): ?>
                            <span class="badge bg-success"><?php echo e(__('Ativo')); ?></span>
                            <input type="text"
                                   class="form-control form-control-sm flex-grow-1"
                                   value="<?php echo e($publicShareUrl); ?>"
                                   readonly
                                   aria-label="<?php echo e(__('Link público do projeto')); ?>"
                                   id="cr-public-share-url">
                            <button type="button"
                                    class="btn btn-sm btn-outline-secondary"
                                    id="cr-btn-copy-public-url"
                                    data-url="<?php echo e($publicShareUrl); ?>"
                                    title="<?php echo e(__('Copiar link')); ?>">
                                <i class="fa-solid fa-copy"></i> <?php echo e(__('Copiar')); ?>

                            </button>
                            <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.public-share', $project)); ?>" class="d-inline">
                                <?php echo csrf_field(); ?>
                                <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                <input type="hidden" name="enabled" value="0">
                                <button type="submit" class="btn btn-sm btn-outline-warning" title="<?php echo e(__('Desativar visualização pública')); ?>">
                                    <i class="fa-solid fa-eye-slash"></i> <?php echo e(__('Desativar')); ?>

                                </button>
                            </form>
                            <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.public-share.regenerate', $project)); ?>" class="d-inline" onsubmit="return confirm('<?php echo e(__('Regenerar o link? Os links anteriores deixarão de funcionar.')); ?>')">
                                <?php echo csrf_field(); ?>
                                <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                <button type="submit" class="btn btn-sm btn-outline-danger" title="<?php echo e(__('Regenerar link público')); ?>">
                                    <i class="fa-solid fa-rotate"></i> <?php echo e(__('Regenerar link')); ?>

                                </button>
                            </form>
                        <?php else: ?>
                            <span class="badge bg-secondary"><?php echo e(__('Inativo')); ?></span>
                            <form method="post" action="<?php echo e(route('admin.cronogramas.projetos.public-share', $project)); ?>" class="d-inline">
                                <?php echo csrf_field(); ?>
                                <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                                <input type="hidden" name="enabled" value="1">
                                <button type="submit" class="btn btn-sm btn-outline-success" title="<?php echo e(__('Ativar visualização pública')); ?>">
                                    <i class="fa-solid fa-eye"></i> <?php echo e(__('Ativar link público')); ?>

                                </button>
                            </form>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        
        <ul class="nav nav-tabs cr-view-tabs mb-3" role="tablist">
            <?php
                $tabs = [
                    'table' => ['icon' => 'fa-table-list', 'label' => __('Tabela')],
                    'gantt' => ['icon' => 'fa-chart-gantt', 'label' => __('Gantt')],
                    'kanban' => ['icon' => 'fa-columns', 'label' => __('Kanban')],
                    'timeline' => ['icon' => 'fa-timeline', 'label' => __('Linha do tempo')],
                    'archived' => ['icon' => 'fa-box-archive', 'label' => __('Arquivadas'), 'badge' => $archivedCount],
                ];
            ?>
            <?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.projetos.show', array_merge($tabLinkQuery, ['project' => $project->id, '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-tab-badge"><?php echo e($tab['badge']); ?></span>
                        <?php endif; ?>
                    </a>
                </li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </ul>

        <div class="mb-3 <?php if (! (in_array($viewTab, ['gantt', 'kanban'], true))): ?> d-none <?php endif; ?>" id="cr-search-wrap">
            <label for="cr-activity-search" class="visually-hidden"><?php echo e(__('Buscar atividades')); ?></label>
            <div class="d-flex flex-wrap align-items-center gap-2">
                <div class="input-group input-group-sm cr-search-group-max">
                    <span class="input-group-text" aria-hidden="true"><i class="fa-solid fa-search"></i></span>
                    <input type="search"
                           id="cr-activity-search"
                           class="form-control"
                           placeholder="<?php echo e(__('Buscar por código, título, responsável, status...')); ?>"
                           autocomplete="off"
                           aria-label="<?php echo e(__('Buscar atividades')); ?>"
                           aria-controls="cr-activities-table cr-gantt-container cr-kanban-board cr-timeline">
                    <button type="button"
                            class="btn btn-outline-secondary d-none"
                            id="cr-search-clear"
                            title="<?php echo e(__('Limpar busca')); ?>"
                            aria-label="<?php echo e(__('Limpar busca')); ?>">
                        <i class="fa-solid fa-xmark"></i>
                    </button>
                </div>
                <small class="text-muted d-none" id="cr-search-hint" role="status" aria-live="polite"></small>
            </div>
        </div>

        <div class="tab-content">
            
            <?php if($viewTab === 'table'): ?>
                <div class="tab-pane fade show active" role="tabpanel">
                    <?php echo $__env->make('components.cronogramas.activity-filters', [
                        'project' => $project,
                        'filterParams' => $filterParams ?? [],
                        'viewTab' => 'table',
                        'pageParam' => 'ap',
                        'activityFilters' => $activityFilters ?? [],
                        'statusOptions' => $statusOptions,
                        'responsibleOptions' => $filterResponsibleOptions ?? $responsibleOptions,
                        'filtersActive' => $filtersActive ?? false,
                        'filtersCount' => $filtersCount ?? 0,
                        'selectId' => 'table',
                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-3">
                        <div>
                    <?php if($canAdd): ?>
                            <button type="button" class="btn btn-primary btn-sm" id="cr-btn-new-activity" data-bs-toggle="modal" data-bs-target="#crModalActivity">
                                <i class="fa-solid fa-plus"></i> <?php echo e(__('Nova atividade')); ?>

                            </button>
                            <?php if($showDragReorder): ?>
                                <span class="small text-muted ms-2"><?php echo e(__('Arraste pela alça para reordenar.')); ?></span>
                            <?php elseif(($activitySort ?? 'manual') !== 'manual'): ?>
                                <span class="small text-muted ms-2"><?php echo e(__('Reordenação disponível apenas na ordem manual.')); ?></span>
                            <?php elseif(isset($activitiesPaginator) && $activitiesPaginator->hasPages()): ?>
                                <span class="small text-muted ms-2"><?php echo e(__('Reordenação disponível apenas com todas as atividades em uma página.')); ?></span>
                            <?php endif; ?>
                    <?php endif; ?>
                        </div>
                        <div class="d-flex flex-wrap align-items-center gap-3">
                            <?php echo $__env->make('components.cronogramas.sort-selector', [
                                'project' => $project,
                                'filterParams' => $filterParams ?? [],
                                'viewTab' => 'table',
                                'pageParam' => 'ap',
                                'sortOptions' => $sortOptions,
                                'currentSort' => $activitySort ?? 'code',
                                'currentDir' => $activityDir ?? 'desc',
                                'selectId' => 'cr_sort_table',
                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                            <?php echo $__env->make('components.cronogramas.per-page-selector', [
                                'project' => $project,
                                'filterParams' => $filterParams ?? [],
                                'viewTab' => 'table',
                                'pageParam' => 'ap',
                                'perPageOptions' => $perPageOptions,
                                'currentPerPage' => $currentPerPage,
                                'selectId' => 'cr_per_page_table',
                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        </div>
                    </div>

                    <?php if($orderedRows->isEmpty()): ?>
                        <div class="text-center text-muted py-5 border rounded">
                            <i class="fa-solid fa-list-check fa-2x mb-2 d-block"></i>
                            <?php if($filtersActive ?? false): ?>
                                <?php echo e(__('Nenhuma atividade encontrada com os filtros aplicados.')); ?>

                            <?php else: ?>
                                <?php echo e(__('Nenhuma atividade cadastrada.')); ?>

                            <?php endif; ?>
                        </div>
                    <?php elseif(($activitySort ?? 'manual') === 'chronological'): ?>
                        <?php echo $__env->make('components.cronogramas.timeline', ['rows' => $tableRows, 'dir' => $activityDir ?? 'asc'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        <?php if(isset($activitiesPaginator) && $activitiesPaginator->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 atividade(s)', [
                                        'from' => $activitiesPaginator->firstItem(),
                                        'to' => $activitiesPaginator->lastItem(),
                                        'total' => $activitiesPaginator->total(),
                                    ])); ?>

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

                                    </div>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                    <?php else: ?>
                        <div class="table-responsive">
                            <table class="table table-sm table-hover align-middle cr-table" id="cr-activities-table">
                                <thead class="table-light">
                                    <tr>
                                        <?php if($showDragReorder): ?><th scope="col" class="cr-table-drag-col"></th><?php endif; ?>
                                        <th scope="col"><?php echo e(__('Item')); ?></th>
                                        <th scope="col"><?php echo e(__('Atividades')); ?></th>
                                        <th scope="col"><?php echo e(__('Predecessora')); ?></th>
                                        <th scope="col" class="cr-col-progress"><?php echo e(__('%')); ?></th>
                                        <th scope="col" class="cr-col-status"><?php echo e(__('Status')); ?></th>
                                        <th scope="col"><?php echo e(__('Responsável')); ?></th>
                                        <th scope="col"><?php echo e(__('Início')); ?></th>
                                        <th scope="col"><?php echo e(__('Término')); ?></th>
                                        <th scope="col"><?php echo e(__('Descrição')); ?></th>
                                        <th scope="col"><?php echo e(__('Observação')); ?></th>
                                        <th scope="col" class="cr-table-actions"><?php echo e(__('Ações')); ?></th>
                                    </tr>
                                </thead>
                                <tbody id="cr-activities-tbody">
                                    <?php $__currentLoopData = $orderedRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php $row = $item['row']; $depth = $item['depth']; ?>
                                        <tr data-activity-id="<?php echo e($row['id']); ?>" <?php if($row['is_overdue']): ?> class="table-danger" <?php endif; ?>>
                                            <?php if($showDragReorder): ?>
                                                <td class="cr-drag-handle text-muted" title="<?php echo e(__('Reordenar')); ?>" aria-label="<?php echo e(__('Reordenar')); ?>">
                                                    <i class="fa-solid fa-grip-vertical"></i>
                                                </td>
                                            <?php endif; ?>
                                            <td class="text-nowrap"><code><?php echo e($row['code']); ?></code></td>
                                            <td>
                                                <span class="<?php if($depth > 0): ?> cr-depth-1 <?php endif; ?>">
                                                    <?php if($depth > 0): ?><i class="fa-solid fa-turn-up fa-rotate-90 text-muted me-1 small"></i><?php endif; ?>
                                                    <?php echo e($row['title']); ?>

                                                </span>
                                            </td>
                                            <td class="small text-muted"><?php echo e($row['predecessors'] ?: '-'); ?></td>
                                            <td>
                                                <div class="d-flex align-items-center gap-2 cr-row-progress-wrap">
                                                    <div class="progress flex-grow-1 cr-row-progress" role="progressbar" aria-label="<?php echo e(__('Progresso (%)')); ?>" aria-valuenow="<?php echo e((int) $row['completion_percent']); ?>" aria-valuemin="0" aria-valuemax="100">
                                                        <div class="progress-bar cr-progress-bar-dynamic" style="--cr-w: <?php echo e($row['completion_percent']); ?>%;"></div>
                                                    </div>
                                                    <small class="text-muted text-nowrap cr-row-progress-label"><?php echo e((int) $row['completion_percent']); ?>%</small>
                                                </div>
                                            </td>
                                            <td>
                                                <?php if($canEdit): ?>
                                                    <select class="form-select form-select-sm cr-inline-status" data-field="status" aria-label="<?php echo e(__('Status da atividade')); ?>">
                                                        <?php $__currentLoopData = $statusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($st->value); ?>" <?php if($row['status'] === $st->value): echo 'selected'; endif; ?>><?php echo e($st->label()); ?></option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                <?php else: ?>
                                                    <span class="badge bg-secondary cr-status-badge"><?php echo e($row['status_label']); ?></span>
                                                <?php endif; ?>
                                                <span class="badge bg-danger mt-1 cr-status-overdue-badge <?php if (! ($row['is_overdue'])): ?> d-none <?php endif; ?>"><?php echo e(__('Atrasado')); ?></span>
                                            </td>
                                            <td class="small">
                                                <?php if (isset($component)) { $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.cronogramas.responsible-badges','data' => ['labels' => $row['responsible_labels'] ?? []]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('cronogramas.responsible-badges'); ?>
<?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(['labels' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($row['responsible_labels'] ?? [])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $attributes = $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $component = $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
                                            </td>
                                            <td class="small text-nowrap"><?php echo e($row['planned_start_date'] ? \Carbon\Carbon::parse($row['planned_start_date'])->format('d/m/Y') : '-'); ?></td>
                                            <td class="small text-nowrap"><?php echo e($row['planned_end_date'] ? \Carbon\Carbon::parse($row['planned_end_date'])->format('d/m/Y') : '-'); ?></td>
                                            <td class="small text-muted cr-col-longtext" title="<?php echo e($row['description']); ?>"><?php echo e($row['description'] ?: '-'); ?></td>
                                            <td class="small text-muted cr-col-longtext" title="<?php echo e($row['notes']); ?>"><?php echo e($row['notes'] ?: '-'); ?></td>
                                            <td class="cr-table-actions text-nowrap">
                                                <div class="cr-table-actions-inner">
                                                    <button type="button" class="btn btn-sm btn-outline-secondary cr-btn-details" data-activity-id="<?php echo e($row['id']); ?>" title="<?php echo e(__('Detalhes, comentários e anexos')); ?>">
                                                        <i class="fa-solid fa-circle-info"></i>
                                                        <span class="badge bg-secondary cr-badge-comments" data-activity-id="<?php echo e($row['id']); ?>"><?php echo e($row['comments_count'] ?: ''); ?></span>
                                                        <span class="badge bg-info cr-badge-attachments" data-activity-id="<?php echo e($row['id']); ?>"><?php echo e($row['attachments_count'] ?: ''); ?></span>
                                                    </button>
                                                    <?php if($canEdit): ?>
                                                        <button type="button" class="btn btn-sm btn-outline-primary cr-btn-edit" data-activity-id="<?php echo e($row['id']); ?>" data-bs-toggle="modal" data-bs-target="#crModalActivity" title="<?php echo e(__('Editar')); ?>">
                                                            <i class="fa-solid fa-pen"></i>
                                                        </button>
                                                    <?php endif; ?>
                                                    <?php if($canAdd): ?>
                                                        <form method="post" action="<?php echo e(route('admin.cronogramas.atividades.duplicate', [$project, $row['id']])); ?>" class="d-inline">
                                                            <?php echo csrf_field(); ?>
                                                            <button type="submit" class="btn btn-sm btn-outline-secondary" title="<?php echo e(__('Duplicar')); ?>"><i class="fa-solid fa-copy"></i></button>
                                                        </form>
                                                    <?php endif; ?>
                                                    <?php if($canEdit): ?>
                                                        <button type="button"
                                                                class="btn btn-sm btn-outline-warning cr-btn-archive"
                                                                data-activity-id="<?php echo e($row['id']); ?>"
                                                                title="<?php echo e(__('Arquivar')); ?>">
                                                            <i class="fa-solid fa-box-archive"></i>
                                                        </button>
                                                    <?php endif; ?>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                        <?php if(isset($activitiesPaginator) && $activitiesPaginator->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 atividade(s)', [
                                        'from' => $activitiesPaginator->firstItem(),
                                        'to' => $activitiesPaginator->lastItem(),
                                        'total' => $activitiesPaginator->total(),
                                    ])); ?>

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

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

            
            <?php elseif($viewTab === 'gantt'): ?>
                <div class="tab-pane fade show active" role="tabpanel">
                    <div class="d-flex flex-wrap gap-3 mb-2 align-items-center">
                        <div class="d-flex align-items-center gap-1">
                            <span class="small text-muted me-1"><?php echo e(__('Zoom')); ?>:</span>
                            <div class="btn-group btn-group-sm" role="group" aria-label="<?php echo e(__('Zoom do Gantt')); ?>">
                                <button type="button" class="btn btn-outline-secondary cr-gantt-zoom" data-zoom="day"><?php echo e(__('Dia')); ?></button>
                                <button type="button" class="btn btn-outline-secondary cr-gantt-zoom" data-zoom="week"><?php echo e(__('Semana')); ?></button>
                                <button type="button" class="btn btn-outline-secondary cr-gantt-zoom active" data-zoom="month"><?php echo e(__('Mês')); ?></button>
                            </div>
                        </div>
                        <div class="d-flex flex-wrap gap-3 align-items-center">
                            <span class="small text-muted d-flex align-items-center gap-1"><span class="cr-gantt-v2-legend-dot cr-gantt-legend-macro"></span><?php echo e(__('Atividade macro')); ?></span>
                            <span class="small text-muted d-flex align-items-center gap-1"><span class="cr-gantt-v2-legend-dot cr-gantt-legend-activity"></span><?php echo e(__('Atividade')); ?></span>
                            <span class="small text-muted d-flex align-items-center gap-1"><span class="cr-gantt-v2-legend-dot cr-gantt-legend-done"></span><?php echo e(__('Concluída')); ?></span>
                            <span class="small text-muted d-flex align-items-center gap-1"><span class="cr-gantt-v2-legend-dot cr-gantt-legend-overdue"></span><?php echo e(__('Atrasada')); ?></span>
                            <span class="small text-muted d-flex align-items-center gap-1"><span class="cr-gantt-v2-legend-today"></span><?php echo e(__('Hoje')); ?></span>
                        </div>
                    </div>
                    <div id="cr-gantt-container" class="cr-gantt-container" role="img" aria-label="<?php echo e(__('Gráfico de Gantt do projeto')); ?>"></div>
                </div>

            
            <?php elseif($viewTab === 'kanban'): ?>
                <div class="tab-pane fade show active" role="tabpanel">
                    <?php if($canEdit): ?><p class="small text-muted"><?php echo e(__('Arraste os cartões entre as colunas para alterar o status.')); ?></p><?php endif; ?>
                    <div class="cr-kanban-board" id="cr-kanban-board">
                        <?php $__currentLoopData = \App\Enums\Accounts\Cronogramas\CronogramaActivityStatus::kanbanColumns(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $col): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="cr-kanban-col">
                                <div class="card border h-100">
                                    <div class="card-header py-2 d-flex justify-content-between align-items-center">
                                        <span class="small fw-semibold"><?php echo e($col->label()); ?></span>
                                        <span class="badge bg-secondary cr-col-badge" data-col-status="<?php echo e($col->value); ?>"><?php echo e(collect($kanbanRows)->where('status', $col->value)->count()); ?></span>
                                    </div>
                                    <div class="card-body p-2 cr-kanban-column" data-status="<?php echo e($col->value); ?>" <?php if($canEdit): ?> data-droppable="1" <?php endif; ?>>
                                        <?php $__currentLoopData = $kanbanRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php if($row['status'] === $col->value): ?>
                                                <div class="card mb-2 cr-kanban-card <?php if($row['is_overdue']): ?> border-danger <?php endif; ?>"
                                                     data-activity-id="<?php echo e($row['id']); ?>"
                                                     <?php if($canEdit): ?> draggable="true" <?php endif; ?>>
                                                    <div class="card-body p-2">
                                                        <div class="small fw-semibold text-truncate" title="<?php echo e($row['title']); ?>"><code><?php echo e($row['code']); ?></code> <?php echo e($row['title']); ?></div>
                                                        <div class="progress mt-1 cr-progress-h-xs">
                                                            <div class="progress-bar cr-progress-bar-dynamic" style="--cr-w: <?php echo e($row['completion_percent']); ?>%;"></div>
                                                        </div>
                                                        <div class="small text-muted mt-1 d-flex align-items-start gap-1">
                                                            <i class="fa-regular fa-user mt-1"></i>
                                                            <?php if (isset($component)) { $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.cronogramas.responsible-badges','data' => ['labels' => $row['responsible_labels'] ?? []]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('cronogramas.responsible-badges'); ?>
<?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(['labels' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($row['responsible_labels'] ?? [])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $attributes = $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $component = $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>

            
            <?php elseif($viewTab === 'timeline'): ?>
                <div class="tab-pane fade show active" role="tabpanel">
                    <?php echo $__env->make('components.cronogramas.activity-filters', [
                        'project' => $project,
                        'filterParams' => $filterParams ?? [],
                        'viewTab' => 'timeline',
                        'pageParam' => 'tp',
                        'activityFilters' => $activityFilters ?? [],
                        'statusOptions' => $statusOptions,
                        'responsibleOptions' => $filterResponsibleOptions ?? $responsibleOptions,
                        'filtersActive' => $filtersActive ?? false,
                        'filtersCount' => $filtersCount ?? 0,
                        'selectId' => 'timeline',
                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <div class="d-flex flex-wrap justify-content-end align-items-center gap-3 mb-3">
                        <?php echo $__env->make('components.cronogramas.sort-selector', [
                            'project' => $project,
                            'filterParams' => $filterParams ?? [],
                            'viewTab' => 'timeline',
                            'pageParam' => 'tp',
                            'sortOptions' => $sortOptions,
                            'currentSort' => $activitySort ?? 'manual',
                            'currentDir' => $activityDir ?? 'asc',
                            'selectId' => 'cr_sort_timeline',
                        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        <?php echo $__env->make('components.cronogramas.per-page-selector', [
                            'project' => $project,
                            'filterParams' => $filterParams ?? [],
                            'viewTab' => 'timeline',
                            'pageParam' => 'tp',
                            'perPageOptions' => $perPageOptions,
                            'currentPerPage' => $currentPerPage,
                            'selectId' => 'cr_per_page_timeline',
                        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                    <?php if(empty($tableRows)): ?>
                        <p class="text-muted">
                            <?php if($filtersActive ?? false): ?>
                                <?php echo e(__('Nenhuma atividade encontrada com os filtros aplicados.')); ?>

                            <?php else: ?>
                                <?php echo e(__('Nenhuma atividade cadastrada.')); ?>

                            <?php endif; ?>
                        </p>
                    <?php else: ?>
                        <?php echo $__env->make('components.cronogramas.timeline', ['rows' => $tableRows], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        <?php if(isset($timelinePaginator) && $timelinePaginator->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 atividade(s)', [
                                        'from' => $timelinePaginator->firstItem(),
                                        'to' => $timelinePaginator->lastItem(),
                                        'total' => $timelinePaginator->total(),
                                    ])); ?>

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

            
            <?php elseif($viewTab === 'archived'): ?>
                <div class="tab-pane fade show active" role="tabpanel">
                    <p class="small text-muted"><?php echo e(__('Atividades arquivadas podem ser restauradas ou excluídas 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(__('Nenhuma atividade arquivada.')); ?>

                        </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"
                                        disabled>
                                    <i class="fa-solid fa-trash" aria-hidden="true"></i>
                                    <?php echo e(__('Excluir selecionadas')); ?>

                                    <span class="badge bg-danger ms-1 d-none" id="cr-archived-selected-count">0</span>
                                </button>
                                <small class="text-muted" id="cr-archived-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-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-select-all"
                                                       title="<?php echo e(__('Selecionar todas desta página')); ?>"
                                                       aria-label="<?php echo e(__('Selecionar todas desta página')); ?>">
                                            </th>
                                        <?php endif; ?>
                                        <th scope="col"><?php echo e(__('Código')); ?></th>
                                        <th scope="col"><?php echo e(__('Atividade')); ?></th>
                                        <th scope="col"><?php echo e(__('Responsável')); ?></th>
                                        <th scope="col"><?php echo e(__('Status')); ?></th>
                                        <th scope="col"><?php echo e(__('Arquivada em')); ?></th>
                                        <th scope="col" class="cr-table-actions"><?php echo e(__('Ações')); ?></th>
                                    </tr>
                                </thead>
                                <tbody id="cr-archived-tbody">
                                    <?php $__currentLoopData = $archivedRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr data-activity-id="<?php echo e($row['id']); ?>">
                                            <?php if($canDelete): ?>
                                                <td>
                                                    <input type="checkbox"
                                                           class="form-check-input cr-archived-check"
                                                           value="<?php echo e($row['id']); ?>"
                                                           aria-label="<?php echo e(__('Selecionar atividade :code', ['code' => $row['code']])); ?>">
                                                </td>
                                            <?php endif; ?>
                                            <td class="text-nowrap"><code><?php echo e($row['code']); ?></code></td>
                                            <td><?php echo e($row['title']); ?></td>
                                            <td class="small">
                                                <?php if (isset($component)) { $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.cronogramas.responsible-badges','data' => ['labels' => $row['responsible_labels'] ?? []]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('cronogramas.responsible-badges'); ?>
<?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(['labels' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($row['responsible_labels'] ?? [])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $attributes = $__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__attributesOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c)): ?>
<?php $component = $__componentOriginala0dea79f0b80f4bdbefb79367f67c23c; ?>
<?php unset($__componentOriginala0dea79f0b80f4bdbefb79367f67c23c); ?>
<?php endif; ?>
                                            </td>
                                            <td><span class="badge bg-secondary"><?php echo e($row['status_label']); ?></span></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">
                                                    <button type="button" class="btn btn-sm btn-outline-secondary cr-btn-details" data-activity-id="<?php echo e($row['id']); ?>" title="<?php echo e(__('Detalhes e histórico')); ?>">
                                                        <i class="fa-solid fa-circle-info"></i>
                                                    </button>
                                                    <?php if($canEdit): ?>
                                                        <button type="button"
                                                                class="btn btn-sm btn-outline-success cr-btn-restore"
                                                                data-activity-id="<?php echo e($row['id']); ?>"
                                                                title="<?php echo e(__('Restaurar')); ?>">
                                                            <i class="fa-solid fa-rotate-left"></i>
                                                        </button>
                                                    <?php endif; ?>
                                                    <?php if($canDelete): ?>
                                                        <button type="button"
                                                                class="btn btn-sm btn-outline-danger cr-btn-delete-archived"
                                                                data-activity-id="<?php echo e($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(isset($archivedPaginator) && $archivedPaginator->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 atividade(s) arquivada(s)', [
                                        'from' => $archivedPaginator->firstItem(),
                                        'to' => $archivedPaginator->lastItem(),
                                        'total' => $archivedPaginator->total(),
                                    ])); ?>

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


<?php if($canAdd || $canEdit): ?>
<div class="modal fade" id="crModalActivity" tabindex="-1" aria-labelledby="crModalActivityLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable">
        <div class="modal-content">
            <form id="cr-activity-form" method="post" action="<?php echo e(route('admin.cronogramas.atividades.store', $project)); ?>"
                  data-label-new="<?php echo e(__('Nova atividade')); ?>"
                  data-label-edit="<?php echo e(__('Editar atividade')); ?>">
                <?php echo csrf_field(); ?>
                <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $filterQuery], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                <input type="hidden" name="_method" id="cr-activity-method" value="POST">
                <div class="modal-header">
                    <h2 class="modal-title h5" id="crModalActivityLabel"><?php echo e(__('Nova atividade')); ?></h2>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<?php echo e(__('Fechar')); ?>"></button>
                </div>
                <div class="modal-body row g-3">
                    <div class="col-md-3">
                        <label for="cr-f-code" class="form-label"><?php echo e(__('Código')); ?></label>
                        <input type="text" name="code" id="cr-f-code" class="form-control" maxlength="32" placeholder="<?php echo e(__('Automático')); ?>">
                    </div>
                    <div class="col-md-9">
                        <label for="cr-f-title" class="form-label"><?php echo e(__('Título')); ?> <span class="text-danger">*</span></label>
                        <input type="text" name="title" id="cr-f-title" class="form-control" required maxlength="300">
                    </div>
                    <div class="col-12">
                        <label for="cr-f-description" class="form-label"><?php echo e(__('Descrição')); ?></label>
                        <textarea name="description" id="cr-f-description" class="form-control" rows="2"></textarea>
                    </div>
                    <div class="col-md-6">
                        <label for="cr-f-parent" class="form-label"><?php echo e(__('Atividade pai (subatividade de)')); ?></label>
                        <select name="parent_id" id="cr-f-parent" class="form-select">
                            <option value=""><?php echo e(__('- Nenhuma (atividade raiz) -')); ?></option>
                            <?php $__currentLoopData = $rootActivities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($r->id); ?>"><?php echo e($r->code); ?> - <?php echo e($r->title); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <span class="form-label d-block mb-1"><?php echo e(__('Responsáveis')); ?></span>
                        <div class="d-flex gap-2 mb-2 align-items-start flex-wrap cr-responsible-adder">
                            <select class="form-select form-select-sm cr-resp-type-select" id="cr-f-responsible-type" aria-label="<?php echo e(__('Tipo de responsável')); ?>">
                                <?php $__currentLoopData = \App\Enums\Accounts\Cronogramas\CronogramaResponsibleType::cases(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $respType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($respType->value); ?>"><?php echo e($respType->label()); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <div class="flex-grow-1 cr-resp-picker-wrap">
                                <select class="form-select form-select-sm cr-responsible-picker" id="cr-f-responsible-user" data-responsible-type="user" aria-label="<?php echo e(__('Pessoa responsável')); ?>">
                                    <option value=""><?php echo e(__('- Selecione uma pessoa -')); ?></option>
                                    <?php $__currentLoopData = $responsibleOptions['users']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($u->id); ?>"><?php echo e($u->firstName); ?> <?php echo e($u->lastName); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <select class="form-select form-select-sm cr-responsible-picker d-none" id="cr-f-responsible-empresa" data-responsible-type="empresa" aria-label="<?php echo e(__('Empresa responsável')); ?>" hidden>
                                    <option value=""><?php echo e(__('- Selecione uma empresa -')); ?></option>
                                    <?php $__currentLoopData = $responsibleOptions['empresas']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $empresa): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($empresa->id); ?>">
                                            <?php echo e($empresa->nomeFantasia ?: $empresa->razaoSocial); ?><?php if($empresa->cnpj): ?> (<?php echo e($empresa->cnpj); ?>)<?php endif; ?>
                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <select class="form-select form-select-sm cr-responsible-picker d-none" id="cr-f-responsible-structure" data-responsible-type="structure" aria-label="<?php echo e(__('Órgão responsável')); ?>" hidden>
                                    <option value=""><?php echo e(__('- Selecione um órgão -')); ?></option>
                                    <?php $__currentLoopData = $responsibleOptions['structures']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $structure): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($structure->id); ?>">
                                            <?php echo e($structure->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <select class="form-select form-select-sm cr-responsible-picker d-none" id="cr-f-responsible-unidade" data-responsible-type="unidade" aria-label="<?php echo e(__('Unidade organizacional responsável')); ?>" hidden>
                                    <option value=""><?php echo e(__('- Selecione uma unidade -')); ?></option>
                                    <?php $__currentLoopData = $responsibleOptions['unidades']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unidade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($unidade->id); ?>">
                                            <?php echo e($unidade->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <button type="button" class="btn btn-outline-primary btn-sm" id="cr-f-responsible-add" title="<?php echo e(__('Adicionar responsável')); ?>" aria-label="<?php echo e(__('Adicionar responsável')); ?>">
                                <i class="fa-solid fa-plus"></i>
                            </button>
                        </div>
                        <div id="cr-f-responsibles-list" class="d-flex flex-wrap gap-1" aria-live="polite"></div>
                        <div id="cr-f-responsibles-hidden"></div>
                        <small class="text-muted d-block mt-1"><?php echo e(__('Escolha o tipo e a entidade e clique em adicionar. É possível incluir vários responsáveis.')); ?></small>
                    </div>
                    <div class="col-md-6">
                        <label for="cr-f-status" class="form-label"><?php echo e(__('Status')); ?></label>
                        <select name="status" id="cr-f-status" class="form-select">
                            <?php $__currentLoopData = $statusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($st->value); ?>" <?php if($st->value === 'not_started'): echo 'selected'; endif; ?>><?php echo e($st->label()); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <small class="text-muted d-block mt-1"><?php echo e(__('O progresso (%) é definido automaticamente pelo status.')); ?></small>
                    </div>
                    <div class="col-12">
                        <label for="cr-f-pred-search" class="form-label"><?php echo e(__('Predecessoras')); ?></label>
                        <input type="text" id="cr-f-pred-search" class="form-control form-control-sm mb-2" placeholder="<?php echo e(__('Buscar por código ou título...')); ?>" autocomplete="off">
                        <div id="cr-f-pred-list" class="border rounded cr-pred-list overflow-auto">
                            <?php $__currentLoopData = $allActivitiesForSelect; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <label class="d-flex align-items-center gap-2 cr-pred-item px-2 py-1 mb-0" data-pred-text="<?php echo e(\Illuminate\Support\Str::lower($r->code . ' ' . $r->title)); ?>">
                                    <input type="checkbox" class="form-check-input m-0 cr-pred-check" name="predecessor_ids[]" value="<?php echo e($r->id); ?>" data-pred-id="<?php echo e($r->id); ?>">
                                    <span class="small"><code><?php echo e($r->code); ?></code> <?php echo e(\Illuminate\Support\Str::limit($r->title, 70)); ?></span>
                                </label>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <div class="text-muted small px-2 py-2 d-none" id="cr-f-pred-empty"><?php echo e(__('Nenhuma atividade encontrada.')); ?></div>
                        </div>
                        <small class="text-muted d-block mt-1"><span id="cr-f-pred-count">0</span> <?php echo e(__('selecionada(s)')); ?></small>
                    </div>
                    <div class="col-md-6">
                        <label for="cr-f-start" class="form-label"><?php echo e(__('Início')); ?></label>
                        <input type="date" name="planned_start_date" id="cr-f-start" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label for="cr-f-end" class="form-label"><?php echo e(__('Término')); ?></label>
                        <input type="date" name="planned_end_date" id="cr-f-end" class="form-control">
                    </div>
                    <div class="col-12">
                        <label for="cr-f-notes" class="form-label"><?php echo e(__('Observações')); ?></label>
                        <textarea name="notes" id="cr-f-notes" class="form-control" rows="2"></textarea>
                    </div>
                    <div class="col-12">
                        <span class="small text-muted" id="cr-activity-autosave" aria-live="polite"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo e(__('Cancelar')); ?></button>
                    <button type="submit" class="btn btn-primary"><?php echo e(__('Salvar atividade')); ?></button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php endif; ?>


<div class="offcanvas offcanvas-end cr-offcanvas-details" tabindex="-1" id="crOffcanvasDetails" aria-labelledby="crOffcanvasDetailsLabel">
    <div class="offcanvas-header border-bottom">
        <h2 class="offcanvas-title h5 mb-0" id="crOffcanvasDetailsLabel"><?php echo e(__('Detalhes da atividade')); ?></h2>
        <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="<?php echo e(__('Fechar')); ?>"></button>
    </div>
    <div class="offcanvas-body">
        <div id="cr-details-meta" class="mb-3"></div>

        <ul class="nav nav-pills nav-fill mb-3" role="tablist">
            <li class="nav-item"><button class="nav-link active" data-cr-pane="comments" type="button"><?php echo e(__('Comentários')); ?></button></li>
            <li class="nav-item"><button class="nav-link" data-cr-pane="attachments" type="button"><?php echo e(__('Anexos')); ?></button></li>
            <li class="nav-item"><button class="nav-link" data-cr-pane="history" type="button"><?php echo e(__('Histórico')); ?></button></li>
        </ul>

        
        <div data-cr-pane-content="comments">
            <nav id="cr-comments-pagination" class="mb-2 d-none" aria-label="<?php echo e(__('Paginação de comentários')); ?>"></nav>
            <ul class="list-group list-group-flush mb-3" id="cr-comments-list"></ul>
            <?php if($canAdd): ?>
                <form id="cr-comment-form">
                    <label for="cr-comment-input" class="form-label visually-hidden"><?php echo e(__('Comentário')); ?></label>
                    <textarea id="cr-comment-input" class="form-control mb-2" rows="3" maxlength="5000" required placeholder="<?php echo e(__('Escreva um comentário...')); ?>"></textarea>
                    <button type="submit" class="btn btn-primary btn-sm"><?php echo e(__('Comentar')); ?></button>
                </form>
            <?php endif; ?>
        </div>

        
        <div data-cr-pane-content="attachments" hidden>
            <ul class="list-group list-group-flush mb-3" id="cr-attachments-list"></ul>
            <?php if($canAdd): ?>
                <form id="cr-attachment-form">
                    <label for="cr-attachment-input" class="form-label"><?php echo e(__('Enviar arquivos')); ?></label>
                    <input type="file" id="cr-attachment-input" class="form-control mb-2" multiple>
                    <button type="submit" class="btn btn-primary btn-sm"><?php echo e(__('Enviar')); ?></button>
                    <div class="form-text"><?php echo e(__('Máx. 50 MB por arquivo.')); ?></div>
                </form>
            <?php endif; ?>
        </div>

        
        <div data-cr-pane-content="history" hidden>
            <nav id="cr-history-pagination" class="mb-2 d-none" aria-label="<?php echo e(__('Paginação do histórico')); ?>"></nav>
            <ul class="list-group list-group-flush" id="cr-history-list"></ul>
        </div>
    </div>
</div>

<script type="application/json" id="cr-table-rows"><?php echo json_encode($kanbanRows ?? [], 15, 512) ?></script>
<script type="application/json" id="cr-gantt-data"><?php echo json_encode($ganttData, 15, 512) ?></script>
<script type="application/json" id="cr-archived-rows"><?php echo json_encode($archivedRows ?? [], 15, 512) ?></script>

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

<?php $__env->startPush('after-scripts'); ?>
    <script src="<?php echo e(asset('pmar/js/cronogramas.js')); ?>?v=<?php echo e(filemtime(public_path('pmar/js/cronogramas.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/show.blade.php ENDPATH**/ ?>