<div class="htmx-indicator full-width-loader">
    <div class="indeterminate"></div>
</div>

<?php if(isset($error)): ?>
    <div class="alert alert-danger">
        <?php echo __($error); ?>

    </div>
<?php else: ?>
<div id="allTasksContainer"
     hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
     hx-trigger="<?php echo e(\Leantime\Domain\Tickets\Htmx\HtmxTicketEvents::UPDATE); ?> from:body, refresh"
     class="clear"
     hx-swap="outerHTML"
     hx-ext="json-enc"
     hx-indicator=".htmx-indicator"
>
    <!-- Filters Section -->
    <div class="clear" style="position:absolute; top:10px; right:35px;">
        <!-- Group By Selector -->
        <div class="btn-group left">
            <button class="btn btn-link btn-round-icon dropdown-toggle f-right" type="button" 
                    data-tippy-content="<?php echo __('alltasks.grouping.title'); ?>"
                    data-toggle="dropdown">
                <span class="fa-solid fa-diagram-project"></span>
            </button>
            <ul class="dropdown-menu pull-right">
                <li class="nav-header"><?php echo __("alltasks.grouping.title"); ?></li>
                <li>
                    <span class="radio">
                        <input type="radio" name="allTasksGroupBy"
                               <?php if($groupBy == "user"): ?> checked='checked' <?php endif; ?>
                               value="user" id="allTasksGroupByUser"
                               hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
                               hx-trigger="click"
                               hx-target="#allTasksContainer"
                               hx-swap="outerHTML"
                               hx-indicator=".htmx-indicator"
                               style="margin-top:4px;"
                               hx-vals='{"projectFilter": "<?php echo e($projectFilter); ?>", "userFilter": "<?php echo e($userFilter); ?>", "statusFilter": "<?php echo e($statusFilter); ?>", "groupBy": "user"}'
                        />
                        <label for="allTasksGroupByUser"><?php echo __("alltasks.grouping.by_user"); ?></label>
                    </span>
                </li>
                <li>
                    <span class="radio">
                        <input type="radio" name="allTasksGroupBy"
                               <?php if($groupBy == "project"): ?> checked='checked' <?php endif; ?>
                               value="project" id="allTasksGroupByProject"
                               hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
                               hx-trigger="click"
                               hx-target="#allTasksContainer"
                               hx-swap="outerHTML"
                               hx-indicator=".htmx-indicator"
                               style="margin-top:4px;"
                               hx-vals='{"projectFilter": "<?php echo e($projectFilter); ?>", "userFilter": "<?php echo e($userFilter); ?>", "statusFilter": "<?php echo e($statusFilter); ?>", "groupBy": "project"}'
                        />
                        <label for="allTasksGroupByProject"><?php echo __("alltasks.grouping.by_project"); ?></label>
                    </span>
                </li>
            </ul>
        </div>

        <!-- Filters Dropdown -->
        <div class="btn-group left">
            <button class="btn btn-link btn-round-icon dropdown-toggle f-right" type="button" data-toggle="dropdown">
                <i class="fas fa-filter"></i>
                <?php
                    $activeFilters = 0;
                    if ($projectFilter != '') $activeFilters++;
                    if ($userFilter != '') $activeFilters++;
                    if ($statusFilter != 'not_done') $activeFilters++;
                ?>
                <?php if($activeFilters > 0): ?>
                    <span class='badge badge-primary'><?php echo e($activeFilters); ?></span>
                <?php endif; ?>
            </button>
            <ul class="dropdown-menu pull-right" style="min-width:250px;">
                <li class="nav-header"><?php echo __("alltasks.filters.title"); ?></li>
                
                <!-- Project Filter -->
                <li style="padding: 5px 15px;" onclick="event.stopPropagation();">
                    <label><?php echo __('alltasks.filters.project'); ?></label>
                    <select name="projectFilter" 
                            class="tw-w-full"
                            hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
                            hx-trigger="change"
                            hx-target="#allTasksContainer"
                            hx-swap="outerHTML"
                            hx-indicator=".htmx-indicator"
                            hx-include="[name='userFilter'], [name='statusFilter'], [name='allTasksGroupBy']:checked">
                        <option value="" <?php echo e($projectFilter === '' ? 'selected' : ''); ?>><?php echo __("alltasks.filters.all_projects"); ?></option>
                        <?php if(isset($allProjects)): ?>
                            <?php $__currentLoopData = $allProjects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $project): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($project['id']); ?>" <?php echo e($projectFilter == $project['id'] ? 'selected' : ''); ?>>
                                    <?php echo e($project['name']); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </select>
                </li>

                <!-- User Filter -->
                <li style="padding: 5px 15px;" onclick="event.stopPropagation();">
                    <label><?php echo __('alltasks.filters.user'); ?></label>
                    <select name="userFilter"
                            class="tw-w-full"
                            hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
                            hx-trigger="change"
                            hx-target="#allTasksContainer"
                            hx-swap="outerHTML"
                            hx-indicator=".htmx-indicator"
                            hx-include="[name='projectFilter'], [name='statusFilter'], [name='allTasksGroupBy']:checked">
                        <option value="" <?php echo e($userFilter === '' ? 'selected' : ''); ?>><?php echo __("alltasks.filters.all_users"); ?></option>
                        <?php if(isset($allUsers)): ?>
                            <?php $__currentLoopData = $allUsers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($user['id']); ?>" <?php echo e($userFilter == $user['id'] ? 'selected' : ''); ?>>
                                    <?php echo e($user['firstname']); ?> <?php echo e($user['lastname']); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </select>
                </li>

                <!-- Status Filter -->
                <li style="padding: 5px 15px;" onclick="event.stopPropagation();">
                    <label><?php echo __('alltasks.filters.status'); ?></label>
                    <select name="statusFilter"
                            class="tw-w-full"
                            hx-get="<?php echo e(BASE_URL); ?>/hx/AllTasks/AllTasks/get"
                            hx-trigger="change"
                            hx-target="#allTasksContainer"
                            hx-swap="outerHTML"
                            hx-indicator=".htmx-indicator"
                            hx-include="[name='projectFilter'], [name='userFilter'], [name='allTasksGroupBy']:checked">
                        <option value="not_done" <?php echo e($statusFilter == 'not_done' ? 'selected' : ''); ?>>
                            <?php echo __('alltasks.filters.open_tasks'); ?>

                        </option>
                        <option value="" <?php echo e($statusFilter == '' ? 'selected' : ''); ?>>
                            <?php echo __('alltasks.filters.all_statuses'); ?>

                        </option>
                        <option value="done" <?php echo e($statusFilter == 'done' ? 'selected' : ''); ?>>
                            <?php echo __('alltasks.filters.completed'); ?>

                        </option>
                    </select>
                </li>
            </ul>
        </div>
    </div>

    <div class="tw-flex tw-flex-col">
        <div class="">
            <?php if(!isset($ticketsGrouped) || count($ticketsGrouped) == 0): ?>
                <div class='center'>
                    <div style='width:30%' class='svgContainer'>
                        <?php echo file_get_contents(ROOT . "/dist/images/svg/undraw_a_moment_to_relax_bbpa.svg"); ?>

                    </div>
                    <br/>
                    <h4><?php echo __("alltasks.messages.no_tasks_found"); ?></h4>
                </div>
            <?php endif; ?>

            <?php $__currentLoopData = $ticketsGrouped; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $groupId => $tickets): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    // Determine icon and group name based on groupBy
                    if ($groupBy === 'user') {
                        $icon = 'fa fa-user';
                        $groupLabel = $groupNames[$groupId] ?? 'Unknown';
                    } else {
                        $icon = 'fa fa-folder';
                        $groupLabel = $groupNames[$groupId] ?? 'Unknown';
                    }
                ?>
                
                <?php if (isset($component)) { $__componentOriginalb42738ebdee3365d3e140e48fd37e95c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb42738ebdee3365d3e140e48fd37e95c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'global::components.accordion','data' => ['id' => 'ticketBox-'.e($groupBy).'-'.e($groupId).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('global::accordion'); ?>
<?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(['id' => 'ticketBox-'.e($groupBy).'-'.e($groupId).'']); ?>
                     <?php $__env->slot('title', null, []); ?> 
                        <i class="<?php echo e($icon); ?>"></i> <?php echo e($groupLabel); ?>

                        <span class="task-count">(<?php echo e(count($tickets)); ?>)</span>
                     <?php $__env->endSlot(); ?>
                     <?php $__env->slot('content', null, []); ?> 
                        <div id="sortable-tasks-<?php echo e($groupId); ?>" class="sortable-container">
                            <?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $projectId = $ticket['projectId'];
                                    $ticketDataJson = json_encode([
                                        'id' => $ticket['id'],
                                        'title' => $ticket['headline'],
                                        'color' => 'var(--accent2)',
                                        'entityType' => 'ticket',
                                        'url' => BASE_URL.'#/tickets/showTicket/'.$ticket['id'],
                                    ]);
                                ?>
                                
                                <div class="ticketBox priority-border-<?php echo e($ticket['priority'] ?? 0); ?>" 
                                     data-val="<?php echo e($ticket['id']); ?>"
                                     data-event='<?php echo $ticketDataJson; ?>'>
                                    
                                    <div class="tw-flex tw-flex-row">
                                        <div class="tw-flex-1 ticket-title ticket-title-wrapper">
                                            <div class="title-text">
                                                <?php if($groupBy === 'user'): ?>
                                                    <small style="display:inline-block;"><?php echo e($projectNames[$projectId] ?? $ticket['projectName'] ?? 'Unknown'); ?></small> <br/>
                                                <?php endif; ?>
                                                <strong>
                                                    <a href="#/tickets/showTicket/<?php echo e($ticket['id']); ?>" preload="mouseover">
                                                        <?php echo e($ticket['headline']); ?>

                                                    </a>
                                                </strong>
                                            </div>
                                        </div>

                                        <div class="tw-content-center right">
                                            <div class="tw-flex tw-flex-row tw-gap-2 tw-items-center">
                                                <?php if($groupBy === 'project' && !empty($ticket['userFirstname'])): ?>
                                                    <div class="tw-hidden sm:tw-block profileImage">
                                                        <img src="<?php echo e(BASE_URL); ?>/api/users?profileImage=<?php echo e($ticket['editorId'] ?? $ticket['userId']); ?>" 
                                                             alt="<?php echo e($ticket['userFirstname']); ?>"
                                                             data-tippy-content="<?php echo e($ticket['userFirstname']); ?> <?php echo e($ticket['userLastname']); ?>"/>
                                                    </div>
                                                <?php endif; ?>

                                                <?php if(!empty($ticket['dateToFinish']) && $ticket['dateToFinish'] != '0000-00-00 00:00:00' && $ticket['dateToFinish'] != '1969-12-31 00:00:00'): ?>
                                                    <?php
                                                        $today = strtotime(date('Y-m-d'));
                                                        $dueDate = strtotime($ticket['dateToFinish']);
                                                        $isOverdue = $dueDate < $today;
                                                    ?>
                                                    <div class="ticket-due-date <?php echo e($isOverdue ? 'overdue' : ''); ?>">
                                                        <i class="fa fa-calendar"></i>
                                                        <?php echo e(format($ticket['dateToFinish'])->date()); ?>

                                                    </div>
                                                <?php endif; ?>

                                                <?php if(isset($statusLabels[$projectId][$ticket['status']])): ?>
                                                    <div class="dropdown ticketDropdown statusDropdown colorized">
                                                        <a class="dropdown-toggle status <?php echo e($statusLabels[$projectId][$ticket['status']]['class'] ?? 'label-default'); ?>"
                                                           href="javascript:void(0);"
                                                           role="button"
                                                           id="allTasksStatusDropdown<?php echo e($ticket['id']); ?>"
                                                           data-toggle="dropdown"
                                                           aria-haspopup="true"
                                                           aria-expanded="false">
                                                            <span class="text">
                                                                <?php echo e($statusLabels[$projectId][$ticket['status']]['name']); ?>

                                                            </span>
                                                            &nbsp;<i class="fa fa-caret-down" aria-hidden="true"></i>
                                                        </a>
                                                        <ul class="dropdown-menu pull-right"
                                                            aria-labelledby="allTasksStatusDropdown<?php echo e($ticket['id']); ?>">
                                                            <li class="nav-header border"><?php echo e(__("dropdown.choose_status")); ?></li>
                                                            <?php $__currentLoopData = $statusLabels[$projectId]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $statusKey => $statusLabel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <li class='dropdown-item'>
                                                                    <a href='javascript:void(0);'
                                                                       class='<?php echo e($statusLabel["class"]); ?>'
                                                                       data-label='<?php echo e($statusLabel["name"]); ?>'
                                                                       data-value='<?php echo e($ticket["id"]); ?>_<?php echo e($statusKey); ?>_<?php echo e($statusLabel["class"]); ?>'>
                                                                        <?php echo e($statusLabel["name"]); ?>

                                                                    </a>
                                                                </li>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </ul>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                     <?php $__env->endSlot(); ?>
                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb42738ebdee3365d3e140e48fd37e95c)): ?>
<?php $attributes = $__attributesOriginalb42738ebdee3365d3e140e48fd37e95c; ?>
<?php unset($__attributesOriginalb42738ebdee3365d3e140e48fd37e95c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb42738ebdee3365d3e140e48fd37e95c)): ?>
<?php $component = $__componentOriginalb42738ebdee3365d3e140e48fd37e95c; ?>
<?php unset($__componentOriginalb42738ebdee3365d3e140e48fd37e95c); ?>
<?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>

<script type="text/javascript">
    jQuery(document).ready(function () {
        initAllTasksWidget();
    });

    htmx.onLoad(function () {
        initAllTasksWidget();
    });

    function initAllTasksWidget() {
        // Initialize status dropdown
        leantime.ticketsController.initStatusDropdown();
    }

    // Use event delegation at document level to avoid multiple bindings
    jQuery(document).off('click.allTasksStatus').on('click.allTasksStatus', '#allTasksContainer .statusDropdown .dropdown-item a', function() {
        // Wait for the status update to complete, then reload the widget
        setTimeout(function() {
            htmx.trigger('#allTasksContainer', 'refresh');
        }, 500);
    });
</script>
<?php endif; ?>
<?php /**PATH /home/ninatech/leantime/app/Plugins/AllTasks/Templates/get.blade.php ENDPATH**/ ?>