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

{% block title %}{% trans "Update Compliance" %}{% endblock %}

{% block content %}
<div class="container-fluid px-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">{% trans "Update Compliance Assessment" %}</h1>
            <p class="text-muted mb-0">{{ compliance.standard.code }} - {{ compliance.standard.title }}</p>
        </div>
        <a href="{% url 'standards:department_standards' pk=compliance.department.id %}"
           class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left me-2"></i>{% trans "Back to Standards" %}
        </a>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <!-- Standard Details -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="card-title mb-0">{% trans "Standard Details" %}</h5>
                </div>
                <div class="card-body">
                    <table class="table table-sm">
                        <tr>
                            <th width="30%">{% trans "Code" %}</th>
                            <td>{{ compliance.standard.code }}</td>
                        </tr>
                        <tr>
                            <th>{% trans "Title" %}</th>
                            <td>{{ compliance.standard.title }}</td>
                        </tr>
                        <tr>
                            <th>{% trans "Source" %}</th>
                            <td>{{ compliance.standard.source.name }}</td>
                        </tr>
                        <tr>
                            <th>{% trans "Category" %}</th>
                            <td>{{ compliance.standard.category.name }}</td>
                        </tr>
                        <tr>
                            <th>{% trans "Description" %}</th>
                            <td>{{ compliance.standard.description|linebreaks }}</td>
                        </tr>
                    </table>
                </div>
            </div>

            <!-- Compliance Form -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="card-title mb-0">{% trans "Compliance Assessment" %}</h5>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        <div class="mb-3">
                            <label for="{{ form.status.id_for_label }}" class="form-label">
                                {% trans "Status" %}
                            </label>
                            {{ form.status }}
                            {% if form.status.errors %}
                            <div class="text-danger">{{ form.status.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <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 %}
                            <div class="text-danger">{{ form.last_assessed_date.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.assessor.id_for_label }}" class="form-label">
                                {% trans "Assessor" %}
                            </label>
                            {{ form.assessor }}
                            {% if form.assessor.errors %}
                            <div class="text-danger">{{ form.assessor.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.notes.id_for_label }}" class="form-label">
                                {% trans "Assessment Notes" %}
                            </label>
                            {{ form.notes }}
                            {% if form.notes.errors %}
                            <div class="text-danger">{{ form.notes.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.evidence_summary.id_for_label }}" class="form-label">
                                {% trans "Evidence Summary" %}
                            </label>
                            {{ form.evidence_summary }}
                            {% if form.evidence_summary.errors %}
                            <div class="text-danger">{{ form.evidence_summary.errors }}</div>
                            {% endif %}
                        </div>

                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-2"></i>{% trans "Save Assessment" %}
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <!-- Department Info -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="card-title mb-0">{% trans "Department" %}</h5>
                </div>
                <div class="card-body">
                    <p><strong>{{ compliance.department.name }}</strong></p>
                    {% if compliance.department.hospital %}
                    <p class="text-muted mb-0">{{ compliance.department.hospital.name }}</p>
                    {% endif %}
                </div>
            </div>

            <!-- Evidence Attachments -->
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">{% trans "Evidence Attachments" %}</h5>
                    <a href="{% url 'standards:attachment_upload' compliance_id=compliance.id %}"
                       class="btn btn-sm btn-success">
                        <i class="fas fa-upload me-1"></i>{% trans "Upload" %}
                    </a>
                </div>
                <div class="card-body">
                    {% if compliance.attachments.all %}
                    <ul class="list-group">
                        {% for attachment in compliance.attachments.all %}
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <div>
                                <i class="fas fa-file me-2"></i>
                                {{ attachment.filename }}
                            </div>
                            <small class="text-muted">
                                {{ attachment.uploaded_at|date:"Y-m-d" }}
                            </small>
                        </li>
                        {% endfor %}
                    </ul>
                    {% else %}
                    <p class="text-muted text-center mb-0">{% trans "No attachments" %}</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
