{% extends 'portal_base.html' %}
{% load static i18n %}

{% block title %}{% trans "Candidate Dashboard" %} - ATS{% endblock %}

{% block content %}
<div class="container-fluid">
    <!-- Dashboard Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    <div class="row align-items-center">
                        <div class="col-md-6">
                            <h4 class="mb-1">
                                <i class="fas fa-user-tie me-2 text-primary"></i>
                                {% trans "Welcome" %} {{ candidate.first_name }}
                            </h4>
                            <p class="text-muted mb-0">
                                {% trans "Manage your applications and profile" %}
                            </p>
                        </div>
                        {% comment %} <div class="col-md-6 text-md-end">
                            <span class="badge bg-success fs-6">
                                <i class="fas fa-circle me-1"></i>
                                {% trans "Active" %}
                            </span>
                        </div> {% endcomment %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Quick Stats -->
    <div class="row mb-4">
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="fas fa-briefcase fa-2x text-primary"></i>
                    </div>
                    <h5 class="card-title">{{ candidate.job.title|default:"No Job" }}</h5>
                    <p class="text-muted small mb-0">
                        {% trans "Applied Position" %}
                    </p>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="fas fa-tasks fa-2x text-info"></i>
                    </div>
                    <h5 class="card-title">{{ candidate.stage|default:"Applied" }}</h5>
                    <p class="text-muted small mb-0">
                        {% trans "Current Stage" %}
                    </p>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="fas fa-calendar fa-2x text-success"></i>
                    </div>
                    <h5 class="card-title">{{ candidate.created_at|date:"M d, Y" }}</h5>
                    <p class="text-muted small mb-0">
                        {% trans "Application Date" %}
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- Profile Information -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">
                        <i class="fas fa-user me-2"></i>
                        {% trans "Profile Information" %}
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold">
                                {% trans "Full Name" %}
                            </label>
                            <p class="form-control-plaintext">
                                {{ candidate.first_name }} {{ candidate.last_name }}
                            </p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold">
                                {% trans "Email Address" %}
                            </label>
                            <p class="form-control-plaintext">
                                {{ candidate.email }}
                            </p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold">
                                {% trans "Phone Number" %}
                            </label>
                            <p class="form-control-plaintext">
                                {{ candidate.phone|default:"Not provided" }}
                            </p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold">
                                {% trans "Resume" %}
                            </label>
                            <p class="form-control-plaintext">
                                {% if candidate.resume %}
                                    <a href="{{ candidate.resume.url }}" class="btn btn-sm btn-outline-primary" target="_blank">
                                        <i class="fas fa-download me-1"></i>
                                        {% trans "Download Resume" %}
                                    </a>
                                {% else %}
                                    <span class="text-muted">{% trans "No resume uploaded" %}</span>
                                {% endif %}
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Applications Section -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">
                        <i class="fas fa-briefcase me-2"></i>
                        {% trans "My Applications" %}
                    </h5>
                </div>
                <div class="card-body">
                    {% if applications %}
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>{% trans "Job Title" %}</th>
                                        <th>{% trans "Department" %}</th>
                                        <th>{% trans "Applied Date" %}</th>
                                        <th>{% trans "Current Stage" %}</th>
                                        <th>{% trans "Status" %}</th>
                                        <th>{% trans "Actions" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for application in applications %}
                                    <tr>
                                        <td>
                                            <strong>{{ application.job.title }}</strong>
                                            {% if application.job.department %}
                                                <br><small class="text-muted">{{ application.job.department }}</small>
                                            {% endif %}
                                        </td>
                                        <td>{{ application.job.department|default:"-" }}</td>
                                        <td>{{ application.created_at|date:"M d, Y" }}</td>
                                        <td>
                                            <span class="badge bg-{{ application.stage|lower }} text-white">
                                                {{ application.get_stage_display }}
                                            </span>
                                        </td>
                                        <td>
                                            {% if application.stage == "Hired" %}
                                                <span class="badge bg-success">{% trans "Hired" %}</span>
                                            {% elif application.stage == "Rejected" %}
                                                <span class="badge bg-danger">{% trans "Rejected" %}</span>
                                            {% elif application.stage == "Offer" %}
                                                <span class="badge bg-info">{% trans "Offer Extended" %}</span>
                                            {% else %}
                                                <span class="badge bg-warning">{% trans "In Progress" %}</span>
                                            {% endif %}
                                        </td>
                                        <td>
                                            <a href="{% url 'candidate_application_detail' application.slug %}"
                                               class="btn btn-sm btn-outline-primary">
                                                <i class="fas fa-eye me-1"></i>
                                                {% trans "View Details" %}
                                            </a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <div class="text-center py-4">
                            <i class="fas fa-briefcase fa-3x text-muted mb-3"></i>
                            <h5 class="text-muted">{% trans "No Applications Yet" %}</h5>
                            <p class="text-muted">
                                {% trans "You haven't applied to any positions yet. Browse available jobs and submit your first application!" %}
                            </p>
                            <a href="{% url 'kaauh_career' %}" class="btn btn-primary">
                                <i class="fas fa-search me-2"></i>
                                {% trans "Browse Jobs" %}
                            </a>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <!-- Actions -->
    <div class="row">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    <div class="row text-center">
                        <div class="col-md-4 mb-3">
                            <button class="btn btn-outline-primary w-100">
                                <i class="fas fa-edit me-2"></i>
                                {% trans "Edit Profile" %}
                            </button>
                        </div>
                        <div class="col-md-4 mb-3">
                            <button class="btn btn-outline-success w-100">
                                <i class="fas fa-file-upload me-2"></i>
                                {% trans "Update Resume" %}
                            </button>
                        </div>
                        <div class="col-md-4 mb-3">
                            <a href="{% url 'kaauh_career' %}" class="btn btn-outline-info w-100">
                                <i class="fas fa-search me-2"></i>
                                {% trans "Browse Jobs" %}
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
