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

{% block title %}{{ observation.tracking_code }} - {% trans "Department Response" %} - PX360{% endblock %}

{% block content %}
<header class="mb-6">
    <div class="flex items-center gap-2 text-sm text-slate mb-2">
        <a href="{% url 'observations:observation_list' %}" class="hover:text-navy">{% trans "Observations" %}</a>
        <i data-lucide="chevron-right" class="w-4 h-4"></i>
        <a href="{% url 'observations:observation_detail' pk=observation.pk %}" class="hover:text-navy">{{ observation.tracking_code }}</a>
        <i data-lucide="chevron-right" class="w-4 h-4"></i>
        <span class="font-bold text-navy">{% trans "Department Response" %}</span>
    </div>
    <h1 class="text-2xl font-bold text-navy">
        {% if observation.title %}{{ observation.title }}{% else %}{{ observation.description|truncatewords:10 }}{% endif %}
    </h1>
</header>

<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6">
    <div class="flex items-center gap-2 mb-4">
        <i data-lucide="message-square" class="w-5 h-5 text-navy"></i>
        <h2 class="text-lg font-bold text-navy">{% trans "Submit Department Response" %}</h2>
    </div>

    <div class="bg-slate-50 rounded-xl p-4 border border-slate-200 mb-6">
        <p class="text-[10px] text-slate-500 uppercase font-bold mb-1">{% trans "Reference" %}</p>
        <p class="font-mono text-sm font-bold text-navy">{{ observation.tracking_code }}</p>
        <p class="text-[10px] text-slate-500 uppercase font-bold mb-1 mt-3">{% trans "Description" %}</p>
        <p class="text-sm text-slate-700 leading-relaxed">{{ observation.description|truncatewords:50 }}</p>
    </div>

    {% if messages %}
    <div class="mb-4">
        {% for message in messages %}
        <div class="px-4 py-3 rounded-lg text-sm font-semibold {% if message.tags == 'error' %}bg-red-50 text-red-700 border border-red-200{% else %}bg-green-50 text-green-700 border border-green-200{% endif %}">
            {{ message }}
        </div>
        {% endfor %}
    </div>
    {% endif %}

    <form method="post" action="{% url 'observations:observation_department_response' pk=observation.pk %}">
        {% csrf_token %}

        <div class="space-y-4">
            <div>
                <label class="block text-sm font-semibold text-slate-700 mb-2">
                    {% trans "Response (English)" %}
                </label>
                <textarea name="response_en" rows="5"
                    class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-slate-700 focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20 resize-none text-sm"
                    placeholder="{% trans 'Enter your response in English...' %}">{{ observation.department_response_en|default:'' }}</textarea>
            </div>

            <div>
                <label class="block text-sm font-semibold text-slate-700 mb-2">
                    {% trans "Response (Arabic)" %}
                </label>
                <textarea name="response_ar" rows="5" dir="rtl"
                    class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-slate-700 focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20 resize-none text-sm"
                    placeholder="{% trans 'أدخل ردك باللغة العربية...' %}">{{ observation.department_response_ar|default:'' }}</textarea>
            </div>

            <p class="text-xs text-slate-500">
                <i data-lucide="info" class="w-3 h-3 inline mr-1"></i>
                {% trans "At least one language is required." %}
            </p>
        </div>

        <div class="flex items-center gap-3 mt-6 pt-4 border-t border-slate-100">
            <button type="submit"
                class="px-6 py-2.5 bg-navy text-white font-semibold rounded-xl hover:bg-blue transition flex items-center gap-2 text-sm">
                <i data-lucide="send" class="w-4 h-4"></i>
                {% trans "Submit Response" %}
            </button>
            <a href="{% url 'observations:observation_detail' pk=observation.pk %}"
                class="px-6 py-2.5 bg-slate-100 text-slate-700 font-medium rounded-xl hover:bg-slate-200 transition text-sm">
                {% trans "Cancel" %}
            </a>
        </div>
    </form>
</div>
{% endblock %}
