@php
    $queryBase = request()->only(['client', 'view', 'from', 'to', 'txn', 'sort', 'dir', 'q', 'company_name', 'contact_name', 'email', 'phone', 'city']);
@endphp
<div class="billing-clients-sidebar__toolbar">
    <div class="dropdown flex-grow-1">
        <button type="button" class="btn btn-filter-clients dropdown-toggle w-100" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" id="btn-toggle-client-filters-panel">
            <span class="text-truncate">Filter Clients / Customers</span>
            @if($hasFilters)<span class="billing-filter-dot"></span>@endif
        </button>
        <div class="dropdown-menu billing-clients-filter-menu shadow p-3 w-100" style="min-width:280px">
            <form method="GET" action="{{ route('admin.customers.index') }}">
                @foreach(collect($queryBase)->except(['company_name', 'contact_name', 'email', 'phone', 'city', 'q']) as $key => $val)
                    @if($val)<input type="hidden" name="{{ $key }}" value="{{ $val }}">@endif
                @endforeach
                <div class="mb-2">
                    <label class="form-label small mb-1">Company name</label>
                    <input type="text" name="company_name" class="form-control form-control-sm" value="{{ $filters['company_name'] ?? '' }}">
                </div>
                <div class="mb-2">
                    <label class="form-label small mb-1">Contact name</label>
                    <input type="text" name="contact_name" class="form-control form-control-sm" value="{{ $filters['contact_name'] ?? '' }}">
                </div>
                <div class="mb-2">
                    <label class="form-label small mb-1">Email</label>
                    <input type="text" name="email" class="form-control form-control-sm" value="{{ $filters['email'] ?? '' }}">
                </div>
                <div class="mb-2">
                    <label class="form-label small mb-1">Phone</label>
                    <input type="text" name="phone" class="form-control form-control-sm" value="{{ $filters['phone'] ?? '' }}">
                </div>
                <div class="mb-3">
                    <label class="form-label small mb-1">City</label>
                    <select name="city" class="form-select form-select-sm">
                        <option value="">All cities</option>
                        @foreach($cities as $city)
                            <option value="{{ $city }}" @selected(($filters['city'] ?? '') === $city)>{{ $city }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-success btn-sm flex-grow-1">Apply</button>
                    <a href="{{ route('admin.customers.index', collect($queryBase)->only(['client', 'view', 'from', 'to', 'txn', 'sort', 'dir'])->filter()->all()) }}" class="btn btn-light btn-sm">Clear</a>
                </div>
            </form>
        </div>
    </div>
    <a href="{{ route('admin.customers.create') }}" class="btn btn-new-client" title="Add new client">
        <i class="ri-add-line"></i><span class="d-none d-xl-inline ms-1">New</span>
    </a>
    <div class="dropdown">
        <button type="button" class="btn btn-sort-menu" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false" title="Sort clients">
            <i class="ri-menu-line"></i>
        </button>
        <div class="dropdown-menu dropdown-menu-end billing-sort-dropdown shadow p-0">
            @include('admin.customers.partials.sort-menu', ['showTableLink' => true])
        </div>
    </div>
</div>
