<x-app-layout>
    <x-slot name="header">
        <h2 class="font-bold text-2xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Sales Representative Commissions') }}
        </h2>
    </x-slot>

    <div class="py-12 bg-gray-50 dark:bg-gray-900 min-h-screen">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
            
            <!-- Report Tabs -->
            <div class="flex space-x-4 px-4 sm:px-0">
                <a href="{{ route('admin.reports.due-balances') }}" class="px-6 py-3 rounded-xl font-bold transition-all {{ request()->routeIs('admin.reports.due-balances') ? 'bg-indigo-600 text-white shadow-lg shadow-indigo-200' : 'bg-white text-gray-600 hover:bg-gray-100' }}">
                    Customer Due Balances
                </a>
                <a href="{{ route('admin.reports.commissions') }}" class="px-6 py-3 rounded-xl font-bold transition-all {{ request()->routeIs('admin.reports.commissions') ? 'bg-indigo-600 text-white shadow-lg shadow-indigo-200' : 'bg-white text-gray-600 hover:bg-gray-100' }}">
                    Sales Rep Commissions
                </a>
            </div>

            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-xl sm:rounded-2xl">
                <div class="p-8">
                    <div class="overflow-x-auto">
                        <table class="w-full text-left border-collapse">
                            <thead>
                                <tr class="bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-200">
                                    <th class="p-4 rounded-tl-xl">Sales Rep</th>
                                    <th class="p-4">Invoice #</th>
                                    <th class="p-4">Customer</th>
                                    <th class="p-4 text-right">Commission (%)</th>
                                    <th class="p-4 text-right">Amount</th>
                                    <th class="p-4 text-center rounded-tr-xl">Status</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
                                @forelse($commissions as $commission)
                                    <tr class="hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors">
                                        <td class="p-4 font-semibold text-gray-900 dark:text-white">
                                            {{ $commission->salesRep->name }}
                                        </td>
                                        <td class="p-4 text-gray-600 dark:text-gray-400">
                                            {{ $commission->sale->invoice_number }}
                                        </td>
                                        <td class="p-4 text-gray-600 dark:text-gray-400">
                                            {{ $commission->sale->customer->name }}
                                        </td>
                                        <td class="p-4 text-right text-gray-600 dark:text-gray-400">
                                            {{ number_format($commission->percentage, 1) }}%
                                        </td>
                                        <td class="p-4 text-right font-bold text-indigo-600 dark:text-indigo-400">
                                            {{ number_format($commission->commission_amount, 2) }}
                                        </td>
                                        <td class="p-4 text-center">
                                            <span class="px-3 py-1 rounded-full text-xs font-bold uppercase {{ $commission->status === 'paid' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800' }}">
                                                {{ $commission->status }}
                                            </span>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="6" class="p-8 text-center text-gray-500">No commissions recorded yet.</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                    <div class="mt-6">
                        {{ $commissions->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
