{% extends "ui/templates/base/layout.html" %}
{% block content %}
{% include "modules/managers/templates/managers/_manager_tabs.html" %}

<div class="space-y-6"><div class="flex flex-wrap items-center justify-between gap-3"><div><h2 class="text-xl font-semibold text-slate-900">Employee Leave Requests</h2><p class="text-sm text-slate-500">Review and approve/reject employee leave applications.</p></div><a href="/employees/leave-balances" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Leave Balances</a></div><form method="get" class="rounded-2xl border border-slate-200 bg-white p-4 shadow-soft"><div class="grid gap-3 md:grid-cols-4"><select name="employee_id" class="rounded-xl border border-slate-300 px-3 py-2 text-sm"><option value="">All employees</option>{% for emp in employees %}<option value="{{ emp.id }}" {% if selected_employee_id == emp.id %}selected{% endif %}>{{ emp.full_name }} - {{ emp.employee_code }}</option>{% endfor %}</select><select name="status" class="rounded-xl border border-slate-300 px-3 py-2 text-sm"><option value="all" {% if status == 'all' %}selected{% endif %}>All statuses</option>{% for st in statuses %}<option value="{{ st }}" {% if status == st %}selected{% endif %}>{{ st.title() }}</option>{% endfor %}</select><button class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Filter</button></div></form><div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-soft"><table class="min-w-full divide-y divide-slate-200 text-sm"><thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500"><tr><th class="px-4 py-3">Employee</th><th class="px-4 py-3">Leave</th><th class="px-4 py-3">Period</th><th class="px-4 py-3">Days</th><th class="px-4 py-3">Status</th><th class="px-4 py-3">Reason / Review</th><th class="px-4 py-3 text-right">Action</th></tr></thead><tbody class="divide-y divide-slate-100">{% for row in rows %}<tr><td class="px-4 py-3"><div class="font-medium text-slate-900">{{ row.employee.full_name if row.employee else ('Employee #' ~ row.employee_id) }}</div><div class="text-xs text-slate-500">{{ row.employee.employee_code if row.employee else '' }}</div></td><td class="px-4 py-3">{{ row.leave_type.name if row.leave_type else row.leave_type_id }}</td><td class="px-4 py-3">{{ row.from_date }} to {{ row.to_date }}</td><td class="px-4 py-3">{{ row.days }}</td><td class="px-4 py-3">{{ row.status.title() }}</td><td class="px-4 py-3 text-slate-600"><div>{{ row.reason or '-' }}</div>{% if row.review_notes %}<div class="text-xs text-slate-500">Review: {{ row.review_notes }}</div>{% endif %}</td><td class="px-4 py-3 text-right">{% if row.status == 'pending' and can_approve_employee_leave(current_user, current_user_permissions, current_user_roles) %}<form method="post" action="/employees/leave/{{ row.id }}/review" class="inline-flex gap-2"><input type="hidden" name="csrf_token" value="{{ csrf_token }}"><input type="hidden" name="status" value="approved"><button class="rounded-lg border border-emerald-300 px-3 py-1.5 text-xs font-semibold text-emerald-700 hover:bg-emerald-50">Approve</button></form><form method="post" action="/employees/leave/{{ row.id }}/review" class="inline-flex gap-2"><input type="hidden" name="csrf_token" value="{{ csrf_token }}"><input type="hidden" name="status" value="rejected"><button class="rounded-lg border border-red-300 px-3 py-1.5 text-xs font-semibold text-red-700 hover:bg-red-50">Reject</button></form>{% else %}-{% endif %}</td></tr>{% else %}<tr><td colspan="7" class="px-4 py-8 text-center text-slate-500">No leave requests found.</td></tr>{% endfor %}</tbody></table></div></div>

{% endblock %}
