{% extends 'base.html' %}
{% load static %}
{% block title %}{% if object %}Edit{% else %}Add{% endif %} Expense{% endblock %}
{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0">{% if object %}Edit{% else %}Add{% endif %} Expense</h1>
        <a href="{% url 'finance:expense_list' %}" class="btn btn-outline-secondary"><i class="fas fa-arrow-left me-2"></i>Back</a>
    </div>
    <div class="row justify-content-center">
        <div class="col-md-7">
            <div class="card shadow">
                <div class="card-header py-3 bg-danger text-white"><h6 class="m-0"><i class="fas fa-receipt me-2"></i>Expense Details</h6></div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        {% if form.errors %}<div class="alert alert-danger">Please correct the errors below.</div>{% endif %}
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Category <span class="text-danger">*</span></label>
                                {{ form.category }}
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Expense Date <span class="text-danger">*</span></label>
                                {{ form.expense_date }}
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-bold">Description <span class="text-danger">*</span></label>
                            {{ form.description }}
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Amount (XAF) <span class="text-danger">*</span></label>
                                {{ form.amount }}
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Payment Method</label>
                                {{ form.payment_method }}
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-bold">Vendor / Supplier</label>
                            {{ form.vendor }}
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-bold">Notes</label>
                            {{ form.notes }}
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-bold">Receipt File</label>
                            {{ form.receipt_file }}
                        </div>
                        <div class="d-flex justify-content-end gap-2 mt-4">
                            <a href="{% url 'finance:expense_list' %}" class="btn btn-secondary">Cancel</a>
                            <button type="submit" class="btn btn-danger"><i class="fas fa-save me-2"></i>Save Expense</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% block extra_js %}
<script>
document.querySelectorAll('input:not(.form-check-input):not([type="submit"]):not([type="file"]), select, textarea').forEach(el => {
    el.classList.add(el.tagName === 'SELECT' ? 'form-select' : 'form-control');
});
</script>
{% endblock %}
{% endblock %}
