{% extends 'layouts/base.html' %}
{% load i18n %}

{% block title %}{% if section %}{% trans "Edit Section" %}{% else %}{% trans "Add Section" %}{% endif %} - PX360{% endblock %}

{% block extra_css %}
<style>
    .page-header-gradient {
        background: linear-gradient(135deg, #005696 0%, #0069a8 50%, #007bbd 100%);
        color: white;
        padding: 1.5rem 2rem;
        border-radius: 1rem;
        margin-bottom: 1.5rem;
        box-shadow: 0 10px 15px -3px rgba(0, 86, 150, 0.2);
    }

    .form-section {
        background: #fff;
        border: 2px solid #e2e8f0;
        border-radius: 1rem;
        padding: 1.5rem;
        margin-bottom: 1.5rem;
        transition: all 0.3s ease;
    }
    .form-section:hover {
        border-color: #005696;
        box-shadow: 0 4px 12px rgba(0, 86, 150, 0.1);
    }

    .hh-btn-primary {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1.5rem;
        background: #005696;
        color: white;
        border-radius: 0.75rem;
        font-weight: 600;
        transition: all 0.2s ease;
        border: none;
        cursor: pointer;
    }
    .hh-btn-primary:hover {
        background: #007bbd;
    }

    .hh-btn-secondary {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1.5rem;
        background: white;
        color: #64748b;
        border: 2px solid #e2e8f0;
        border-radius: 0.75rem;
        font-weight: 600;
        transition: all 0.2s ease;
    }
    .hh-btn-secondary:hover {
        background: #f1f5f9;
        border-color: #005696;
    }
</style>
{% endblock %}

{% block content %}
<!-- Gradient Header -->
<div class="page-header-gradient">
    <div class="flex items-center gap-2 mb-3">
        <a href="{% url 'organizations:orgsection_list' %}" 
           class="inline-flex items-center gap-2 px-4 py-2 bg-white/20 backdrop-blur-sm rounded-xl text-white hover:bg-white/30 transition text-sm font-semibold">
            <i data-lucide="arrow-left" class="w-4 h-4"></i> {% trans "Back" %}
        </a>
    </div>
    <h1 class="text-2xl font-bold">
        {% if section %}{% trans "Edit Section" %}{% else %}{% trans "Add Section" %}{% endif %}
    </h1>
    <p class="text-white/80 mt-1">
        {% if section %}{% trans "Update section information" %}{% else %}{% trans "Create a new org section" %}{% endif %}
    </p>
</div>

<div class="max-w-2xl mx-auto">
    <div class="form-section">
        <form method="post">
            {% csrf_token %}
            
            <div class="space-y-6">
                <div>
                    <label for="department" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Department" %} <span class="text-[#005696]">*</span></label>
                    <select class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="department" name="department" data-tomselect required>
                        <option value="">{% trans "Select Department" %}</option>
                        {% for dept in departments %}
                        <option value="{{ dept.id }}" {% if section.department_id == dept.id %}selected{% endif %}>{{ dept.get_localized_name }}</option>
                        {% endfor %}
                    </select>
                </div>
                
                <div>
                    <label for="name_en" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Section Name (EN)" %} <span class="text-[#005696]">*</span></label>
                    <input type="text" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="name_en" name="name_en" value="{{ section.name_en|default:'' }}" required placeholder="{% trans 'Enter section name in English' %}">
                </div>
                
                <div>
                    <label for="name_ar" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Section Name (AR)" %}</label>
                    <input type="text" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="name_ar" name="name_ar" value="{{ section.name_ar|default:'' }}" dir="rtl" placeholder="{% trans 'Enter section name in Arabic' %}">
                </div>
                
                <div>
                    <label for="code" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Code" %}</label>
                    <input type="text" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="code" name="code" value="{{ section.code|default:'' }}" placeholder="{% trans 'Enter section code' %}">
                </div>
                
                <div>
                    <label for="location_type" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Location Type" %}</label>
                    <select class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="location_type" name="location_type">
                        <option value="" {% if not section.location_type %}selected{% endif %}>---------</option>
                        <option value="OP" {% if section.location_type == 'OP' %}selected{% endif %}>{% trans "OP" %}</option>
                        <option value="IP" {% if section.location_type == 'IP' %}selected{% endif %}>{% trans "IP" %}</option>
                        <option value="ER" {% if section.location_type == 'ER' %}selected{% endif %}>{% trans "ER" %}</option>
                        <option value="GENERAL" {% if section.location_type == 'GENERAL' %}selected{% endif %}>{% trans "General" %}</option>
                    </select>
                </div>
                
                <div>
                    <label for="sub_location" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Sub Location" %}</label>
                    <input type="text" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="sub_location" name="sub_location" value="{{ section.sub_location|default:'' }}" placeholder="{% trans 'Enter sub location' %}">
                </div>
                
                <div>
                    <label for="floor" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Floor" %}</label>
                    <input type="text" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="floor" name="floor" value="{{ section.floor|default:'' }}" placeholder="{% trans 'Enter floor' %}">
                </div>
                
                <div>
                    <label for="status" class="block text-sm font-semibold text-gray-700 mb-2">{% trans "Status" %}</label>
                    <select class="w-full px-4 py-3 border border-gray-200 rounded-xl text-gray-800 focus:ring-2 focus:ring-[#005696] focus:border-transparent transition" id="status" name="status">
                        <option value="active" {% if section.status == 'active' or not section %}selected{% endif %}>{% trans "Active" %}</option>
                        <option value="inactive" {% if section.status == 'inactive' %}selected{% endif %}>{% trans "Inactive" %}</option>
                    </select>
                </div>
            </div>
            
            <div class="flex justify-end gap-3 mt-8 pt-6 border-t border-gray-100">
                <a href="{% url 'organizations:orgsection_list' %}" class="hh-btn-secondary">
                    <i data-lucide="x" class="w-5 h-5"></i>
                    {% trans "Cancel" %}
                </a>
                <button type="submit" class="hh-btn-primary">
                    <i data-lucide="save" class="w-5 h-5"></i>
                    {% trans "Save" %}
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}
