<div class="client-list">
    <x-title>
        Lead Sources

        <x-slot:buttons>
            @can('sources.create')
                <a wire:navigate href="{{ route('sources.create') }}" class="btn btn-success waves-effect waves-light">
                    <i class="mdi mdi-plus me-2"></i> Add Lead Source
                </a>
            @endcan
        </x-slot:buttons>
    </x-title>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">

                    <div class="row">
                        <div class="col-4">
                            <div class="mb-3">
                                <label class="form-label">Per Page</label>
                                <select class="form-select" wire:model.live="perPage">
                                    <option value="5">5</option>
                                    <option value="10">10</option>
                                    <option value="25">25</option>
                                    <option value="50">50</option>
                                    <option value="100">100</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-4"></div>
                        <div class="col-4">
                            <div class="mb-3">
                                <label class="form-label">Search</label>
                                <input type="text" class="form-control" wire:model.live="search"
                                       placeholder="search...">
                            </div>
                        </div>
                    </div>


                    <div class="table-responsive">
                        <table class="table table-centered table-striped table-nowrap mb-0">
                            <thead>
                            <tr>
                                <td>Name</td>
                                <td>Active</td>
                                <td>Created</td>
                                <td class="text-end">Tools</td>
                            </tr>
                            </thead>
                            <tbody>
                            @if(count($sources))
                                @foreach($sources as $leadSource)
                                    <tr>
                                        <td><b>{{ $leadSource->display_name }}</b></td>
                                        <td>
                                            <span class="badge {{ $leadSource->status === 'active' ? 'bg-success' : 'bg-secondary' }}">
                                                {{ ucfirst($leadSource->status) }}
                                            </span>
                                        </td>
                                        <td><b>{{ $leadSource->created_at->format("d/m/Y H:i") }}</b></td>
                                        <td class="text-end">
                                            @can('view', $leadSource)
                                                <a wire:navigate href="{{ route('sources.show', $leadSource) }}" class="btn btn-md">
                                                    <span class="mdi mdi-shield-search text-primary"></span>
                                                </a>
                                            @endcan
                                            @can('update', $leadSource)
                                                <a wire:navigate href="{{ route('sources.edit', $leadSource) }}" class="btn btn-md">
                                                    <span class="mdi mdi-pencil text-primary"></span>
                                                </a>
                                            @endcan
                                            @can('delete', $leadSource)
                                                <a wire:navigate wire:click="deleteLeadSource({{ $leadSource->id }})" class="btn btn-md">
                                                    <span class="mdi mdi-trash-can text-danger"></span>
                                                </a>
                                            @endcan
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <tr>
                                    <td colspan="5">No lead sources found.</td>
                                </tr>
                            @endif
                            </tbody>
                        </table>
                    </div>


                    {{ $sources->links() }}
                </div>
            </div>
        </div>
    </div>
</div>