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

{% block title %}{% trans "Government Ticket" %} {{ ticket.ticket_number }} - 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);
    }
    .info-card {
        background: white;
        border-radius: 1rem;
        border: 2px solid #e2e8f0;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        overflow: hidden;
    }
    .info-card-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;
    }
    .info-row {
        display: flex;
        justify-content: space-between;
        padding: 0.75rem 1.5rem;
        border-bottom: 1px solid #f1f5f9;
    }
    .info-row:last-child {
        border-bottom: none;
    }
    .info-label {
        font-size: 0.875rem;
        font-weight: 600;
        color: #64748b;
    }
    .info-value {
        font-size: 0.875rem;
        color: #1e293b;
    }
    .status-badge {
        display: inline-flex;
        align-items: center;
        padding: 0.25rem 0.75rem;
        border-radius: 9999px;
        font-size: 0.75rem;
        font-weight: 500;
    }
    .status-pending { background: #fef3c7; color: #92400e; }
    .status-in_progress { background: #dbeafe; color: #1e40af; }
    .status-resolved { background: #d1fae5; color: #065f46; }
    .status-closed { background: #f3f4f6; color: #374151; }
    .btn-transition {
        transition: all 0.2s ease-in-out;
    }
</style>
{% endblock %}

{% block content %}
<div class="px-6 py-4">
    <!-- Page Header -->
    <div class="page-header-gradient">
        <div class="flex justify-between items-center">
            <div>
                <div class="flex items-center gap-3 mb-2">
                    <span class="inline-flex items-center px-3 py-1 rounded-lg text-sm font-semibold bg-white/20 text-white">
                        {{ ticket.ticket_number }}
                    </span>
                    <span class="status-badge status-{{ ticket.status }}">
                        {{ ticket.get_status_display }}
                    </span>
                    {% if ticket.converted_to_complaint %}
                    <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800">
                        <i data-lucide="check-circle" class="w-3 h-3 me-1"></i>{% trans "Converted" %}
                    </span>
                    {% endif %}
                </div>
                <h1 class="text-2xl font-bold">{% trans "Government Ticket" %}</h1>
                <p class="text-blue-100 text-sm">{{ ticket.source.name_en }}</p>
            </div>
            <div class="flex gap-2">
                <a href="{% url 'complaints:government_ticket_list' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-white/10 border-2 border-white/30 text-white font-medium rounded-xl hover:bg-white hover:text-navy transition">
                    <i data-lucide="arrow-left" class="w-4 h-4 me-2"></i>{% trans "Back to List" %}
                </a>
            </div>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Main Info -->
        <div class="lg:col-span-2 space-y-6">
            <!-- Complainant Info -->
            <div class="info-card">
                <div class="info-card-header">
                    <i data-lucide="user" class="w-5 h-5 text-navy"></i>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Complainant Information" %}</h5>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Name" %}</span>
                    <span class="info-value">{{ ticket.complainant_name }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "National ID" %}</span>
                    <span class="info-value">{{ ticket.national_id|default:"-" }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Contact Number" %}</span>
                    <span class="info-value">{{ ticket.contact_number|default:"-" }}</span>
                </div>
            </div>

            <!-- Location & Section -->
            <div class="info-card">
                <div class="info-card-header">
                    <i data-lucide="map-pin" class="w-5 h-5 text-navy"></i>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Location & Section" %}</h5>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Department" %}</span>
                    <span class="info-value">{{ ticket.department.name_en|default:"-" }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Location Type" %}</span>
                    <span class="info-value">{{ ticket.department.location_type|default:"-" }}</span>
                </div>
            </div>

            <!-- Content -->
            <div class="info-card">
                <div class="info-card-header">
                    <i data-lucide="file-text" class="w-5 h-5 text-navy"></i>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Ticket Content" %}</h5>
                </div>
                <div class="p-6">
                    <p class="text-sm text-gray-600 mb-2"><strong>{% trans "Classification:" %}</strong> {{ ticket.classification|default:"-" }}</p>
                    <div class="bg-gray-50 rounded-lg p-4">
                        <p class="text-sm text-gray-800 whitespace-pre-wrap">{{ ticket.content }}</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Sidebar -->
        <div class="lg:col-span-1 space-y-6">
            <!-- Actions -->
            <div class="info-card">
                <div class="info-card-header">
                    <i data-lucide="zap" class="w-5 h-5 text-navy"></i>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Actions" %}</h5>
                </div>
                <div class="p-4 space-y-2">
                    <a href="{% url 'complaints:government_ticket_update' pk=ticket.pk %}" 
                       class="btn-transition w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-navy text-white font-medium rounded-xl hover:bg-blue transition">
                        <i data-lucide="edit-2" class="w-4 h-4"></i>{% trans "Edit Ticket" %}
                    </a>
                    
                    {% if not ticket.converted_to_complaint %}
                    <a href="{% url 'complaints:convert_to_complaint' pk=ticket.pk %}" 
                       class="btn-transition w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-green-500 text-white font-medium rounded-xl hover:bg-green-600 transition">
                        <i data-lucide="refresh-cw" class="w-4 h-4"></i>{% trans "Convert to Complaint" %}
                    </a>
                    {% else %}
                    <a href="{% url 'complaints:complaint_detail' pk=ticket.complaint.pk %}" 
                       class="btn-transition w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-100 text-blue-700 font-medium rounded-xl hover:bg-blue-200 transition">
                        <i data-lucide="external-link" class="w-4 h-4"></i>{% trans "View Complaint" %}
                    </a>
                    {% endif %}
                </div>
            </div>

            <!-- Metadata -->
            <div class="info-card">
                <div class="info-card-header">
                    <i data-lucide="info" class="w-5 h-5 text-navy"></i>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Metadata" %}</h5>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Received Date" %}</span>
                    <span class="info-value">{{ ticket.received_date|date:"Y-m-d H:i" }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Assigned To" %}</span>
                    <span class="info-value">{{ ticket.assigned_to.get_full_name|default:"-" }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Created" %}</span>
                    <span class="info-value">{{ ticket.created_at|date:"Y-m-d H:i" }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">{% trans "Updated" %}</span>
                    <span class="info-value">{{ ticket.updated_at|date:"Y-m-d H:i" }}</span>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
