<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php $date_text = function ($value) { return !empty($value) ? date('M d, Y', strtotime($value)) : '--'; }; ?>
<div class="space-y-4 sm:space-y-6">
    <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
        <article class="rounded-2xl border border-border bg-background/70 p-4 sm:p-5 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Tasks</p>
            <p class="mt-3 text-2xl font-semibold text-foreground sm:text-3xl"><?= count($workspace['my_tasks']) ?></p>
            <p class="mt-2 text-xs text-muted-foreground">Assigned tasks currently open in your queue</p>
        </article>
        <article class="rounded-2xl border border-border bg-background/70 p-4 sm:p-5 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Projects</p>
            <p class="mt-3 text-2xl font-semibold text-foreground sm:text-3xl"><?= count($workspace['my_projects']) ?></p>
            <p class="mt-2 text-xs text-muted-foreground">Active projects visible to your account</p>
        </article>
        <article class="rounded-2xl border border-border bg-background/70 p-4 sm:p-5 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Reminders</p>
            <p class="mt-3 text-2xl font-semibold text-foreground sm:text-3xl"><?= count($workspace['my_reminders']) ?></p>
            <p class="mt-2 text-xs text-muted-foreground">Upcoming reminders created in your workspace</p>
        </article>
        <article class="rounded-2xl border border-border bg-background/70 p-4 sm:p-5 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Todo</p>
            <p class="mt-3 text-2xl font-semibold text-foreground sm:text-3xl"><?= count($workspace['my_todos']) ?></p>
            <p class="mt-2 text-xs text-muted-foreground">Checklist items ordered for daily execution</p>
        </article>
    </div>

    <div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
        <article class="rounded-2xl border border-border bg-background/60 p-4 sm:p-5">
            <div class="mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Tasks</p>
                    <h3 class="text-lg font-semibold text-foreground">Assigned work queue</h3>
                </div>
                <a href="<?= base_url('admin/tasks/all_task') ?>" class="text-sm font-semibold text-primary hover:underline">Open tasks</a>
            </div>
            <div class="space-y-3">
                <?php foreach ($workspace['my_tasks'] as $task): ?>
                    <div class="rounded-xl border border-border bg-card p-4">
                        <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
                            <div>
                                <p class="text-sm font-semibold text-foreground"><?= html_escape($task->task_name) ?></p>
                                <p class="mt-1 text-xs text-muted-foreground"><?= html_escape($task->project_name ?: 'No project') ?> • Due <?= $date_text($task->due_date) ?></p>
                            </div>
                            <div class="text-right">
                                <span class="rounded-full bg-muted px-2.5 py-1 text-[11px] font-semibold text-foreground"><?= html_escape(ucwords(str_replace('_', ' ', $task->task_status))) ?></span>
                                <p class="mt-2 text-xs font-semibold text-primary"><?= (int) $task->task_progress ?>%</p>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </article>

        <article class="rounded-2xl border border-border bg-background/60 p-4 sm:p-5">
            <div class="mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Projects</p>
                    <h3 class="text-lg font-semibold text-foreground">Current delivery focus</h3>
                </div>
                <a href="<?= base_url('admin/projects') ?>" class="text-sm font-semibold text-primary hover:underline">Open projects</a>
            </div>
            <div class="space-y-3">
                <?php foreach ($workspace['my_projects'] as $project): ?>
                    <div class="rounded-xl border border-border bg-card p-4">
                        <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
                            <div>
                                <p class="text-sm font-semibold text-foreground"><?= html_escape($project->project_name) ?></p>
                                <p class="mt-1 text-xs text-muted-foreground"><?= html_escape(ucfirst($project->project_status)) ?> • Due <?= $date_text($project->end_date) ?></p>
                            </div>
                            <a href="<?= base_url('admin/projects/project_details/' . $project->project_id) ?>" class="text-sm font-semibold text-primary hover:underline">View</a>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </article>
    </div>

    <div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
        <article class="rounded-2xl border border-border bg-background/60 p-4 sm:p-5">
            <div class="mb-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Reminders</p>
                <h3 class="text-lg font-semibold text-foreground">Upcoming follow-up items</h3>
            </div>
            <div class="space-y-3">
                <?php foreach ($workspace['my_reminders'] as $reminder): ?>
                    <div class="rounded-xl border border-border bg-card p-4">
                        <p class="text-sm font-semibold text-foreground"><?= html_escape($reminder->module ?: 'Reminder') ?></p>
                        <p class="mt-1 text-xs leading-5 text-muted-foreground"><?= html_escape($reminder->description ?: 'No description') ?></p>
                        <p class="mt-2 text-xs font-medium text-primary"><?= $date_text($reminder->date) ?></p>
                    </div>
                <?php endforeach; ?>
            </div>
        </article>

        <article class="rounded-2xl border border-border bg-background/60 p-4 sm:p-5">
            <div class="mb-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">My Todo</p>
                <h3 class="text-lg font-semibold text-foreground">Personal checklist</h3>
            </div>
            <div class="space-y-3">
                <?php foreach ($workspace['my_todos'] as $todo): ?>
                    <div class="rounded-xl border border-border bg-card p-4">
                        <div class="flex items-start justify-between gap-3">
                            <div>
                                <p class="text-sm font-semibold text-foreground"><?= html_escape($todo->title) ?></p>
                                <p class="mt-1 text-xs text-muted-foreground"><?= !empty($todo->status) ? html_escape(ucfirst($todo->status)) : 'Open' ?></p>
                            </div>
                            <span class="rounded-full bg-muted px-2.5 py-1 text-[11px] font-semibold text-foreground">#<?= (int) $todo->order ?></span>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </article>
    </div>
</div>
