{% extends "core/base.html" %}
{% load static %}

{% block title %}Log Expense - SwiftPOS{% endblock %}
{% block topbar_title %}Log Operating Expense{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-lg-8 col-xl-6">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h4 class="fw-bold mb-1">Record Expense</h4>
                <div class="text-muted small">Log a new operating expense for the company.</div>
            </div>
            <a href="{% url 'analytics:expense_list' %}" class="btn btn-outline-secondary btn-sm rounded-pill px-3">
                <i class="fas fa-arrow-left me-1"></i> Back
            </a>
        </div>
        
        <div class="card border-0 shadow-sm" style="border-radius: 16px;">
            <div class="card-body p-4">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="row g-4">
                        {% for field in form %}
                            <div class="{% if field.name in 'notes' %}col-12{% else %}col-md-6{% endif %}">
                                <label class="form-label small fw-bold text-dark mb-2 d-flex justify-content-between align-items-center w-100" for="{{ field.id_for_label }}">
                                    <span>{{ field.label }} {% if field.field.required %}<span class="text-danger">*</span>{% endif %}</span>
                                    {% if field.name == 'category' %}
                                        <a href="{% url 'analytics:expense_category_create' %}" class="text-decoration-none small" style="font-size:0.75rem;"><i class="fas fa-plus-circle me-1"></i>New Category</a>
                                    {% endif %}
                                </label>
                                
                                {{ field }}
                                
                                {% if field.help_text %}
                                    <div class="form-text small mt-1" style="color:var(--sp-text-muted);">{{ field.help_text }}</div>
                                {% endif %}
                                {% for error in field.errors %}
                                    <div class="text-danger small mt-1 fw-medium"><i class="fas fa-exclamation-circle me-1"></i>{{ error }}</div>
                                {% endfor %}
                            </div>
                        {% endfor %}
                    </div>
                    
                    <hr class="my-4" style="border-color: #eee;">
                    
                    <div class="d-flex justify-content-end gap-2">
                        <a href="{% url 'analytics:expense_list' %}" class="btn btn-light btn-sm rounded-pill px-4 text-dark fw-medium">Cancel</a>
                        <button type="submit" class="btn btn-primary btn-sm rounded-pill px-4 fw-medium shadow-sm">
                            <i class="fas fa-save me-1"></i> Save Expense
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
