<div>
    <div class="card shadow-sm mb-3">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="card-title mb-0">
                    <span class="badge bg-success me-2">W&amp;T</span> Wills &amp; Trusts Cases
                </h5>
                @can('wills-cases.create')
                    <a href="{{ route('wills-cases.create') }}"
                       class="btn btn-sm btn-outline-success">
                        <i class="mdi mdi-plus me-1"></i> New
                    </a>
                @endcan
            </div>

            @if($cases->isNotEmpty())
                <div class="table-responsive">
                    <table class="table table-sm table-centered mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>Case #</th>
                                <th>Fee Structure</th>
                                <th>IFA Referred</th>
                                <th>Opened</th>
                                <th>Status</th>
                                <th class="text-end"></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($cases as $case)
                                <tr>
                                    <td><strong>{{ $case->case_number ?? $case->displayId }}</strong></td>
                                    <td>{{ $case->fee_structure ?? '—' }}</td>
                                    <td>
                                        @if($case->ifa_referred)
                                            <span class="badge bg-info">Yes</span>
                                        @else
                                            <span class="badge bg-light text-dark">No</span>
                                        @endif
                                    </td>
                                    <td>{{ $case->opened_at ? $case->opened_at->format('d/m/Y') : '—' }}</td>
                                    <td>
                                        @if($case->is_open)
                                            <span class="badge bg-success">Open</span>
                                        @else
                                            <span class="badge bg-secondary">Closed</span>
                                        @endif
                                    </td>
                                    <td class="text-end">
                                        <a href="{{ route('wills-cases.view', $case) }}"
                                           class="text-secondary me-2" title="View">
                                            <i class="mdi mdi-eye"></i>
                                        </a>
                                        @can('edit', $case)
                                            <a href="{{ route('wills-cases.edit', $case) }}"
                                               class="text-primary" title="Edit">
                                                <i class="mdi mdi-pencil"></i>
                                            </a>
                                        @endcan
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @else
                <p class="text-muted small mb-0">No wills &amp; trusts cases on record.</p>
            @endif
        </div>
    </div>
</div>
