<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php $date_text = function ($value) { return !empty($value) ? date('M d, Y h:i A', strtotime($value)) : '--'; }; ?>
<div class="space-y-6">
    <article class="rounded-2xl border border-border bg-background/60 p-5">
        <div class="mb-4 flex items-center justify-between gap-3">
            <div>
                <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">Recent Activity</p>
                <h3 class="text-lg font-semibold text-foreground">Latest actions across the ERP workspace</h3>
            </div>
            <a href="<?= base_url('admin/settings/activities') ?>" class="text-sm font-semibold text-primary hover:underline">Open activity log</a>
        </div>
        <div class="space-y-3">
            <?php foreach ($activity['recent_activities'] as $row): ?>
                <div class="rounded-xl border border-border bg-card p-4">
                    <div class="flex items-start gap-3">
                        <span class="mt-0.5 inline-flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary">
                            <i data-lucide="history" class="h-4 w-4"></i>
                        </span>
                        <div class="min-w-0 flex-1">
                            <div class="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
                                <p class="text-sm font-semibold text-foreground"><?= html_escape($row->fullname ?: 'System') ?></p>
                                <span class="text-xs text-muted-foreground"><?= $date_text($row->activity_date) ?></span>
                            </div>
                            <p class="mt-1 text-xs leading-6 text-muted-foreground"><?= strip_tags($row->activity . ' ' . $row->value1) ?></p>
                            <?php if (!empty($row->module)): ?>
                                <p class="mt-2 text-[11px] font-semibold uppercase tracking-wide text-primary"><?= html_escape($row->module) ?></p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </article>
</div>
