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

{% block title %}{% trans "Comment Imports" %} - PX360{% 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);
    }
    .section-card {
        background: white;
        border-radius: 1rem;
        border: 2px solid #e2e8f0;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        transition: all 0.3s ease;
    }
    .section-card:hover {
        border-color: #005696;
        box-shadow: 0 10px 25px -5px rgba(0, 86, 150, 0.15);
    }
    .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;
    }
    .section-icon {
        width: 40px;
        height: 40px;
        border-radius: 0.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>
{% endblock %}

{% block content %}
<div class="page-header-gradient">
    <div class="flex justify-between items-center">
        <div>
            <h1 class="text-2xl font-bold mb-1">{% trans "Step 0 — Comment Imports" %}</h1>
            <p class="text-blue-100 text-sm">{% trans "Monthly patient comment data imports from IT department" %}</p>
        </div>
    </div>
</div>

<div class="section-card">
    <div class="section-header flex items-center justify-between">
        <div class="flex items-center gap-3">
            <div class="section-icon bg-blue-500/10">
                <i data-lucide="upload" class="w-5 h-5 text-blue-600"></i>
            </div>
            <h5 class="text-lg font-semibold text-gray-800">{% trans "Import History" %}</h5>
        </div>
    </div>
    <div class="p-0">
        <table class="w-full text-left border-collapse">
            <thead class="bg-slate-50 border-b uppercase text-[10px] font-bold text-slate tracking-wider">
                <tr>
                    <th class="px-6 py-4">{% trans "Hospital" %}</th>
                    <th class="px-6 py-4">{% trans "Year" %}</th>
                    <th class="px-6 py-4">{% trans "Month" %}</th>
                    <th class="px-6 py-4">{% trans "Status" %}</th>
                    <th class="px-6 py-4">{% trans "Total Rows" %}</th>
                    <th class="px-6 py-4">{% trans "Imported" %}</th>
                    <th class="px-6 py-4">{% trans "Errors" %}</th>
                    <th class="px-6 py-4">{% trans "Imported By" %}</th>
                    <th class="px-6 py-4">{% trans "Date" %}</th>
                </tr>
            </thead>
            <tbody class="text-sm divide-y divide-slate-100">
                {% for imp in imports %}
                <tr class="hover:bg-slate-50/50 transition-colors">
                    <td class="px-6 py-4 font-semibold text-gray-800">{{ imp.hospital }}</td>
                    <td class="px-6 py-4 text-slate-600">{{ imp.year }}</td>
                    <td class="px-6 py-4 text-slate-600">{{ imp.month }}</td>
                    <td class="px-6 py-4">
                        {% if imp.status == 'completed' %}
                        <span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase bg-green-100 text-green-700">{% trans "Completed" %}</span>
                        {% elif imp.status == 'failed' %}
                        <span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase bg-red-100 text-red-700">{% trans "Failed" %}</span>
                        {% elif imp.status == 'processing' %}
                        <span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase bg-yellow-100 text-yellow-700">{% trans "Processing" %}</span>
                        {% else %}
                        <span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase bg-slate-100 text-slate-600">{% trans "Pending" %}</span>
                        {% endif %}
                    </td>
                    <td class="px-6 py-4 text-slate-600">{{ imp.total_rows }}</td>
                    <td class="px-6 py-4 text-slate-600">{{ imp.imported_count }}</td>
                    <td class="px-6 py-4 {% if imp.error_count > 0 %}text-red-600 font-semibold{% else %}text-slate-600{% endif %}">{{ imp.error_count }}</td>
                    <td class="px-6 py-4 text-slate-600">{{ imp.imported_by.get_full_name|default:"—" }}</td>
                    <td class="px-6 py-4 text-slate-500">{{ imp.created_at|date:"Y-m-d H:i" }}</td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="9" class="px-6 py-12 text-center">
                        <i data-lucide="inbox" class="w-12 h-12 mx-auto text-slate-300 mb-3"></i>
                        <p class="text-slate">{% trans "No imports yet." %}</p>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
