@extends('layouts.app')

@section('title', 'Offboarding')
@section('heading', 'Offboarding')

@section('content')
@include('hr.top-submenu')
    <x-card>
        <div class="mb-4 flex justify-between items-center">
            <p class="text-slate-600">Exit management with clearance checklist and F&F settlement.</p>
            <a href="{{ route('offboardings.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">Start offboarding</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">LWD</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Type</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">F&F</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
            </x-slot>
            @forelse($offboardings as $o)
                <tr>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-900">{{ $o->user?->name ?? '—' }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $o->last_working_date?->format('M d, Y') ?? $o->offboarding_date?->format('M d, Y') }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ str_replace('_', ' ', $o->type) }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm capitalize text-slate-600">{{ str_replace('_', ' ', $o->status ?? '—') }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">
                        @if($o->fnfSettlement)
                            ₹{{ number_format((float) $o->fnfSettlement->net_payable, 0) }}
                            <span class="text-xs text-slate-400">({{ $o->fnfSettlement->status }})</span>
                        @else
                            —
                        @endif
                    </td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm">
                        <a href="{{ route('offboardings.show', $o) }}" class="font-medium text-primary hover:underline">Open</a>
                    </td>
                </tr>
            @empty
                <tr><td colspan="6" class="px-4 py-8 text-center text-sm text-slate-500">No offboarding records yet.</td></tr>
            @endforelse
        </x-table>
        @if($offboardings->hasPages())<div class="mt-4">{{ $offboardings->links() }}</div>@endif
    </x-card>
@endsection
