@php
    $selectedId = old('customer_id', $selectedCustomerId ?? ($inv?->customer_id ?? $quote?->customer_id ?? request('customer_id')));
    $selected = collect($customers ?? [])->firstWhere('id', (int) $selectedId);
    $label = $selected
        ? $selected->name . ($selected->city ? ' - ' . $selected->city : '')
        : 'Select Client';
@endphp
<div class="billing-client-picker billing-unit-picker billing-unit-picker--lg" data-client-picker data-placeholder="Select Client">
    <input type="hidden" name="customer_id" id="billing-customer-id" data-field="customer_id" value="{{ $selectedId }}" required>
    <button type="button" class="billing-unit-picker__trigger form-select text-start" aria-haspopup="listbox" aria-expanded="false">
        <span class="billing-unit-picker__label text-truncate {{ $selected ? '' : 'text-muted' }}" title="{{ $label }}">{{ $label }}</span>
        <i class="ri-arrow-down-s-line billing-unit-picker__arrow"></i>
    </button>
    <div class="billing-unit-picker__dropdown d-none" role="listbox">
        <div class="billing-unit-picker__search-wrap">
            <input type="text" class="form-control form-control-sm billing-unit-picker__search" placeholder="Type to search" autocomplete="off">
        </div>
        <ul class="billing-unit-picker__list billing-client-picker__list"></ul>
        <button type="button" class="billing-unit-picker__add billing-client-picker__add btn btn-link btn-sm w-100 text-start">
            <i class="ri-add-line"></i> Add new client
        </button>
    </div>
</div>
