{% extends 'base.html' %}
{% block content %}
<div class="row g-4">
    <div class="col-md-4">
        <div class="card glass-card border-0 shadow-sm">
            <div class="card-body p-4">
                <h4 class="fw-bold mb-4 d-flex align-items-center">
                    <div class="bg-primary-subtle text-primary p-2 rounded-3 me-3">
                        <i data-lucide="tag"></i>
                    </div>
                    Tambah Kategori
                </h4>
                <form method="post">
                    {% csrf_token %}
                    {% for field in form %}
                        <div class="mb-3">
                            <label class="form-label small fw-bold text-muted text-uppercase mb-1" style="font-size: 0.65rem; letter-spacing: 0.5px;">{{ field.label }}</label>
                            {{ field }}
                            {% if field.help_text %}
                                <div class="form-text small">{{ field.help_text }}</div>
                            {% endif %}
                            {% for error in field.errors %}
                                <div class="text-danger small">{{ error }}</div>
                            {% endfor %}
                        </div>
                    {% endfor %}
                    <button type="submit" class="btn btn-primary w-100 py-3 mt-3 shadow-sm d-flex align-items-center justify-content-center">
                        <i data-lucide="save" class="me-2 icon-sm"></i> Simpan Kategori
                    </button>
                </form>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card glass-card border-0 shadow-sm">
            <div class="card-body p-4">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h4 class="fw-bold mb-0 d-flex align-items-center">
                        <div class="bg-primary-subtle text-primary p-2 rounded-3 me-3">
                            <i data-lucide="layers"></i>
                        </div>
                        Daftar Kategori
                    </h4>
                    <span class="badge bg-light text-dark border px-3 py-2 rounded-pill">{{ categories|length }} Total</span>
                </div>
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>Nama Kategori</th>
                                <th>Deskripsi</th>
                                <th class="text-end">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for c in categories %}
                            <tr>
                                <td>
                                    <div class="fw-bold text-dark">{{ c.name }}</div>
                                </td>
                                <td><span class="text-muted small">{{ c.description|default:"-"|truncatechars:100 }}</span></td>
                                <td class="text-end">
                                    <a href="/admin/core/category/{{ c.id }}/change/" class="btn btn-light btn-sm rounded-circle p-2">
                                        <i data-lucide="edit-3" class="icon-sm"></i>
                                    </a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="3" class="text-center py-5 text-muted">
                                    <i data-lucide="inbox" class="mb-2 d-block mx-auto opacity-20" style="width: 48px; height: 48px;"></i>
                                    Belum ada data kategori.
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
