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

{% block title %}{% if action == 'create' %}{% trans "New Acknowledgement" %}{% else %}{% trans "Edit Acknowledgement" %}{% 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);
    }

    .form-label {
        display: block;
        font-size: 0.875rem;
        font-weight: 600;
        color: #1e293b;
        margin-bottom: 0.5rem;
    }

    .form-control, .form-select {
        width: 100%;
        padding: 0.75rem 1rem;
        border: 2px solid #e2e8f0;
        border-radius: 0.75rem;
        font-size: 0.875rem;
        transition: all 0.2s ease;
    }
    .form-control:focus, .form-select:focus {
        outline: none;
        border-color: #005696;
        box-shadow: 0 0 0 3px 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 %}
<div class="p-6 md:p-8 bg-gradient-to-br from-slate-50 to-blue-50 min-h-screen">
    <!-- Page Header -->
    <div class="page-header-gradient flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
        <div>
            <nav aria-label="breadcrumb" class="mb-2">
                <ol class="flex items-center gap-2 text-sm text-white/80">
                    <li><a href="{% url 'accounts:simple_acknowledgements:admin_list' %}" class="hover:text-white transition">{% trans "Acknowledgements" %}</a></li>
                    <li><i data-lucide="chevron-right" class="w-4 h-4"></i></li>
                    <li class="text-white">{% if action == 'create' %}{% trans "Create" %}{% else %}{% trans "Edit" %}{% endif %}</li>
                </ol>
            </nav>
            <h1 class="text-2xl font-bold flex items-center gap-2">
                <i data-lucide="{% if action == 'create' %}plus{% else %}edit{% endif %}" class="w-8 h-8"></i>
                {% if action == 'create' %}{% trans "New Acknowledgement" %}{% else %}{% trans "Edit Acknowledgement" %}{% endif %}
            </h1>
        </div>
        <a href="{% url 'accounts:simple_acknowledgements:admin_list' %}" class="inline-flex items-center gap-2 px-4 py-2 bg-white/20 text-white rounded-lg hover:bg-white/30 transition">
            <i data-lucide="arrow-left" class="w-4 h-4"></i>
            {% trans "Back to List" %}
        </a>
    </div>

    <!-- Form Section -->
    <div class="max-w-3xl">
        <div class="form-section">
            <div class="flex items-center gap-2 mb-4 pb-3 border-b border-slate-100">
                <i data-lucide="file-text" class="w-5 h-5 text-blue-600"></i>
                <h2 class="text-lg font-bold text-slate-800">{% trans "Acknowledgement Details" %}</h2>
            </div>
            <form method="post" enctype="multipart/form-data" class="space-y-6">
                {% csrf_token %}

                <!-- Title -->
                <div>
                    <label class="form-label">
                        {% trans "Title" %} <span class="text-red-500">*</span>
                    </label>
                    <input type="text" name="title" required
                           value="{{ acknowledgement.title|default:'' }}"
                           class="form-control"
                           placeholder="{% trans 'Enter acknowledgement title' %}">
                </div>

                <!-- Description -->
                <div>
                    <label class="form-label">
                        {% trans "Description" %}
                    </label>
                    <textarea name="description" rows="5"
                              class="form-control"
                              placeholder="{% trans 'Enter detailed description of the acknowledgement' %}">{{ acknowledgement.description|default:'' }}</textarea>
                </div>

                <!-- PDF Document -->
                <div>
                    <label class="form-label">
                        {% trans "PDF Document" %}
                    </label>
                    <div class="border-2 border-dashed border-slate-300 rounded-xl p-6 text-center hover:border-blue-500 transition">
                        <input type="file" name="pdf_document" accept=".pdf"
                               class="w-full"
                               onchange="updateFileName(this)">
                        {% if acknowledgement.pdf_document %}
                            <p class="text-sm text-slate-600 mt-2">
                                {% trans "Current:" %} <a href="{{ acknowledgement.pdf_document.url }}" target="_blank" class="text-blue-600 hover:underline">{{ acknowledgement.pdf_document.name }}</a>
                            </p>
                        {% endif %}
                    </div>
                    <p class="text-xs text-slate-500 mt-2">{% trans "Upload a PDF document for employees to review (optional)" %}</p>
                </div>

                <!-- Settings -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="bg-slate-50 rounded-xl p-4">
                        <label class="flex items-center gap-3 cursor-pointer">
                            <input type="checkbox" name="is_active"
                                   {% if acknowledgement.is_active|default:True %}checked{% endif %}
                                   class="w-5 h-5 text-blue-600 rounded focus:ring-blue-500">
                            <div>
                                <span class="font-semibold text-slate-800">{% trans "Active" %}</span>
                                <p class="text-xs text-slate-500">{% trans "Show in employee checklist" %}</p>
                            </div>
                        </label>
                    </div>
                    <div class="bg-slate-50 rounded-xl p-4">
                        <label class="flex items-center gap-3 cursor-pointer">
                            <input type="checkbox" name="is_required"
                                   {% if acknowledgement.is_required|default:True %}checked{% endif %}
                                   class="w-5 h-5 text-blue-600 rounded focus:ring-blue-500">
                            <div>
                                <span class="font-semibold text-slate-800">{% trans "Required" %}</span>
                                <p class="text-xs text-slate-500">{% trans "Must be signed by all employees" %}</p>
                            </div>
                        </label>
                    </div>
                </div>

                <!-- Order -->
                <div>
                    <label class="form-label">
                        {% trans "Display Order" %}
                    </label>
                    <input type="number" name="order"
                           value="{{ acknowledgement.order|default:0 }}"
                           class="form-control w-32">
                    <p class="text-xs text-slate-500 mt-2">{% trans "Lower numbers appear first" %}</p>
                </div>

                <!-- Actions -->
                <div class="flex justify-end gap-3 pt-6 border-t border-slate-100">
                    <a href="{% url 'accounts:simple_acknowledgements:admin_list' %}"
                       class="hh-btn hh-btn-secondary">
                        {% trans "Cancel" %}
                    </a>
                    <button type="submit" class="hh-btn hh-btn-primary">
                        <i data-lucide="save" class="w-4 h-4"></i>
                        {% if action == 'create' %}{% trans "Create Acknowledgement" %}{% else %}{% trans "Save Changes" %}{% endif %}
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
function updateFileName(input) {
    if (input.files && input.files[0]) {
        // File selected - you can add visual feedback here
    }
}

document.addEventListener('DOMContentLoaded', function() {
    lucide.createIcons();
});
</script>
{% endblock %}
