@extends('layouts.user')

@section('title', __('Employee_Bonus.bonus_report'))
@section('page_title', __('Employee_Bonus.bonus_report'))
@section('breadcrumb', __('Employee_Bonus.hr_payroll'))

@section('content')
<div class="w-full px-1 sm:px-2 lg:px-3 space-y-6">

    {{-- Summary --}}
    <div class="grid grid-cols-1 gap-3 md:grid-cols-3">
        <div class="border border-slate-200 bg-white p-3 shadow-sm">
            <div class="text-xs text-slate-500">{{ __('Employee_Bonus.total_bonus') }}</div>
            <div class="mt-1 text-sm font-bold text-slate-800">
                {{ number_format((float) $summary['total_bonus'], 2) }}
            </div>
        </div>

        <div class="border border-slate-200 bg-white p-3 shadow-sm">
            <div class="text-xs text-slate-500">{{ __('Employee_Bonus.paid_bonus') }}</div>
            <div class="mt-1 text-sm font-bold text-emerald-700">
                {{ number_format((float) $summary['paid_bonus'], 2) }}
            </div>
        </div>

        <div class="border border-slate-200 bg-white p-3 shadow-sm">
            <div class="text-xs text-slate-500">{{ __('Employee_Bonus.unpaid_bonus') }}</div>
            <div class="mt-1 text-sm font-bold text-amber-700">
                {{ number_format((float) $summary['unpaid_bonus'], 2) }}
            </div>
        </div>
    </div>

    {{-- Filter --}}
    <div class="border border-slate-200 bg-white p-3 shadow-sm">
        <form method="GET" class="grid grid-cols-1 gap-2 md:grid-cols-4">

            <select name="month" class="border border-slate-200 px-3 py-2 text-xs">
                <option value="">{{ __('Employee_Bonus.all_months') }}</option>
                @for($m = 1; $m <= 12; $m++)
                    <option value="{{ $m }}" @selected(request('month') == $m)>
                        {{ sprintf('%02d', $m) }}
                    </option>
                @endfor
            </select>

            <input type="number"
                   name="year"
                   value="{{ request('year') }}"
                   placeholder="{{ __('Employee_Bonus.year') }}"
                   class="border border-slate-200 px-3 py-2 text-xs">

            <select name="status" class="border border-slate-200 px-3 py-2 text-xs">
                <option value="">{{ __('Employee_Bonus.all_status') }}</option>
                <option value="paid" @selected(request('status') === 'paid')>{{ __('Employee_Bonus.paid') }}</option>
                <option value="unpaid" @selected(request('status') === 'unpaid')>{{ __('Employee_Bonus.unpaid') }}</option>
            </select>

            <button type="submit"
                    class="bg-slate-900 px-3 py-2 text-xs font-semibold text-white">
                {{ __('Employee_Bonus.filter') }}
            </button>
        </form>
    </div>

    {{-- Table --}}
    <div class="overflow-hidden border border-slate-200 bg-white shadow-sm">
        <div class="overflow-x-auto">
            <table class="min-w-full text-xs">
                <thead class="bg-slate-50">
                    <tr class="text-left text-slate-600">
                        <th class="px-4 py-2">{{ __('Employee_Bonus.employee') }}</th>
                        <th class="px-4 py-2">{{ __('Employee_Bonus.title') }}</th>
                        <th class="px-4 py-2">{{ __('Employee_Bonus.amount') }}</th>
                        <th class="px-4 py-2">{{ __('Employee_Bonus.date') }}</th>
                        <th class="px-4 py-2">{{ __('Employee_Bonus.status') }}</th>
                        <th class="px-4 py-2">{{ __('Employee_Bonus.account') }}</th>
                    </tr>
                </thead>

                <tbody class="divide-y divide-slate-100">
                    @forelse($bonuses as $bonus)
                        <tr class="hover:bg-slate-50">
                            <td class="px-4 py-2">{{ $bonus->employee?->name }}</td>
                            <td class="px-4 py-2">{{ $bonus->title }}</td>
                            <td class="px-4 py-2 font-semibold">
                                {{ number_format((float) $bonus->amount, 2) }}
                            </td>
                            <td class="px-4 py-2">
                                {{ $bonus->bonus_date?->format('d M Y') }}
                            </td>
                            <td class="px-4 py-2">
                                {{ ucfirst($bonus->status) }}
                            </td>
                            <td class="px-4 py-2">
                                {{ $bonus->account?->account_name ?? __('Employee_Bonus.dash') }}
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="px-4 py-8 text-center text-xs text-slate-500">
                                {{ __('Employee_Bonus.no_bonus_report_found') }}
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($bonuses->hasPages())
            <div class="border-t border-slate-200 px-4 py-2">
                {{ $bonuses->links() }}
            </div>
        @endif
    </div>

</div>
@endsection