{% extends 'base.html' %}
{% block content %}
<div class="row g-4">
    <div class="col-md-4">
        <div class="card glass-card border-0 shadow-sm h-100">
            <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="file-plus"></i>
                    </div>
                    Input Faktur Baru
                </h4>
                <form method="post">
                    {% csrf_token %}
                    {% for field in faktur_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.errors %}
                                <div class="text-danger small">{{ field.errors }}</div>
                            {% endif %}
                        </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="arrow-right" class="me-2 icon-sm"></i> Simpan & Lanjutkan
                    </button>
                </form>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card glass-card border-0 shadow-sm h-100">
            <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="history"></i>
                        </div>
                        Riwayat Faktur
                    </h4>
                    <span class="badge bg-light text-dark border px-3 py-2 rounded-pill">{{ fakturs|length }} Total</span>
                </div>
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>No. Faktur</th>
                                <th>Supplier</th>
                                <th>Tanggal</th>
                                <th>Tipe</th>
                                <th class="text-end">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for f in fakturs %}
                            <tr>
                                <td class="fw-bold text-dark">{{ f.faktur_number }}</td>
                                <td>{{ f.supplier.name|default:"-" }}</td>
                                <td><span class="text-muted small">{{ f.date }}</span></td>
                                <td>
                                    <span class="badge {% if f.faktur_type == 'MASUK' %}bg-info-subtle text-info{% else %}bg-warning-subtle text-warning{% endif %} rounded-pill px-3">
                                        {{ f.get_faktur_type_display }}
                                    </span>
                                </td>
                                <td class="text-end">
                                    <a href="{% url 'faktur_detail' f.pk %}" class="btn btn-light btn-sm rounded-pill px-3 fw-bold">
                                        <i data-lucide="plus-circle" class="me-1 icon-sm"></i> Input Barang
                                    </a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="5" 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 faktur.
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}