<?= $this->extend('layouts/mobile') ?>

<?= $this->section('header') ?>
<?= view('dashboard/_filter_bar') ?>
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<?php if (! empty($filterError)): ?>
    <div class="flash flash-error" role="alert"><?= esc($filterError) ?></div>
<?php endif; ?>
<div class="quadrant-grid" data-task-lists data-status-filter="<?= esc($filters['status'] ?? 'pending') ?>" data-empty-message="<?= esc($emptyMessage ?? 'No tasks due today.') ?>">
    <?php
    $cardClasses = [
        1 => 'q-red',
        2 => 'q-green',
        3 => 'q-blue',
        4 => 'q-orange',
    ];
    $priorities   = config('Tieasy')->priorities;
    $grouped      = $grouped ?? [];
    $emptyMessage = $emptyMessage ?? 'No tasks due today.';
    $dash         = $dash ?? null;
    $filters      = $filters ?? [];
    ?>
    <?php foreach ($priorities as $id => $label): ?>
        <?php $rows = $grouped[$id] ?? []; ?>
        <section class="quadrant <?= esc($cardClasses[$id] ?? 'q-red') ?>" data-priority="<?= $id ?>">
            <a class="quadrant-head" href="<?= $dash !== null ? esc($dash->href('tasks/priority/' . $id, $filters)) : site_url('tasks/priority/' . $id) ?>"><?= esc($label) ?></a>
            <div class="quadrant-body">
                <?php if ($rows === []): ?>
                    <p class="quadrant-empty"><?= esc($emptyMessage) ?></p>
                <?php else: ?>
                    <?php foreach ($rows as $row): ?>
                        <?= view('dashboard/_task_row', ['row' => $row]) ?>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>
            <a class="quadrant-add" href="<?= site_url('tasks/create?priority=' . $id) ?>">+ Add Task</a>
        </section>
    <?php endforeach; ?>
</div>
<?= view('dashboard/_task_sheets') ?>
<?= $this->endSection() ?>
