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

{% block title %}
    {% if mode == "edit" %}Edit Branch{% else %}New Branch{% endif %} - SwiftPOS
{% endblock %}
{% block topbar_title %}
    {% if mode == "edit" %}Edit Branch{% else %}New Branch{% endif %}
{% endblock %}

{% block content %}
<div class="container-fluid px-0">
    <div class="card sp-animate-card">
        <div class="card-header">
            <h6 class="card-title mb-0">
                {% if mode == "edit" %}Edit Branch{% else %}Create Branch{% endif %}
            </h6>
        </div>
        <div class="card-body">
            <form method="post" novalidate>
                {% csrf_token %}

                <div class="row g-3 mb-3">
                    <div class="col-md-4">
                        <label class="form-label small fw-semibold">Name</label>
                        {{ form.name }}
                        {% for error in form.name.errors %}
                            <div class="text-danger small">{{ error }}</div>
                        {% endfor %}
                    </div>
                    <div class="col-md-4">
                        <label class="form-label small fw-semibold">Code</label>
                        {{ form.code }}
                        {% for error in form.code.errors %}
                            <div class="text-danger small">{{ error }}</div>
                        {% endfor %}
                    </div>
                    <div class="col-md-4 d-flex align-items-center">
                        <div class="form-check mt-4">
                            {{ form.is_active }}
                            <label class="form-check-label small">Active</label>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label small fw-semibold">Phone</label>
                        {{ form.phone }}
                        {% for error in form.phone.errors %}
                            <div class="text-danger small">{{ error }}</div>
                        {% endfor %}
                    </div>
                    <div class="col-md-6">
                        <label class="form-label small fw-semibold">Address</label>
                        {{ form.address }}
                        {% for error in form.address.errors %}
                            <div class="text-danger small">{{ error }}</div>
                        {% endfor %}
                    </div>
                </div>

                <div class="d-flex justify-content-between">
                    <a href="{% url 'branch_list' %}" class="btn btn-outline-secondary btn-sm">
                        Cancel
                    </a>
                    <button type="submit" class="btn btn-primary btn-sm">
                        <i class="fas fa-save me-1"></i>
                        {% if mode == "edit" %}Save Changes{% else %}Create Branch{% endif %}
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}
