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

{% block title %}{% trans "Create Acknowledgement" %} - PX360{% endblock %}

{% block content %}
<div class="p-6 md:p-8 bg-gradient-to-br from-light to-blue-50 min-h-screen">
    <!-- Header -->
    <div class="flex items-center gap-3 mb-8">
        <div class="flex items-center justify-center w-12 h-12 bg-gradient-to-br from-emerald-500 to-emerald-600 rounded-2xl shadow-lg shadow-emerald-200">
            <i data-lucide="plus-circle" class="w-6 h-6 text-white"></i>
        </div>
        <div>
            <h1 class="text-2xl font-bold text-navy">{% trans "Create Acknowledgement" %}</h1>
            <p class="text-slate text-sm">{% trans "Create a new acknowledgement for employees to sign" %}</p>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Main Form -->
        <div class="lg:col-span-2">
            <div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden">
                <div class="px-6 py-4 border-b border-slate-100 bg-gradient-to-r from-emerald-50 to-transparent">
                    <h2 class="font-bold text-navy flex items-center gap-2">
                        <i data-lucide="file-text" class="w-5 h-5 text-emerald-600"></i>
                        {% trans "Acknowledgement Details" %}
                    </h2>
                </div>

                <form method="post" enctype="multipart/form-data" class="p-6 space-y-6">
                    {% csrf_token %}

                    <!-- Title -->
                    <div>
                        <label class="block text-sm font-bold text-navy mb-2">
                            {% trans "Title" %} <span class="text-red-500">*</span>
                        </label>
                        <input type="text" name="title" required
                               class="w-full px-4 py-3 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent transition"
                               placeholder="{% trans 'e.g., Code of Conduct, Safety Policy, HIPAA Agreement' %}">
                        <p class="text-xs text-slate mt-2">{% trans "Give this acknowledgement a clear, descriptive title" %}</p>
                    </div>

                    <!-- Description -->
                    <div>
                        <label class="block text-sm font-bold text-navy mb-2">
                            {% trans "Description" %}
                        </label>
                        <textarea name="description" rows="6"
                                  class="w-full px-4 py-3 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent transition resize-none"
                                  placeholder="{% trans 'Enter the full text of the acknowledgement or a detailed description of what employees are agreeing to...' %}"></textarea>
                        <p class="text-xs text-slate mt-2">{% trans "Employees will see this description when signing" %}</p>
                    </div>

                    <!-- PDF Upload -->
                    <div>
                        <label class="block text-sm font-bold text-navy mb-2">
                            {% trans "Attach PDF Document" %}
                        </label>
                        <div class="border-2 border-dashed border-slate-300 rounded-xl p-8 text-center hover:border-emerald-500 hover:bg-emerald-50/30 transition cursor-pointer" onclick="document.getElementById('pdf-upload').click()">
                            <input type="file" id="pdf-upload" name="pdf_document" accept=".pdf" class="hidden" onchange="handleFileSelect(this)">
                            <div id="upload-placeholder">
                                <i data-lucide="upload-cloud" class="w-12 h-12 text-slate-400 mx-auto mb-3"></i>
                                <p class="text-slate font-medium">{% trans "Click to upload PDF" %}</p>
                                <p class="text-sm text-slate mt-1">{% trans "or drag and drop here" %}</p>
                            </div>
                            <div id="upload-preview" class="hidden">
                                <i data-lucide="file-text" class="w-12 h-12 text-emerald-500 mx-auto mb-3"></i>
                                <p class="font-medium text-navy" id="filename"></p>
                                <p class="text-sm text-emerald-600 mt-1">{% trans "Click to change file" %}</p>
                            </div>
                        </div>
                        <p class="text-xs text-slate mt-2">{% trans "Optional: Upload a PDF for employees to review before signing" %}</p>
                    </div>

                    <!-- Settings -->
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div class="bg-emerald-50 border border-emerald-100 rounded-xl p-4">
                            <label class="flex items-start gap-3 cursor-pointer">
                                <input type="checkbox" name="is_active" checked
                                       class="w-5 h-5 text-emerald-500 rounded focus:ring-emerald-500 mt-0.5">
                                <div>
                                    <span class="font-semibold text-navy">{% trans "Active" %}</span>
                                    <p class="text-xs text-slate mt-1">{% trans "Show this acknowledgement in employee checklists immediately" %}</p>
                                </div>
                            </label>
                        </div>
                        <div class="bg-amber-50 border border-amber-100 rounded-xl p-4">
                            <label class="flex items-start gap-3 cursor-pointer">
                                <input type="checkbox" name="is_required" checked
                                       class="w-5 h-5 text-amber-500 rounded focus:ring-amber-500 mt-0.5">
                                <div>
                                    <span class="font-semibold text-navy">{% trans "Required" %}</span>
                                    <p class="text-xs text-slate mt-1">{% trans "All employees must sign this acknowledgement" %}</p>
                                </div>
                            </label>
                        </div>
                    </div>

                    <!-- Display Order -->
                    <div>
                        <label class="block text-sm font-bold text-navy mb-2">
                            {% trans "Display Order" %}
                        </label>
                        <input type="number" name="order" value="0" min="0"
                               class="w-32 px-4 py-3 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent transition">
                        <p class="text-xs text-slate mt-2">{% trans "Lower numbers appear first in the list (0 = top)" %}</p>
                    </div>

                    <!-- Actions -->
                    <div class="flex gap-3 pt-4 border-t border-slate-100">
                        <a href="{% url 'accounts:simple_acknowledgements:admin_list' %}"
                           class="inline-flex items-center justify-center gap-2 px-6 py-3 bg-slate-100 text-slate-700 rounded-xl font-semibold hover:bg-slate-200 transition">
                            <i data-lucide="x" class="w-5 h-5"></i>
                            {% trans "Cancel" %}
                        </a>
                        <button type="submit"
                                class="flex-1 inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-emerald-500 to-emerald-600 text-white rounded-xl font-semibold hover:from-emerald-600 hover:to-emerald-700 transition shadow-lg shadow-emerald-200">
                            <i data-lucide="check-circle" class="w-5 h-5"></i>
                            {% trans "Create Acknowledgement" %}
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Help Sidebar -->
        <div class="lg:col-span-1">
            <div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden sticky top-6">
                <div class="px-6 py-4 border-b border-slate-100 bg-gradient-to-r from-blue to-navy">
                    <h3 class="font-bold text-white flex items-center gap-2">
                        <i data-lucide="help-circle" class="w-5 h-5"></i>
                        {% trans "Tips" %}
                    </h3>
                </div>
                <div class="p-6 space-y-4">
                    <div class="flex items-start gap-3">
                        <div class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center flex-shrink-0">
                            <span class="font-bold text-blue text-sm">1</span>
                        </div>
                        <div>
                            <p class="font-semibold text-navy text-sm">{% trans "Clear Title" %}</p>
                            <p class="text-xs text-slate mt-1">{% trans "Use a descriptive title so employees understand what they're signing" %}</p>
                        </div>
                    </div>

                    <div class="flex items-start gap-3">
                        <div class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center flex-shrink-0">
                            <span class="font-bold text-blue text-sm">2</span>
                        </div>
                        <div>
                            <p class="font-semibold text-navy text-sm">{% trans "Detailed Description" %}</p>
                            <p class="text-xs text-slate mt-1">{% trans "Include the full policy text or a clear summary" %}</p>
                        </div>
                    </div>

                    <div class="flex items-start gap-3">
                        <div class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center flex-shrink-0">
                            <span class="font-bold text-blue text-sm">3</span>
                        </div>
                        <div>
                            <p class="font-semibold text-navy text-sm">{% trans "PDF Attachment" %}</p>
                            <p class="text-xs text-slate mt-1">{% trans "Upload official policy documents for reference" %}</p>
                        </div>
                    </div>

                    <div class="flex items-start gap-3">
                        <div class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center flex-shrink-0">
                            <span class="font-bold text-blue text-sm">4</span>
                        </div>
                        <div>
                            <p class="font-semibold text-navy text-sm">{% trans "Required vs Optional" %}</p>
                            <p class="text-xs text-slate mt-1">{% trans "Mark critical policies as required" %}</p>
                        </div>
                    </div>

                    <div class="pt-4 border-t border-slate-100">
                        <a href="{% url 'accounts:simple_acknowledgements:admin_list' %}"
                           class="inline-flex items-center gap-2 text-sm text-blue hover:text-navy transition">
                            <i data-lucide="arrow-left" class="w-4 h-4"></i>
                            {% trans "Back to list" %}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function handleFileSelect(input) {
    const placeholder = document.getElementById('upload-placeholder');
    const preview = document.getElementById('upload-preview');
    const filename = document.getElementById('filename');

    if (input.files && input.files[0]) {
        placeholder.classList.add('hidden');
        preview.classList.remove('hidden');
        filename.textContent = input.files[0].name;
    }
}

// Drag and drop support
const dropZone = document.querySelector('.border-dashed');

dropZone.addEventListener('dragover', (e) => {
    e.preventDefault();
    dropZone.classList.add('border-emerald-500', 'bg-emerald-50');
});

dropZone.addEventListener('dragleave', () => {
    dropZone.classList.remove('border-emerald-500', 'bg-emerald-50');
});

dropZone.addEventListener('drop', (e) => {
    e.preventDefault();
    dropZone.classList.remove('border-emerald-500', 'bg-emerald-50');

    const files = e.dataTransfer.files;
    if (files.length > 0 && files[0].type === 'application/pdf') {
        document.getElementById('pdf-upload').files = files;
        handleFileSelect(document.getElementById('pdf-upload'));
    } else {
        alert('{% trans "Please upload a PDF file" %}');
    }
});

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