<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @hotelSettings
    <title>Payroll Runs - {{ hotelName() }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-light">
<div class="container py-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="mb-0"><i class="fas fa-money-check-dollar me-2"></i>Payroll Runs</h4>
        <a href="{{ route('staff.payroll.create') }}" class="btn btn-primary">New Payroll Run</a>
    </div>

    @if(session('success')) <div class="alert alert-success">{{ session('success') }}</div> @endif
    @if(session('error')) <div class="alert alert-danger">{{ session('error') }}</div> @endif

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-dark">
                <tr>
                    <th>Run #</th>
                    <th>Period</th>
                    <th>Gross</th>
                    <th>Net</th>
                    <th>Status</th>
                    <th>Paid Date</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                @forelse($runs as $run)
                    <tr>
                        <td>{{ $run->run_number }}</td>
                        <td>{{ str_pad($run->pay_month, 2, '0', STR_PAD_LEFT) }}/{{ $run->pay_year }}</td>
                        <td>UGX {{ number_format((float)$run->gross_total, 2) }}</td>
                        <td>UGX {{ number_format((float)$run->net_total, 2) }}</td>
                        <td><span class="badge bg-{{ $run->status === 'paid' ? 'success' : ($run->status === 'approved' ? 'primary' : 'warning text-dark') }}">{{ ucfirst($run->status) }}</span></td>
                        <td>{{ optional($run->paid_date)->format('Y-m-d') ?: '-' }}</td>
                        <td><a class="btn btn-sm btn-outline-primary" href="{{ route('staff.payroll.show', $run) }}">Open</a></td>
                    </tr>
                @empty
                    <tr><td colspan="7" class="text-center py-4">No payroll runs yet.</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="card-body">{{ $runs->links() }}</div>
    </div>
</div>
</body>
</html>
