@extends('layouts.app')

@section('title', 'HR Finance')
@section('heading', 'HR Finance')

@section('content')
@php $currency = config('app.currency_symbol', '₹'); @endphp

@include('finance.top-submenu')

<div class="mb-5">
    <p class="text-sm text-slate-600">Operational finance — expenses, salary advances, and F&amp;F. Treasury cash accounts are managed by the Finance team.</p>
</div>

<div class="mb-6 grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
    <a href="{{ route('expenses.index', ['scope' => 'company', 'status' => 'pending']) }}"
       class="rounded-2xl border border-slate-200/70 bg-white p-5 shadow-sm transition hover:border-primary/30 hover:bg-primary/5">
        <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Pending expenses</p>
        <p class="mt-2 text-3xl font-semibold text-slate-900">{{ $stats['pending_expenses'] ?? 0 }}</p>
        <p class="mt-1 text-xs text-slate-500">{{ $currency }}{{ number_format($stats['pending_expenses_amount'] ?? 0, 2) }}</p>
        <p class="mt-2 text-sm text-primary">Review claims →</p>
    </a>
    <a href="{{ route('pre-payments.index') }}"
       class="rounded-2xl border border-slate-200/70 bg-white p-5 shadow-sm transition hover:border-primary/30 hover:bg-primary/5">
        <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Active advance repayments</p>
        <p class="mt-2 text-3xl font-semibold text-slate-900">{{ $stats['pending_advances'] ?? 0 }}</p>
        <p class="mt-2 text-sm text-primary">Manage advances →</p>
    </a>
    @if(auth()->user()?->hasPermission('hr_operations_view'))
        <a href="{{ route('offboardings.index') }}"
           class="rounded-2xl border border-slate-200/70 bg-white p-5 shadow-sm transition hover:border-primary/30 hover:bg-primary/5">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">F&amp;F awaiting action</p>
            <p class="mt-2 text-3xl font-semibold text-slate-900">{{ $stats['fnf_awaiting_action'] ?? 0 }}</p>
            <p class="mt-2 text-sm text-primary">Open offboarding →</p>
        </a>
    @endif
</div>

<x-card>
    <div class="mb-4 flex items-center justify-between">
        <h2 class="text-sm font-semibold text-slate-800">Recent pending expenses</h2>
        <a href="{{ route('expenses.index', ['scope' => 'company', 'status' => 'pending']) }}" class="inline-flex items-center gap-1 text-sm font-medium text-primary hover:underline">
            View all <i class="bi bi-chevron-right text-[10px]"></i>
        </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">Category</th>
                <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Amount</th>
                <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Date</th>
            </tr>
        </x-slot>
        @forelse($stats['recent_pending_expenses'] ?? [] as $expense)
            <tr>
                <td class="px-4 py-3 text-sm text-slate-900">{{ $expense->claimant?->name ?? '—' }}</td>
                <td class="px-4 py-3 text-sm text-slate-700">{{ $expense->category }}</td>
                <td class="px-4 py-3 text-sm font-medium text-slate-900">{{ $currency }}{{ number_format((float) $expense->amount, 2) }}</td>
                <td class="px-4 py-3 text-sm text-slate-600">{{ $expense->date?->format('d M Y') }}</td>
            </tr>
        @empty
            <tr><td colspan="4" class="p-0">
                @include('finance.partials.empty-state', [
                    'title' => 'No pending expenses',
                    'description' => 'Company-wide reimbursement claims awaiting action will show here.',
                    'actionUrl' => route('expenses.index', ['scope' => 'company']),
                    'actionLabel' => 'Open expense list',
                    'icon' => 'bi-cash-stack',
                ])
            </td></tr>
        @endforelse
    </x-table>
</x-card>
@endsection
