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

{% block title %}{% trans "Convert to System Complaint" %} - {{ source_complaint.reference_number }}{% endblock %}

{% block content %}
<div class="max-w-2xl mx-auto px-4 py-8">
    <div class="mb-6">
        <a href="{% url 'px_sources:source_detail' pk=source_complaint.px_source.pk %}" class="inline-flex items-center gap-2 px-4 py-2 border border-slate-200 rounded-xl text-slate-600 hover:bg-slate-50 transition text-sm font-semibold">
            <i data-lucide="arrow-left" class="w-4 h-4"></i> {% trans "Back to Source" %}
        </a>
    </div>

    <div class="bg-amber-50 border border-amber-200 rounded-2xl p-4 mb-6 flex items-start gap-3">
        <i data-lucide="info" class="w-5 h-5 text-amber-600 flex-shrink-0 mt-0.5"></i>
        <div>
            <p class="font-semibold text-amber-800">{% trans "Convert to System Complaint" %}</p>
            <p class="text-sm text-amber-700 mt-1">{% trans "Review and edit the details below before creating the system complaint. Fields are pre-filled from the source complaint." %}</p>
        </div>
    </div>

    <div class="bg-white rounded-2xl border border-slate-200 shadow-sm">
        <div class="p-6 border-b border-slate-200 bg-slate-50 rounded-t-2xl">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-xs font-bold text-slate uppercase tracking-wider">{% trans "Source Complaint" %}</p>
                    <p class="font-mono text-navy font-bold">{{ source_complaint.reference_number }}</p>
                </div>
                <div class="text-right">
                    <p class="text-xs font-bold text-slate uppercase tracking-wider">{% trans "Source" %}</p>
                    <p class="text-sm font-semibold text-navy">{{ source_complaint.px_source.get_localized_name }}</p>
                </div>
            </div>
        </div>

        <form method="post" class="p-6">
            {% csrf_token %}
            <div class="space-y-5">
                <div>
                    <label class="block text-sm font-semibold text-navy mb-2">{% trans "Title" %} <span class="text-red-500">*</span></label>
                    <input type="text" name="title" value="{{ source_complaint.subject }}" required
                           class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-sm focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20">
                </div>

                <div>
                    <label class="block text-sm font-semibold text-navy mb-2">{% trans "Description" %} <span class="text-red-500">*</span></label>
                    <textarea name="description" rows="6" required
                              class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-sm focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20 resize-none">{{ source_complaint.description }}</textarea>
                </div>

                <div>
                    <label class="block text-sm font-semibold text-navy mb-2">{% trans "Patient Name" %}</label>
                    <input type="text" name="patient_name" value="{{ source_complaint.patient_name }}"
                           class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-sm focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20">
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold text-navy mb-2">{% trans "Hospital" %}</label>
                        <select name="hospital" class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-sm focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20">
                            <option value="">—</option>
                            {% for h in hospitals %}
                            <option value="{{ h.id }}" {% if request.user.hospital and request.user.hospital.id == h.id %}selected{% endif %}>
                                {{ h.name }}
                            </option>
                            {% endfor %}
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-semibold text-navy mb-2">{% trans "Department" %}</label>
                        <select name="department" class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-sm focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20">
                            <option value="">—</option>
                            {% for d in departments %}
                            <option value="{{ d.id }}">{{ d.get_localized_name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
            </div>

            <div class="flex gap-3 mt-8">
                <a href="{% url 'px_sources:source_detail' pk=source_complaint.px_source.pk %}"
                   class="flex-1 px-6 py-3 border border-slate-200 rounded-xl font-semibold text-slate hover:bg-slate-50 transition text-center">
                    {% trans "Cancel" %}
                </a>
                <button type="submit" class="flex-1 px-6 py-3 bg-green-600 text-white rounded-xl font-semibold hover:bg-green-700 transition flex items-center justify-center gap-2">
                    <i data-lucide="arrow-right-left" class="w-4 h-4"></i> {% trans "Create System Complaint" %}
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}
