@extends('layouts.app')

@section('title', 'Resignations')
@section('heading', 'Resignations')

@section('content')
@include('hr.top-submenu')
    <x-card>
        <div class="mb-4 flex justify-between items-center">
            <p class="text-slate-600">Employee resignations and status.</p>
            <a href="{{ route('resignations.create') }}" class="inline-flex items-center rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700"><i class="bi bi-plus-lg me-1"></i>Add Resignation</a>
        </div>
        <x-table>
            <x-slot name="head">
                <tr>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Employee</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500 whitespace-nowrap">Resignation Date</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500 whitespace-nowrap">Last Working Date</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Status</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
            </x-slot>
            @forelse($resignations as $r)
                <tr>
                    <td class="whitespace-nowrap px-4 py-3">
                        <div class="flex items-center gap-3">
                            @if($r->user)
                                <x-user-avatar :user="$r->user" size="sm" class="shrink-0" />
                            @endif
                            <span class="text-slate-900">{{ $r->user?->name ?? '—' }}</span>
                        </div>
                    </td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $r->resignation_date?->format('M d, Y') }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $r->last_working_date?->format('M d, Y') ?? '—' }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm"><x-badge :status="$r->status">{{ $r->status }}</x-badge></td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm">
                        <a href="{{ route('resignations.edit', $r) }}" class="btn-icon-action btn-icon-action--edit" title="Edit" aria-label="Edit"><i class="bi bi-pencil-square"></i></a>
                        <form action="{{ route('resignations.update-status', $r) }}" method="post" class="inline ml-2">
                            @csrf
                            <select name="status" class="text-xs rounded border border-slate-300 py-0.5 js-select2" style="width: 180px;" onchange="this.form.submit()">
                                <option value="pending" {{ $r->status === 'pending' ? 'selected' : '' }}>Pending</option>
                                <option value="approved" {{ $r->status === 'approved' ? 'selected' : '' }}>Approved</option>
                                <option value="rejected" {{ $r->status === 'rejected' ? 'selected' : '' }}>Rejected</option>
                                <option value="withdrawn" {{ $r->status === 'withdrawn' ? 'selected' : '' }}>Withdrawn</option>
                            </select>
                        </form>
                    </td>
                </tr>
            @empty
                <tr><td colspan="5" class="px-4 py-8 text-center text-sm text-slate-500">No resignations yet.</td></tr>
            @endforelse
        </x-table>
        @if($resignations->hasPages())<div class="mt-4">{{ $resignations->links() }}</div>@endif
    </x-card>
@endsection
