{% extends "base.html" %}
{% load static i18n %}

{% block title %}{{ participant.name }} - Participant Details{% endblock %}

{% block customCSS %}
<style>
    /* ================================================= */
    /* THEME VARIABLES AND GLOBAL STYLES (KAAT-S Teal Theme) */
    /* ================================================= */
    :root {
        --kaauh-teal: #00636e;
        --kaauh-teal-dark: #004a53;
        --kaauh-border: #eaeff3;
        --kaauh-primary-text: #343a40;
        --kaauh-bg-light: #f8f9fa;
    }

    /* Primary Color Overrides */
    .text-primary-theme { color: var(--kaauh-teal) !important; }
    
    /* Main Action Button Style */
    .btn-main-action {
        background-color: var(--kaauh-teal);
        border-color: var(--kaauh-teal);
        color: white;
        font-weight: 600;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.6rem 1.2rem;
    }
    .btn-main-action:hover {
        background-color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* Secondary/Outline Button Styles */
    .btn-outline-secondary {
        color: var(--kaauh-teal-dark);
        border: 1px solid var(--kaauh-teal);
        font-weight: 500;
        padding: 0.6rem 1.2rem;
    }
    .btn-outline-secondary:hover {
        background-color: var(--kaauh-teal-dark);
        color: white;
        border-color: var(--kaauh-teal-dark);
    }

    /* Card enhancements */
    .card {
        border: 1px solid var(--kaauh-border);
        border-radius: 0.75rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        background-color: white;
    }

    /* Primary Header Card (For Details Page Banner) */
    .detail-header-card {
        background: linear-gradient(135deg, var(--kaauh-teal), #004d57);
        color: white;
        border-radius: 0.75rem 0.75rem 0 0;
        padding: 1.5rem 2rem;
        box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    }
    .detail-header-card h1 {
        font-weight: 700;
        font-size: 2rem;
        margin: 0;
    }
    
    /* Detail Labels */
    .detail-label {
        font-size: 0.8rem;
        font-weight: 600;
        color: #6c757d;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 0.25rem;
        display: block;
    }
    .detail-value {
        font-size: 1.1rem;
        color: var(--kaauh-primary-text);
        font-weight: 500;
    }

    /* Badge Styling for Jobs */
    .job-badge {
        font-weight: 600;
        padding: 0.4em 0.7em;
        border-radius: 0.3rem;
        background-color: var(--kaauh-teal);
        color: white;
        display: inline-block;
        margin-right: 0.5rem;
        margin-bottom: 0.5rem;
        transition: background-color 0.2s;
    }
    .job-badge:hover {
        background-color: var(--kaauh-teal-dark);
        text-decoration: none;
    }

    /* Section Separator */
    .section-title {
        color: var(--kaauh-teal-dark);
        font-weight: 600;
        font-size: 1.4rem;
        margin-bottom: 1.5rem;
    }
</style>
{% endblock %}

{% block content %}
<div class="container-fluid py-4">

    {# --- HEADER CARD WITH ACTIONS --- #}
    <div class="card mb-4 border-0" style="border-radius: 0.75rem;">
        <div class="detail-header-card">
            <div class="d-flex justify-content-between align-items-center flex-wrap">
                <div class="flex-grow-1">
                    <h1 class="mb-1">
                        <i class="fas fa-user-tag me-2"></i> 
                        {{ participant.name }}
                    </h1>
                    <p class="text-white opacity-75 mb-0">{% trans "Participant Details" %}</p>
                </div>
                
                <div class="d-flex gap-3 mt-3 mt-lg-0">
                    <a href="{% url 'participants_list' %}" class="btn btn-outline-light" title="{% trans 'Back to List' %}">
                        <i class="fas fa-arrow-left me-1"></i> {% trans "Back to List" %}
                    </a>
                    {% if user.is_staff %}
                        <a href="{% url 'participants_update' participant.slug %}" class="btn btn-main-action" title="{% trans 'Edit Participant' %}">
                            <i class="fas fa-edit me-1"></i> {% trans "Edit Profile" %}
                        </a>
                        <button type="button" class="btn btn-danger" title="{% trans 'Delete' %}"
                                data-bs-toggle="modal" data-bs-target="#deleteModal"
                                data-delete-url="{% url 'participants_delete' participant.slug %}"
                                data-item-name="{{ participant.name }}">
                            <i class="fas fa-trash-alt"></i>
                        </button>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    {# --- END HEADER CARD --- #}

    <div class="row g-4">
        
        {# --- LEFT COLUMN: CORE CONTACT AND PROFESSIONAL INFO --- #}
        <div class="col-lg-8">
            <div class="card p-4 h-100">
                <div class="card-body">
                    <h2 class="section-title mb-4">{% trans "Contact & Role Information" %}</h2>

                    <div class="row g-4">
                        {# Name (Redundant here but included for clarity) #}
                        <div class="col-md-6">
                            <span class="detail-label">{% trans "Full Name" %}</span>
                            <span class="detail-value">{{ participant.name }}</span>
                        </div>
                        
                        {# Email #}
                        <div class="col-md-6">
                            <span class="detail-label">{% trans "Email Address" %}</span>
                            <span class="detail-value text-primary-theme">{{ participant.email }}</span>
                        </div>

                        {# Phone #}
                        <div class="col-md-6">
                            <span class="detail-label">{% trans "Phone Number" %}</span>
                            <span class="detail-value">{{ participant.phone|default:"N/A" }}</span>
                        </div>

                        {# Designation #}
                        <div class="col-md-6">
                            <span class="detail-label">{% trans "Designation" %}</span>
                            <span class="detail-value">{{ participant.designation|default:"N/A" }}</span>
                        </div>
                    </div>
                    
                    <hr class="my-5">

                    {# Assigned Jobs Section #}
                    <h2 class="section-title">{% trans "Assigned Jobs" %}</h2>
                    <div class="d-flex flex-wrap">
                        {% for job in participant.jobs_participating.all %}
                            <a href="{% url 'job_detail' job.slug %}" class="job-badge text-decoration-none">
                                <i class="fas fa-briefcase me-1"></i> {{ job.title }}
                            </a>
                        {% empty %}
                            <p class="text-muted">{% trans "This participant is not currently assigned to any job." %}</p>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
        
        {# --- RIGHT COLUMN: TIMESTAMPS AND METADATA --- #}
        <div class="col-lg-4">
            <div class="card p-4 h-100 bg-light">
                <div class="card-body">
                    <h2 class="section-title mb-4">{% trans "Metadata" %}</h2>
                    
                    <div class="mb-4">
                        <span class="detail-label">{% trans "Record Created" %}</span>
                        <span class="detail-value">{{ participant.created_at|date:"F d, Y" }} ({% trans "at" %} {{ participant.created_at|time:"H:i" }})</span>
                    </div>

                    <div class="mb-4">
                        <span class="detail-label">{% trans "Last Updated" %}</span>
                        <span class="detail-value">{{ participant.updated_at|date:"F d, Y" }} ({% trans "at" %} {{ participant.updated_at|time:"H:i" }})</span>
                    </div>
                    
                    <hr class="my-4">

                    <div class="mb-2">
                        <span class="detail-label">{% trans "Total Assigned Jobs" %}</span>
                        <h3 class="fw-bold text-primary-theme">{{ participant.jobs_participating.count }}</h3>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

    {# Delete Confirmation Modal #}
    <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                      <h5 class="modal-title" id="deleteModalLabel">{% trans "Confirm Deletion" %}</h5> 
                      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <p>{% trans "Are you sure you want to delete" %} <strong id="itemName"></strong>?</p>
                    
                    <p class="text-danger">
                        <i class="fas fa-exclamation-triangle me-1"></i>
                        {% trans "This action cannot be undone." %}
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
                    <form method="post" id="deleteForm">
                        {% csrf_token %}
                        <button type="submit" class="btn btn-danger">{% trans "Delete" %}</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
 
{% endblock %}



{% block customJS %}
<script>
    // Populate Delete Modal with dynamic data
    var deleteModal = document.getElementById('deleteModal');               

    // We must check if the modal element exists before adding the listener
    if (deleteModal) {
        deleteModal.addEventListener('show.bs.modal', function (event) {
            var button = event.relatedTarget; 
            
            // Get data from the button that triggered the modal
            var deleteUrl = button.getAttribute('data-delete-url'); 
            var itemName = button.getAttribute('data-item-name'); 

            // Get modal elements
            var modalItemName = deleteModal.querySelector('#itemName');
            var deleteForm = deleteModal.querySelector('#deleteForm');

            // Set the dynamic content
            if (modalItemName) {
                modalItemName.textContent = itemName;
            }
            // Set the form action URL
            if (deleteForm) {
                deleteForm.action = deleteUrl;
            }
        });
    }
</script>
{% endblock %}