<div class="row g-3">
  <div class="col-lg-5">
    <div class="card mb-3"><div class="card-header"><i class="bi bi-person me-1"></i>Data Profil</div>
      <form method="post" action="<?= url('/profil') ?>" class="card-body">
        <?= csrf() ?>
        <div class="text-center mb-3">
          <span class="avatar mx-auto" style="width:64px;height:64px;font-size:26px"><?= e(mb_substr($u['name'],0,1)) ?></span>
          <div class="mt-2 fw-bold"><?= e($u['name']) ?></div>
          <div class="small text-body-secondary"><?= badge($u['role_name'],'primary') ?></div>
        </div>
        <div class="mb-2"><label class="form-label" for="username">Nama Pengguna</label>
          <input type="text" class="form-control" id="username" value="<?= attr($u['username']) ?>" readonly></div>
        <div class="mb-2"><label class="form-label required" for="name">Nama Lengkap</label>
          <input type="text" class="form-control" id="name" name="name" required maxlength="120" value="<?= attr($u['name']) ?>"></div>
        <div class="mb-2"><label class="form-label required" for="email">Email</label>
          <input type="email" class="form-control" id="email" name="email" required maxlength="150" value="<?= attr($u['email']) ?>"></div>
        <div class="mb-3"><label class="form-label" for="phone">Telepon</label>
          <input type="text" class="form-control" id="phone" name="phone" maxlength="40" value="<?= attr($u['phone']) ?>"></div>
        <div class="d-flex gap-2">
          <button class="btn btn-primary" type="submit"><i class="bi bi-check-lg me-1"></i>Simpan Profil</button>
          <a class="btn btn-outline-secondary" href="<?= url('/ganti-sandi') ?>"><i class="bi bi-key me-1"></i>Ganti Kata Sandi</a>
        </div>
      </form>
    </div>
    <div class="card"><div class="card-header"><i class="bi bi-graph-up me-1"></i>Ringkasan Aktivitas</div>
      <div class="card-body"><dl class="dl-grid">
        <dt>Total Aktivitas</dt><dd><?= nf($stats['aktivitas']) ?></dd>
        <dt>Invoice Dibuat</dt><dd><?= nf($stats['invoice_dibuat']) ?></dd>
        <dt>Pembayaran Dicatat</dt><dd><?= nf($stats['pembayaran_dibuat']) ?></dd>
        <dt>Terakhir Masuk</dt><dd><?= tglWaktu($u['last_login_at']) ?></dd>
        <dt>IP Terakhir</dt><dd><?= e($u['last_login_ip'] ?: '-') ?></dd>
        <dt>Sandi Diubah</dt><dd><?= tglWaktu($u['password_changed_at']) ?></dd>
        <dt>Cakupan Data</dt><dd><?= e(['all'=>'Seluruh data','own_collection'=>'Invoice yang ditagih sendiri',
              'own_sales'=>'Invoice sales terkait','own_area'=>'Area terkait'][$u['data_scope'] ?? 'all'] ?? '-') ?></dd>
      </dl></div></div>
  </div>
  <div class="col-lg-7">
    <div class="card"><div class="card-header"><i class="bi bi-clock-history me-1"></i>25 Aktivitas Terakhir Saya</div>
      <div class="table-wrap" style="max-height:70vh"><table class="table table-sm table-hover table-sticky mb-0">
        <thead><tr><th class="ctr">Waktu</th><th>Modul</th><th>Aksi</th><th>Keterangan</th></tr></thead>
        <tbody>
        <?php if (!$recent): ?><tr><td colspan="4" class="text-center text-body-secondary py-3">Belum ada aktivitas.</td></tr><?php endif; ?>
        <?php foreach ($recent as $a): ?>
          <tr><td class="ctr small nowrap"><?= tglWaktu($a['created_at']) ?></td>
            <td class="small"><?= e($a['module']) ?></td>
            <td><?= badge(\App\Core\Audit::actionLabel($a['action']),'secondary') ?></td>
            <td class="small"><?= e(truncate($a['description'],70)) ?></td></tr>
        <?php endforeach; ?>
        </tbody></table></div>
    </div>
  </div>
</div>
