{% extends 'base.html' %}
{% load static %}

{% block title %}Leave Request - {{ leave.staff.get_full_name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">Leave Request Detail</h1>
            <p class="text-muted">{{ leave.staff.get_full_name }} &bull; {{ leave.get_leave_type_display }}</p>
        </div>
        <div class="btn-group">
            <a href="{% url 'staff:leave_list' %}" class="btn btn-outline-secondary">
                <i class="fas fa-arrow-left me-2"></i>Back
            </a>
            {% if leave.status == 'pending' %}
            <a href="{% url 'staff:leave_edit' leave.pk %}" class="btn btn-warning">
                <i class="fas fa-edit me-2"></i>Edit
            </a>
            {% endif %}
        </div>
    </div>

    <div class="row">
        <div class="col-md-8">
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">Leave Information</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Staff Member</label>
                            <p class="fw-bold">{{ leave.staff.user.get_full_name }}</p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Employee ID</label>
                            <p class="fw-bold">{{ leave.staff.employee_id }}</p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Leave Type</label>
                            <p class="fw-bold">{{ leave.get_leave_type_display }}</p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Status</label>
                            <p>
                                <span class="badge bg-{% if leave.status == 'approved' %}success{% elif leave.status == 'rejected' %}danger{% elif leave.status == 'cancelled' %}secondary{% else %}warning{% endif %} fs-6">
                                    {{ leave.get_status_display }}
                                </span>
                            </p>
                        </div>
                        <div class="col-md-4 mb-3">
                            <label class="text-muted small">Start Date</label>
                            <p class="fw-bold">{{ leave.start_date|date:"d M Y" }}</p>
                        </div>
                        <div class="col-md-4 mb-3">
                            <label class="text-muted small">End Date</label>
                            <p class="fw-bold">{{ leave.end_date|date:"d M Y" }}</p>
                        </div>
                        <div class="col-md-4 mb-3">
                            <label class="text-muted small">Days Requested</label>
                            <p class="fw-bold">{{ leave.days_requested }} day{{ leave.days_requested|pluralize }}</p>
                        </div>
                        <div class="col-12 mb-3">
                            <label class="text-muted small">Reason</label>
                            <p>{{ leave.reason }}</p>
                        </div>
                        {% if leave.remarks %}
                        <div class="col-12 mb-3">
                            <label class="text-muted small">Admin Remarks</label>
                            <p class="fst-italic text-muted">{{ leave.remarks }}</p>
                        </div>
                        {% endif %}
                        {% if leave.approved_by %}
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Approved/Rejected By</label>
                            <p class="fw-bold">{{ leave.approved_by.user.get_full_name }}</p>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="text-muted small">Decision Date</label>
                            <p class="fw-bold">{{ leave.approved_date|date:"d M Y" }}</p>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            {% if leave.status == 'pending' and request.user.is_staff %}
            <div class="card shadow mb-4 border-success">
                <div class="card-header bg-success text-white">
                    <h6 class="m-0"><i class="fas fa-gavel me-2"></i>Actions</h6>
                </div>
                <div class="card-body">
                    <form method="post" action="{% url 'staff:leave_detail' leave.pk %}">
                        {% csrf_token %}
                        <div class="mb-3">
                            <label class="form-label">Remarks</label>
                            <textarea name="remarks" class="form-control" rows="3" placeholder="Optional remarks..."></textarea>
                        </div>
                        <div class="d-grid gap-2">
                            <button type="submit" name="action" value="approve" class="btn btn-success">
                                <i class="fas fa-check me-2"></i>Approve
                            </button>
                            <button type="submit" name="action" value="reject" class="btn btn-danger">
                                <i class="fas fa-times me-2"></i>Reject
                            </button>
                        </div>
                    </form>
                </div>
            </div>
            {% endif %}

            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">Request Info</h6>
                </div>
                <div class="card-body">
                    <p class="mb-1 small text-muted">Submitted</p>
                    <p class="fw-bold">{{ leave.created_at|date:"d M Y H:i" }}</p>
                    <p class="mb-1 small text-muted">Last Updated</p>
                    <p class="fw-bold">{{ leave.updated_at|date:"d M Y H:i" }}</p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
