<div wire:init="loadSolicitors">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1">Solicitors</h1>
            <p class="text-muted mb-0">Manage your solicitor records</p>
        </div>

        <div>
            <a href="{{ route('solicitors.create') }}" class="btn btn-primary">
                Add Solicitor
            </a>
        </div>
    </div>

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

    <div class="card shadow-sm">
        <div class="card-body">
            <div class="row g-3 mb-3">
                <div class="col-md-8">
                    <label class="form-label">Search</label>
                    <input
                            type="text"
                            class="form-control"
                            placeholder="Search by name, domain, email or phone..."
                            wire:model.live.debounce.300ms="search"
                    >
                </div>

                <div class="col-md-4">
                    <label class="form-label">Per Page</label>
                    <select class="form-select" wire:model.live="perPage">
                        <option value="10">10</option>
                        <option value="25">25</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                    </select>
                </div>
            </div>

            @if (! $readyToLoad)
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                        <tr>
                            <th>Name</th>
                            <th>Domain</th>
                            <th>Email Address</th>
                            <th>Phone Number</th>
                            <th class="text-end">Actions</th>
                        </tr>
                        </thead>
                        <tbody>
                        @for ($i = 0; $i < 5; $i++)
                            <tr>
                                <td><span class="placeholder col-8"></span></td>
                                <td><span class="placeholder col-6"></span></td>
                                <td><span class="placeholder col-8"></span></td>
                                <td><span class="placeholder col-6"></span></td>
                                <td class="text-end"><span class="placeholder col-8"></span></td>
                            </tr>
                        @endfor
                        </tbody>
                    </table>
                </div>
            @elseif ($solicitors->count())
                <div class="table-responsive">
                    <table class="table table-hover align-middle">
                        <thead>
                        <tr>
                            <th>Name</th>
                            <th>Domain</th>
                            <th>Email Address</th>
                            <th>Phone Number</th>
                            <th class="text-end">Actions</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($solicitors as $solicitor)
                            <tr wire:key="solicitor-{{ $solicitor->id }}">
                                <td>{{ $solicitor->name }}</td>
                                <td>{{ $solicitor->domain ?: '—' }}</td>
                                <td>{{ $solicitor->email_address ?: '—' }}</td>
                                <td>{{ $solicitor->phone_number ?: '—' }}</td>
                                <td class="text-end">
                                    <div class="btn-group">
                                        <a
                                                href="{{ route('solicitors.show', $solicitor) }}"
                                                class="btn btn-sm"
                                        >
                                            <i class="mdi mdi-eye text-primary"></i>
                                        </a>

                                        <a
                                                href="{{ route('solicitors.edit', $solicitor) }}"
                                                class="btn btn-sm"
                                        >
                                            <i class="mdi mdi-pencil"></i>
                                        </a>

                                        <button
                                                type="button"
                                                class="btn btn-sm "
                                                wire:click="delete({{ $solicitor->id }})"
                                                onclick="confirm('Are you sure you want to delete this solicitor?') || event.stopImmediatePropagation()"
                                        >
                                            <i class="mdi mdi-trash-can text-danger"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>

                <div>
                    {{ $solicitors->links() }}
                </div>
            @else
                <div class="text-center py-4">
                    <p class="text-muted mb-3">No solicitors found.</p>

                    <a href="{{ route('solicitors.create') }}" class="btn btn-primary">
                        Create First Solicitor
                    </a>
                </div>
            @endif
        </div>
    </div>
</div>