{% extends 'base.html' %}
{% load static %}
{% block title %}{{ title }} — Rapha-Bethel BNPS{% endblock %}

{% block content %}
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <div><h1 class="h3 mb-0">{{ title }}</h1></div>
    <a href="{% url 'finance:school_item_list' %}" class="btn btn-outline-secondary">
      <i class="fas fa-arrow-left me-1"></i>Back
    </a>
  </div>
  <div class="row justify-content-center">
    <div class="col-md-6">
      <div class="card shadow">
        <div class="card-header py-3 bg-primary text-white">
          <h6 class="m-0"><i class="fas fa-tshirt me-2"></i>Item Price Details</h6>
        </div>
        <div class="card-body">
          <form method="post">
            {% csrf_token %}
            {% if form.errors %}
            <div class="alert alert-danger">
              Please correct the errors below. {{ form.non_field_errors }}
            </div>
            {% endif %}

            <div class="row mb-3">
              <div class="col-md-6">
                <label class="form-label fw-bold">Item Type <span class="text-danger">*</span></label>
                {{ form.item_type }}
              </div>
              <div class="col-md-6">
                <label class="form-label fw-bold">Item Name <span class="text-danger">*</span></label>
                {{ form.name }}
              </div>
            </div>
            <div class="row mb-3">
              <div class="col-md-6">
                <label class="form-label fw-bold">Selling Price (XAF) <span class="text-danger">*</span></label>
                {{ form.price }}
              </div>
              <div class="col-md-6">
                <label class="form-label fw-bold">Academic Year</label>
                {{ form.academic_year }}
              </div>
            </div>
            <div class="mb-3">
              <label class="form-label fw-bold">Description / Notes</label>
              {{ form.description }}
            </div>
            <div class="mb-3">
              <div class="form-check">
                {{ form.is_active }}
                <label class="form-check-label fw-bold">Available for Sale</label>
              </div>
            </div>
            <div class="d-flex justify-content-end gap-2 mt-4">
              <a href="{% url 'finance:school_item_list' %}" class="btn btn-secondary">Cancel</a>
              <button type="submit" class="btn btn-primary">
                <i class="fas fa-save me-1"></i>Save
              </button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.querySelectorAll('input:not(.form-check-input):not([type="submit"]), select, textarea').forEach(el => {
  el.classList.add(el.tagName === 'SELECT' ? 'form-select' : 'form-control');
});
</script>
{% endblock %}