
<?php
    $f = $activityFilters ?? [];
    $suffix = $selectId ?? $viewTab;
    $collapseId = 'cr-activity-filters-' . $suffix;

    // Parâmetros preservados como hidden: tudo, menos a aba, a página da aba e os próprios filtros.
    $hiddenParams = collect($filterParams ?? [])
        ->except(array_merge(['tab', $pageParam ?? 'ap'], app(\App\Http\Resources\Accounts\Cronogramas\CronogramasResource::class)->activityFilterKeys()))
        ->all();

    // Parâmetros para "Limpar": preserva ordenação/itens-por-página, descarta filtros e página.
    $clearParams = array_merge($hiddenParams, ['tab' => $viewTab]);
?>

<div class="mb-3">
    <div class="d-flex flex-wrap align-items-center gap-2">
        <button type="button"
                class="btn btn-outline-secondary btn-sm"
                data-bs-toggle="collapse"
                data-bs-target="#<?php echo e($collapseId); ?>"
                aria-expanded="<?php echo e($filtersActive ? 'true' : 'false'); ?>"
                aria-controls="<?php echo e($collapseId); ?>">
            <i class="fa-solid fa-filter" aria-hidden="true"></i> <?php echo e(__('Filtros')); ?>

            <?php if(($filtersCount ?? 0) > 0): ?>
                <span class="badge bg-primary ms-1"><?php echo e($filtersCount); ?></span>
            <?php endif; ?>
        </button>
        <?php if($filtersActive): ?>
            <a class="btn btn-outline-danger btn-sm"
               href="<?php echo e(route('admin.cronogramas.projetos.show', array_merge(['project' => $project->id], $clearParams))); ?>">
                <i class="fa-solid fa-xmark" aria-hidden="true"></i> <?php echo e(__('Limpar filtros')); ?>

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

    <div class="collapse mt-2 <?php if($filtersActive): ?> show <?php endif; ?>" id="<?php echo e($collapseId); ?>">
        <form method="get"
              action="<?php echo e(route('admin.cronogramas.projetos.show', $project)); ?>"
              class="card card-body border bg-light">
            <input type="hidden" name="tab" value="<?php echo e($viewTab); ?>">
            <?php echo $__env->make('components.cronogramas.persist-query', ['params' => $hiddenParams], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

            <div class="row g-3">
                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-q-<?php echo e($suffix); ?>"><?php echo e(__('Busca (todas as páginas)')); ?></label>
                    <input type="search"
                           name="f_q"
                           id="cr-f-q-<?php echo e($suffix); ?>"
                           class="form-control form-control-sm"
                           maxlength="150"
                           value="<?php echo e($f['q'] ?? ''); ?>"
                           placeholder="<?php echo e(__('Código, título, descrição ou observação')); ?>">
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-status-<?php echo e($suffix); ?>"><?php echo e(__('Status')); ?></label>
                    <select name="f_status" id="cr-f-status-<?php echo e($suffix); ?>" class="form-select form-select-sm">
                        <option value=""><?php echo e(__('Todos')); ?></option>
                        <?php $__currentLoopData = $statusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($st->value); ?>" <?php if(($f['status'] ?? null) === $st->value): echo 'selected'; endif; ?>><?php echo e($st->label()); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-overdue-<?php echo e($suffix); ?>"><?php echo e(__('Situação de prazo')); ?></label>
                    <select name="f_overdue" id="cr-f-overdue-<?php echo e($suffix); ?>" class="form-select form-select-sm">
                        <option value=""><?php echo e(__('Todas')); ?></option>
                        <option value="yes" <?php if(($f['overdue'] ?? null) === 'yes'): echo 'selected'; endif; ?>><?php echo e(__('Apenas atrasadas')); ?></option>
                        <option value="no" <?php if(($f['overdue'] ?? null) === 'no'): echo 'selected'; endif; ?>><?php echo e(__('Apenas no prazo')); ?></option>
                    </select>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-parent-<?php echo e($suffix); ?>"><?php echo e(__('Atividade pai')); ?></label>
                    <select name="f_parent" id="cr-f-parent-<?php echo e($suffix); ?>" class="form-select form-select-sm">
                        <option value=""><?php echo e(__('Todos')); ?></option>
                        <option value="yes" <?php if(($f['has_parent'] ?? null) === 'yes'): echo 'selected'; endif; ?>><?php echo e(__('Sim (subatividade)')); ?></option>
                        <option value="no" <?php if(($f['has_parent'] ?? null) === 'no'): echo 'selected'; endif; ?>><?php echo e(__('Não (atividade raiz)')); ?></option>
                    </select>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-pred-<?php echo e($suffix); ?>"><?php echo e(__('Predecessora')); ?></label>
                    <select name="f_pred" id="cr-f-pred-<?php echo e($suffix); ?>" class="form-select form-select-sm">
                        <option value=""><?php echo e(__('Todas')); ?></option>
                        <option value="yes" <?php if(($f['has_pred'] ?? null) === 'yes'): echo 'selected'; endif; ?>><?php echo e(__('Sim (possui predecessora)')); ?></option>
                        <option value="no" <?php if(($f['has_pred'] ?? null) === 'no'): echo 'selected'; endif; ?>><?php echo e(__('Não (sem predecessora)')); ?></option>
                    </select>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1" for="cr-f-resp-<?php echo e($suffix); ?>"><?php echo e(__('Responsável')); ?></label>
                    <select name="f_resp" id="cr-f-resp-<?php echo e($suffix); ?>" class="form-select form-select-sm">
                        <option value=""><?php echo e(__('Todos')); ?></option>
                        <?php if(! empty($responsibleOptions['users']) && count($responsibleOptions['users'])): ?>
                            <optgroup label="<?php echo e(__('Pessoa')); ?>">
                                <?php $__currentLoopData = $responsibleOptions['users']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="user:<?php echo e($u->id); ?>" <?php if(($f['resp_combined'] ?? null) === 'user:' . $u->id): echo 'selected'; endif; ?>><?php echo e(trim($u->firstName . ' ' . $u->lastName)); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </optgroup>
                        <?php endif; ?>
                        <?php if(! empty($responsibleOptions['empresas']) && count($responsibleOptions['empresas'])): ?>
                            <optgroup label="<?php echo e(__('Empresa')); ?>">
                                <?php $__currentLoopData = $responsibleOptions['empresas']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $empresa): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="empresa:<?php echo e($empresa->id); ?>" <?php if(($f['resp_combined'] ?? null) === 'empresa:' . $empresa->id): echo 'selected'; endif; ?>><?php echo e($empresa->nomeFantasia ?: $empresa->razaoSocial); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </optgroup>
                        <?php endif; ?>
                        <?php if(! empty($responsibleOptions['structures']) && count($responsibleOptions['structures'])): ?>
                            <optgroup label="<?php echo e(__('Órgão')); ?>">
                                <?php $__currentLoopData = $responsibleOptions['structures']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $structure): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="structure:<?php echo e($structure->id); ?>" <?php if(($f['resp_combined'] ?? null) === 'structure:' . $structure->id): echo 'selected'; endif; ?>><?php echo e($structure->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </optgroup>
                        <?php endif; ?>
                        <?php if(! empty($responsibleOptions['unidades']) && count($responsibleOptions['unidades'])): ?>
                            <optgroup label="<?php echo e(__('Unidade Organizacional')); ?>">
                                <?php $__currentLoopData = $responsibleOptions['unidades']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unidade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="unidade:<?php echo e($unidade->id); ?>" <?php if(($f['resp_combined'] ?? null) === 'unidade:' . $unidade->id): echo 'selected'; endif; ?>><?php echo e($unidade->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </optgroup>
                        <?php endif; ?>
                    </select>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1"><?php echo e(__('Início planejado')); ?></label>
                    <div class="input-group input-group-sm">
                        <span class="input-group-text"><?php echo e(__('De')); ?></span>
                        <input type="date" name="f_start_from" class="form-control" value="<?php echo e($f['start_from'] ?? ''); ?>" aria-label="<?php echo e(__('Início planejado (de)')); ?>">
                        <span class="input-group-text"><?php echo e(__('Até')); ?></span>
                        <input type="date" name="f_start_to" class="form-control" value="<?php echo e($f['start_to'] ?? ''); ?>" aria-label="<?php echo e(__('Início planejado (até)')); ?>">
                    </div>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1"><?php echo e(__('Término planejado')); ?></label>
                    <div class="input-group input-group-sm">
                        <span class="input-group-text"><?php echo e(__('De')); ?></span>
                        <input type="date" name="f_end_from" class="form-control" value="<?php echo e($f['end_from'] ?? ''); ?>" aria-label="<?php echo e(__('Término planejado (de)')); ?>">
                        <span class="input-group-text"><?php echo e(__('Até')); ?></span>
                        <input type="date" name="f_end_to" class="form-control" value="<?php echo e($f['end_to'] ?? ''); ?>" aria-label="<?php echo e(__('Término planejado (até)')); ?>">
                    </div>
                </div>

                <div class="col-md-6 col-lg-4">
                    <label class="form-label small mb-1"><?php echo e(__('Progresso (%)')); ?></label>
                    <div class="input-group input-group-sm">
                        <span class="input-group-text"><?php echo e(__('Mín')); ?></span>
                        <input type="number" name="f_prog_min" class="form-control" min="0" max="100" step="1" value="<?php echo e($f['prog_min'] ?? ''); ?>" aria-label="<?php echo e(__('Progresso mínimo')); ?>">
                        <span class="input-group-text"><?php echo e(__('Máx')); ?></span>
                        <input type="number" name="f_prog_max" class="form-control" min="0" max="100" step="1" value="<?php echo e($f['prog_max'] ?? ''); ?>" aria-label="<?php echo e(__('Progresso máximo')); ?>">
                    </div>
                </div>

                <div class="col-12 d-flex flex-wrap gap-2">
                    <button type="submit" class="btn btn-primary btn-sm">
                        <i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i> <?php echo e(__('Aplicar filtros')); ?>

                    </button>
                    <a class="btn btn-outline-secondary btn-sm"
                       href="<?php echo e(route('admin.cronogramas.projetos.show', array_merge(['project' => $project->id], $clearParams))); ?>">
                        <?php echo e(__('Limpar')); ?>

                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
<?php /**PATH /var/www/html/portal/resources/views/components/cronogramas/activity-filters.blade.php ENDPATH**/ ?>