<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-4">
  <h1 class="section-title mb-0">Karya Saya</h1>
  <a href="<?= base_url('submit') ?>" class="btn btn-primary">
    <i class="bi bi-cloud-upload me-2"></i>Unggah Karya Baru
  </a>
</div>

<?php if (empty($docs)): ?>
  <div class="text-center py-5 text-muted card-stt">
    <i class="bi bi-journal-x fs-1 d-block mb-3 opacity-25"></i>
    <p class="mb-2">Belum ada karya yang diunggah.</p>
    <a href="<?= base_url('submit') ?>" class="btn btn-primary btn-sm">
      <i class="bi bi-plus-circle me-1"></i>Unggah Karya Pertama
    </a>
  </div>
<?php else: ?>
  <div class="card-stt overflow-hidden">
    <table class="table table-stt mb-0">
      <thead>
        <tr>
          <th>Judul</th>
          <th>Jenis</th>
          <th>Tahun</th>
          <th>Status</th>
          <th>Diperbarui</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($docs as $doc): ?>
          <tr>
            <td>
              <a href="<?= base_url('my-works/' . $doc['id']) ?>" class="fw-semibold text-decoration-none">
                <?= esc(character_limiter($doc['title'], 70)) ?>
              </a>
            </td>
            <td class="small text-muted"><?= esc($doc['type_name']) ?></td>
            <td class="small text-muted"><?= esc($doc['year']) ?></td>
            <td>
              <span class="status-badge status-<?= esc($doc['status']) ?>">
                <?= esc(ucfirst($doc['status'])) ?>
              </span>
            </td>
            <td class="small text-muted"><?= date('d M Y', strtotime($doc['updated_at'])) ?></td>
            <td>
              <a href="<?= base_url('my-works/' . $doc['id']) ?>" class="btn btn-sm btn-outline-secondary">
                <i class="bi bi-eye"></i>
              </a>
            </td>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>
<?php endif; ?>

<?= $this->endSection() ?>
