<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @hotelSettings
    <title>{{ $payroll->run_number }} - Payroll Run</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</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">{{ $payroll->run_number }} ({{ str_pad($payroll->pay_month, 2, '0', STR_PAD_LEFT) }}/{{ $payroll->pay_year }})</h4>
        <a href="{{ route('staff.payroll.index') }}" class="btn btn-outline-secondary">Back</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="row g-3 mb-3">
        <div class="col-md-3"><div class="card"><div class="card-body"><small>Status</small><h6>{{ ucfirst($payroll->status) }}</h6></div></div></div>
        <div class="col-md-3"><div class="card"><div class="card-body"><small>Gross</small><h6>UGX {{ number_format((float)$payroll->gross_total,2) }}</h6></div></div></div>
        <div class="col-md-3"><div class="card"><div class="card-body"><small>Net</small><h6>UGX {{ number_format((float)$payroll->net_total,2) }}</h6></div></div></div>
        <div class="col-md-3"><div class="card"><div class="card-body"><small>Paid Date</small><h6>{{ optional($payroll->paid_date)->format('Y-m-d') ?: '-' }}</h6></div></div></div>
    </div>

    @if($payroll->status !== 'paid')
        <div class="card mb-3">
            <div class="card-body">
                <form method="POST" action="{{ route('staff.payroll.mark-paid', $payroll) }}" class="row g-2 align-items-end">
                    @csrf
                    <div class="col-md-4">
                        <label class="form-label">Payment Method</label>
                        <select class="form-select" name="payment_method" required>
                            <option value="bank_transfer">Bank Transfer</option>
                            <option value="cash">Cash</option>
                            <option value="mobile_money">Mobile Money</option>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Reference Number</label>
                        <input type="text" class="form-control" name="reference_number">
                    </div>
                    <div class="col-md-2 text-end">
                        <button class="btn btn-success w-100" type="submit">Mark Paid</button>
                    </div>
                </form>
            </div>
        </div>
    @endif

    <div class="card">
        <div class="table-responsive">
            <table class="table table-sm table-hover mb-0">
                <thead class="table-dark">
                <tr>
                    <th>Staff</th>
                    <th>Gross</th>
                    <th>Allowances</th>
                    <th>Deductions</th>
                    <th>Net</th>
                    <th>Status</th>
                </tr>
                </thead>
                <tbody>
                @foreach($payroll->items as $item)
                    <tr>
                        <td>{{ $item->staff->full_name ?? 'N/A' }}</td>
                        <td>UGX {{ number_format((float)$item->gross_salary,2) }}</td>
                        <td>UGX {{ number_format((float)$item->allowances,2) }}</td>
                        <td>UGX {{ number_format((float)$item->deductions,2) }}</td>
                        <td><strong>UGX {{ number_format((float)$item->net_salary,2) }}</strong></td>
                        <td>{{ ucfirst($item->status) }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
