@php
    $queryBase = request()->only([
        'debit_note', 'q', 'client_name', 'debit_note_number', 'status', 'city',
        'issued_from', 'issued_to', 'amount_min', 'amount_max', 'item_name',
    ]);
@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">
            <span class="text-truncate">Filter Debit Notes</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:300px">
            <form method="GET" action="{{ route('admin.debit-notes.index') }}">
                @foreach(collect($queryBase)->except([
                    'client_name', 'debit_note_number', 'status', 'city',
                    'issued_from', 'issued_to', 'amount_min', 'amount_max', 'item_name', 'q',
                ]) as $key => $val)
                    @if($val && $val !== 'all')<input type="hidden" name="{{ $key }}" value="{{ $val }}">@endif
                @endforeach
                <div class="mb-2">
                    <label class="form-label small mb-1">Client/Vendor name</label>
                    <input type="text" name="client_name" class="form-control form-control-sm" value="{{ $filters['client_name'] ?? '' }}">
                </div>
                <div class="mb-2">
                    <label class="form-label small mb-1">Debit Note no</label>
                    <input type="text" name="debit_note_number" class="form-control form-control-sm" value="{{ $filters['debit_note_number'] ?? '' }}">
                </div>
                <div class="mb-2">
                    <label class="form-label small mb-1">Status</label>
                    <select name="status" class="form-select form-select-sm">
                        <option value="all">All</option>
                        @foreach($statuses as $key => $meta)
                            <option value="{{ $key }}" @selected(($filters['status'] ?? 'all') === $key)>{{ $meta['label'] }}</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.debit-notes.index', collect($queryBase)->only(['debit_note'])->filter()->all()) }}" class="btn btn-light btn-sm">Clear</a>
                </div>
            </form>
        </div>
    </div>
    <a href="{{ route('admin.debit-notes.create') }}" class="btn btn-new-client" title="New debit note">
        <i class="ri-add-line"></i><span class="d-none d-xl-inline ms-1">New</span>
    </a>
</div>
