{% extends "base.html" %}

{% block title %}Leave Requests | MediHR HRMS{% endblock %}

{% block content %}
<div class="top-bar">
    <div>
        <h1 class="h4 fw-bold mb-1">Leave Requests</h1>
        <p class="text-muted small mb-0">Manage and track employee leave applications.</p>
    </div>
    <a href="/admin/core/leaverequest/add/" class="btn btn-primary btn-sm rounded-pill px-3">
        <i class="fas fa-plus me-1"></i> New Request
    </a>
</div>

<div class="table-card">
    <div class="table-responsive">
        <table class="table table-hover align-middle mb-0">
            <thead>
                <tr>
                    <th>Employee</th>
                    <th>Type</th>
                    <th>Duration</th>
                    <th>Reason</th>
                    <th>Status</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                {% for leave in leaves %}
                <tr>
                    <td>
                        <div class="fw-bold">{{ leave.employee.first_name }} {{ leave.employee.last_name }}</div>
                        <div class="text-muted small">ID: {{ leave.employee.employee_id }}</div>
                    </td>
                    <td><span class="badge bg-info-subtle text-info border border-info-subtle">{{ leave.leave_type.name }}</span></td>
                    <td>
                        <div class="small fw-500 text-dark">{{ leave.start_date }}</div>
                        <div class="text-muted small">to {{ leave.end_date }}</div>
                    </td>
                    <td><div class="text-truncate" style="max-width: 200px;" title="{{ leave.reason }}">{{ leave.reason }}</div></td>
                    <td>
                        {% if leave.status == 'pending' %}
                        <span class="badge bg-warning text-dark">Pending</span>
                        {% elif leave.status == 'approved' %}
                        <span class="badge bg-success">Approved</span>
                        {% else %}
                        <span class="badge bg-danger">Rejected</span>
                        {% endif %}
                    </td>
                    <td>
                        <a href="/admin/core/leaverequest/{{ leave.id }}/change/" class="btn btn-sm btn-light border">
                            <i class="fas fa-edit"></i>
                        </a>
                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="6" class="text-center py-5 text-muted">No leave requests found.</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
