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

{% block title %}{% trans "Convert to QI Project" %} - PX360{% endblock %}

{% block content %}
<!-- Back Button -->
<div class="mb-6">
    <a href="{% url 'actions:action_detail' pk=action.pk %}" class="inline-flex items-center gap-2 text-slate hover:text-navy transition">
        <i data-lucide="arrow-left" class="w-4 h-4"></i>
        <span class="text-sm font-medium">{% trans "Back to Action" %}</span>
    </a>
</div>

<!-- Header -->
<header class="mb-6">
    <h1 class="text-2xl font-bold text-navy flex items-center gap-3">
        <i data-lucide="arrow-right-circle" class="w-7 h-7 text-blue"></i>
        {% trans "Convert PX Action to QI Project" %}
    </h1>
    <p class="text-sm text-slate mt-1">{% trans "Transform this action into a formal Quality Improvement project" %}</p>
</header>

<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 border shadow-sm overflow-hidden">
            <div class="px-6 py-4 border-b bg-slate-50">
                <h2 class="text-sm font-bold text-navy flex items-center gap-2">
                    <i data-lucide="file-plus" class="w-4 h-4"></i>
                    {% trans "Project Details" %}
                </h2>
            </div>
            <div class="p-6">
                <form method="post" novalidate>
                    {% csrf_token %}
                    
                    <!-- Template Selection -->
                    <div class="mb-5">
                        <label for="{{ form.template.id_for_label }}" class="block text-sm font-semibold text-navy mb-2">
                            {% trans "Project Template" %}
                        </label>
                        {{ form.template }}
                        {% if form.template.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.template.errors.0 }}</p>
                        {% endif %}
                        <p class="mt-1 text-xs text-slate">{% trans "Select a template to pre-fill project details, or leave blank for empty project" %}</p>
                    </div>

                    <!-- Project Name -->
                    <div class="mb-5">
                        <label for="{{ form.project_name.id_for_label }}" class="block text-sm font-semibold text-navy mb-2">
                            {% trans "Project Name" %} <span class="text-red-500">*</span>
                        </label>
                        {{ form.project_name }}
                        {% if form.project_name.errors %}
                            <p class="mt-1 text-xs text-red-600">{{ form.project_name.errors.0 }}</p>
                        {% endif %}
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-5">
                        <!-- Project Lead -->
                        <div>
                            <label for="{{ form.project_lead.id_for_label }}" class="block text-sm font-semibold text-navy mb-2">
                                {% trans "Project Lead" %} <span class="text-red-500">*</span>
                            </label>
                            {{ form.project_lead }}
                            {% if form.project_lead.errors %}
                                <p class="mt-1 text-xs text-red-600">{{ form.project_lead.errors.0 }}</p>
                            {% endif %}
                        </div>
                        
                        <!-- Target Completion Date -->
                        <div>
                            <label for="{{ form.target_completion_date.id_for_label }}" class="block text-sm font-semibold text-navy mb-2">
                                {% trans "Target Completion Date" %}
                            </label>
                            {{ form.target_completion_date }}
                            {% if form.target_completion_date.errors %}
                                <p class="mt-1 text-xs text-red-600">{{ form.target_completion_date.errors.0 }}</p>
                            {% endif %}
                        </div>
                    </div>

                    <!-- Submit Buttons -->
                    <div class="flex items-center gap-3 mt-6 pt-6 border-t">
                        <button type="submit" class="bg-green-600 text-white px-5 py-2.5 rounded-xl text-sm font-bold flex items-center gap-2 hover:bg-green-700 transition">
                            <i data-lucide="kanban" class="w-4 h-4"></i>
                            {% trans "Create QI Project" %}
                        </button>
                        <a href="{% url 'actions:action_detail' pk=action.pk %}" class="bg-white text-slate border border-slate-200 px-5 py-2.5 rounded-xl text-sm font-bold hover:bg-slate-50 transition">
                            {% trans "Cancel" %}
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Sidebar - Action Summary -->
    <div class="lg:col-span-1">
        <div class="bg-white rounded-2xl border shadow-sm overflow-hidden">
            <div class="px-6 py-4 border-b bg-blue/5">
                <h2 class="text-sm font-bold text-navy flex items-center gap-2">
                    <i data-lucide="info" class="w-4 h-4"></i>
                    {% trans "PX Action Details" %}
                </h2>
            </div>
            <div class="px-6 py-4 space-y-4">
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Title" %}</p>
                    <p class="text-sm text-navy font-medium">{{ action.title }}</p>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Hospital" %}</p>
                    <p class="text-sm text-navy font-medium">{{ action.hospital.name }}</p>
                </div>
                {% if action.department %}
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Department" %}</p>
                    <p class="text-sm text-navy font-medium">{{ action.department.name }}</p>
                </div>
                {% endif %}
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Priority" %}</p>
                    <span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[10px] font-bold uppercase
                        {% if action.priority == 'critical' %}bg-red-100 text-red-700
                        {% elif action.priority == 'high' %}bg-orange-100 text-orange-700
                        {% elif action.priority == 'medium' %}bg-yellow-100 text-yellow-700
                        {% else %}bg-slate-100 text-slate-700{% endif %}">
                        {{ action.get_priority_display }}
                    </span>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Status" %}</p>
                    <span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[10px] font-bold uppercase
                        {% if action.status == 'completed' %}bg-green-100 text-green-700
                        {% elif action.status == 'in_progress' %}bg-blue-100 text-blue-700
                        {% elif action.status == 'pending' %}bg-yellow-100 text-yellow-700
                        {% else %}bg-slate-100 text-slate-700{% endif %}">
                        {{ action.get_status_display }}
                    </span>
                </div>
                {% if action.description %}
                <div>
                    <p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Description" %}</p>
                    <p class="text-sm text-slate">{{ action.description|truncatewords:30 }}</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- Help Card -->
        <div class="bg-slate-50 rounded-2xl border border-slate-200 p-5 mt-6">
            <div class="flex items-start gap-3">
                <i data-lucide="help-circle" class="w-5 h-5 text-blue flex-shrink-0 mt-0.5"></i>
                <div>
                    <h3 class="text-sm font-bold text-navy mb-1">{% trans "What happens next?" %}</h3>
                    <p class="text-xs text-slate">{% trans "Converting this action to a QI Project will create a structured project with tasks, team members, and outcome tracking." %}</p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}