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

{% block title %}{% trans "Update Compliance" %}{% 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: 1px 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: 1px 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.05);
}

.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: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    font-weight: 600;
    transition: all 0.2s ease;
}
.hh-btn-secondary:hover {
    background: #f1f5f9;
    border-color: #005696;
}

.section-header {
    padding: 1rem 1.5rem;
    border-bottom: 2px solid #e2e8f0;
    background: linear-gradient(to right, #f8fafc, #f1f5f9);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    border-radius: 1rem 1rem 0 0;
}

.section-icon {
    width: 40px;
    height: 40px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>
{% endblock %}

{% block content %}
<div class="p-6">
    <!-- Page Header -->
    <div class="page-header-gradient">
        <div class="flex justify-between items-center">
            <div>
                <h1 class="text-2xl font-bold flex items-center gap-3">
                    <i data-lucide="clipboard-check" class="w-6 h-6"></i>
                    {% trans "Update Compliance Assessment" %}
                </h1>
                <p class="text-blue-100 text-sm mt-1">{{ compliance.standard.code }} - {{ compliance.standard.title }}</p>
            </div>
            <a href="{% url 'standards:department_standards' pk=compliance.department.id %}"
               class="hh-btn hh-btn-secondary bg-white/10 border-white/30 text-white hover:bg-white hover:text-navy">
                <i data-lucide="arrow-left" class="w-4 h-4"></i>
                {% trans "Back to Standards" %}
            </a>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <div class="lg:col-span-2 space-y-6">
            <!-- Standard Details -->
            <div class="form-section p-0 overflow-hidden">
                <div class="section-header">
                    <div class="section-icon bg-navy/10">
                        <i data-lucide="clipboard-list" class="w-5 h-5 text-navy"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-navy m-0">{% trans "Standard Details" %}</h5>
                </div>
                <div class="p-6 pt-0">
                    <dl class="divide-y divide-slate-100">
                        <div class="py-3 flex justify-between">
                            <dt class="text-sm font-semibold text-slate">{% trans "Code" %}</dt>
                            <dd class="text-sm font-semibold text-navy">{{ compliance.standard.code }}</dd>
                        </div>
                        <div class="py-3 flex justify-between">
                            <dt class="text-sm font-semibold text-slate">{% trans "Title" %}</dt>
                            <dd class="text-sm font-semibold text-navy">{{ compliance.standard.title }}</dd>
                        </div>
                        <div class="py-3 flex justify-between">
                            <dt class="text-sm font-semibold text-slate">{% trans "Source" %}</dt>
                            <dd class="text-sm font-semibold text-navy">{{ compliance.standard.source.name }}</dd>
                        </div>
                        <div class="py-3 flex justify-between">
                            <dt class="text-sm font-semibold text-slate">{% trans "Category" %}</dt>
                            <dd class="text-sm font-semibold text-navy">{{ compliance.standard.category.name }}</dd>
                        </div>
                        <div class="py-3">
                            <dt class="text-sm font-medium text-slate mb-2">{% trans "Description" %}</dt>
                            <dd class="text-sm text-slate">{{ compliance.standard.description|linebreaks }}</dd>
                        </div>
                    </dl>
                </div>
            </div>

            <!-- Compliance Assessment Form -->
            <div class="form-section p-0 overflow-hidden">
                <div class="section-header">
                    <div class="section-icon bg-blue/10">
                        <i data-lucide="check-square" class="w-5 h-5 text-blue"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-navy m-0">{% trans "Compliance Assessment" %}</h5>
                </div>
                <div class="p-6 pt-0">
                    <form method="post">
                        {% csrf_token %}
                        
                        <div class="mb-4">
                            <label for="{{ form.status.id_for_label }}" class="form-label">
                                {% trans "Status" %}
                            </label>
                            {{ form.status }}
                            {% if form.status.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.status.errors }}</p>
                            {% endif %}
                        </div>

                        <div class="mb-4">
                            <label for="{{ form.last_assessed_date.id_for_label }}" class="form-label">
                                {% trans "Last Assessed Date" %}
                            </label>
                            {{ form.last_assessed_date }}
                            {% if form.last_assessed_date.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.last_assessed_date.errors }}</p>
                            {% endif %}
                        </div>

                        <div class="mb-4">
                            <label for="{{ form.assessor.id_for_label }}" class="form-label">
                                {% trans "Assessor" %}
                            </label>
                            {{ form.assessor }}
                            {% if form.assessor.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.assessor.errors }}</p>
                            {% endif %}
                        </div>

                        <div class="mb-4">
                            <label for="{{ form.notes.id_for_label }}" class="form-label">
                                {% trans "Assessment Notes" %}
                            </label>
                            {{ form.notes }}
                            {% if form.notes.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.notes.errors }}</p>
                            {% endif %}
                        </div>

                        <div class="mb-6">
                            <label for="{{ form.evidence_summary.id_for_label }}" class="form-label">
                                {% trans "Evidence Summary" %}
                            </label>
                            {{ form.evidence_summary }}
                            {% if form.evidence_summary.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.evidence_summary.errors }}</p>
                            {% endif %}
                        </div>

                        <button type="submit" class="hh-btn hh-btn-primary">
                            <i data-lucide="save" class="w-4 h-4"></i>
                            {% trans "Save Assessment" %}
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <div class="lg:col-span-1 space-y-6">
            <!-- Department -->
            <div class="form-section p-0 overflow-hidden">
                <div class="section-header">
                    <div class="section-icon bg-navy/10">
                        <i data-lucide="building" class="w-5 h-5 text-navy"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-navy m-0">{% trans "Department" %}</h5>
                </div>
                <div class="p-6 pt-0">
                    <p class="text-sm font-semibold text-navy mb-1">{{ compliance.department.name }}</p>
                    {% if compliance.department.hospital %}
                    <p class="text-xs text-slate">{{ compliance.department.hospital.name }}</p>
                    {% endif %}
                </div>
            </div>

            <!-- Evidence Attachments -->
            <div class="form-section p-0 overflow-hidden">
                <div class="section-header">
                    <div class="section-icon bg-blue/10">
                        <i data-lucide="file-text" class="w-5 h-5 text-blue"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-navy m-0 flex-1">{% trans "Evidence Attachments" %}</h5>
                    <a href="{% url 'standards:attachment_upload' compliance_id=compliance.id %}"
                       class="hh-btn hh-btn-primary text-xs py-1.5 px-3">
                        <i data-lucide="upload" class="w-3 h-3"></i>
                        {% trans "Upload" %}
                    </a>
                </div>
                <div class="p-0">
                    {% if compliance.attachments.all %}
                    <ul class="divide-y divide-slate-100">
                        {% for attachment in compliance.attachments.all %}
                        <li class="px-4 py-3 hover:bg-slate-50 transition">
                            <div class="flex items-center justify-between">
                                <div class="flex items-center flex-1 min-w-0">
                                    <i data-lucide="file" class="w-4 h-4 text-slate flex-shrink-0"></i>
                                    <span class="ml-2 text-sm font-medium text-navy truncate">{{ attachment.filename }}</span>
                                </div>
                                <span class="ml-2 text-xs text-slate flex-shrink-0">
                                    {{ attachment.uploaded_at|date:"Y-m-d" }}
                                </span>
                            </div>
                        </li>
                        {% endfor %}
                    </ul>
                    {% else %}
                    <div class="text-center py-8 text-slate">
                        <i data-lucide="file-x" class="w-8 h-8 mx-auto mb-2 text-slate-300"></i>
                        <p class="text-xs">{% trans "No attachments" %}</p>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    lucide.createIcons();
    
    const formInputs = document.querySelectorAll('input[type="text"], input[type="date"], select, textarea');
    formInputs.forEach(input => {
        if (!input.classList.contains('form-control')) {
            input.classList.add('form-control');
        }
    });
});
</script>
{% endblock %}
