{% extends 'base.html' %}
{% load static %}

{% block title %}{% if object %}Edit Subject{% else %}Add Subject{% endif %} - 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">{% if object %}Edit Subject{% else %}Add New Subject{% endif %}</h1>
            <p class="text-muted">{% if object %}Update subject details{% else %}Add a subject to the curriculum{% endif %}</p>
        </div>
        <a href="{% url 'academics:subject_list' %}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left me-2"></i>Back to Subjects
        </a>
    </div>

    <div class="row justify-content-center">
        <div class="col-md-7">
            <div class="card shadow">
                <div class="card-header py-3 bg-primary text-white">
                    <h6 class="m-0"><i class="fas fa-book me-2"></i>Subject Details</h6>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {% if form.errors %}
                        <div class="alert alert-danger"><i class="fas fa-exclamation-circle me-2"></i>Please correct the errors below.</div>
                        {% endif %}

                        <div class="row mb-3">
                            <div class="col-md-4">
                                <label class="form-label fw-bold">Subject Code <span class="text-danger">*</span></label>
                                {{ form.code }}
                                {% if form.code.errors %}<div class="text-danger small">{{ form.code.errors }}</div>{% endif %}
                                <div class="text-muted small">e.g. MATH, ENG, SCI</div>
                            </div>
                            <div class="col-md-8">
                                <label class="form-label fw-bold">Category <span class="text-danger">*</span></label>
                                {{ form.category }}
                            </div>
                        </div>

                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Name (English) <span class="text-danger">*</span></label>
                                {{ form.name }}
                                {% if form.name.errors %}<div class="text-danger small">{{ form.name.errors }}</div>{% endif %}
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Name (French)</label>
                                {{ form.name_fr }}
                            </div>
                        </div>

                        <div class="mb-3">
                            <label class="form-label fw-bold">Description</label>
                            {{ form.description }}
                        </div>

                        <div class="d-flex justify-content-end gap-2 mt-4">
                            <a href="{% url 'academics:subject_list' %}" class="btn btn-secondary">Cancel</a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save me-2"></i>{% if object %}Update{% else %}Add{% endif %} Subject
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

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