<div>
    <x-title :breadcrumbs="[ ['link' => route('reports.tranche.index'), 'title' => 'Tranche DsarReport']]">
        Tranche Report
    </x-title>

    <!-- Stats Grid -->
    <div class="row mb-4">
        <div class="col-md-4 mb-3 mb-md-0">
            <div class="card shadow-sm border-0 text-center p-4">
                <span class="h2 font-weight-bold text-primary mb-1">{{ $stats['funded'] }}</span>
                <p class="text-muted text-uppercase small font-weight-bold mb-0">Funded Cases</p>
            </div>
        </div>
        <div class="col-md-4 mb-3 mb-md-0">
            <div class="card shadow-sm border-0 text-center p-4">
                <span class="h2 font-weight-bold text-success mb-1">{{ $stats['available'] }}</span>
                <p class="text-muted text-uppercase small font-weight-bold mb-0">Available To Fund</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card shadow-sm border-0 text-center p-4">
                <span class="h2 font-weight-bold text-warning mb-1">{{ $stats['pending'] }}</span>
                <p class="text-muted text-uppercase small font-weight-bold mb-0">Pending Availability</p>
            </div>
        </div>
    </div>

    <!-- Tranches Table -->
    <div class="card shadow-sm border-0 rounded-lg overflow-hidden">
        <div class="card-header bg-white py-3 border-bottom-0 d-flex justify-content-between align-items-center">
            <h2 class="h6 font-weight-bold mb-0 text-secondary">Tranche List</h2>
            <input wire:model.live="search" type="text" placeholder="Search tranches..."
                   class="form-control form-control-sm w-auto" style="min-width: 250px;">
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="bg-light text-secondary text-uppercase"
                       style="font-size: 0.75rem; letter-spacing: 0.05em;">
                <tr>
                    <th class="px-4 border-top-0">Funder</th>
                    <th class="px-4 border-top-0">Tranche Name</th>
                    <th class="px-4 border-top-0">Total Funding</th>
                    <th class="px-4 border-top-0 text-center">Cases</th>
                    <th class="px-4 border-top-0 text-center">Actions</th>
                </tr>
                </thead>
                <tbody class="bg-white">
                @foreach($tranches as $tranche)
                    <tr>
                        <td class="px-4 align-middle font-weight-bold text-dark">{{ $tranche->funder_name }}</td>
                        <td class="px-4 align-middle text-muted">{{ $tranche->tranche_name }}</td>
                        <td class="px-4 align-middle font-weight-bold text-success">
                            £{{ number_format($tranche->amount_per_case * $tranche->clients_count, 2) }}
                        </td>
                        <td class="px-4 align-middle text-center">
                            <span class="badge bg-primary px-3 py-2">{{ $tranche->clients_count }}</span>
                        </td>
                        <td class="px-4 align-middle text-center">
                            <a href="{{ route('reports.tranche.view', $tranche) }}"
                               class="btn btn-md">
                                <i class="mdi mdi-view-dashboard text-primary"></i>
                            </a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="card-footer bg-light border-0">
            <div class="d-flex justify-content-center">
                {{ $tranches->links() }}
            </div>
        </div>
    </div>
</div>