@php
    $selectedParties = array_values($filters['parties'] ?? []);
    $selectedPartyLabel = $selectedPartyLabel ?? 'All names';
@endphp
<div class="pl-party-picker" id="plPartyPicker"
     data-tree='@json($filterOptions['partyTree'] ?? [])'
     data-selected='@json($selectedParties)'>
    <button type="button" class="pl-party-picker-toggle form-select text-start" id="plPartyPickerToggle" aria-haspopup="listbox" aria-expanded="false">
        <span class="pl-party-picker-label" id="plPartyPickerLabel">{{ $selectedPartyLabel }}</span>
    </button>
    <div class="pl-party-picker-menu d-none" id="plPartyPickerMenu">
        <div class="pl-party-picker-search">
            <i class="bi bi-search"></i>
            <input type="search" class="form-control form-control-sm" id="plPartyPickerSearch" placeholder="Search names..." autocomplete="off">
        </div>
        <div class="pl-party-picker-columns">
            <span></span>
            <span></span>
            <span>Code</span>
            <span>Name</span>
            <span>Type</span>
        </div>
        <div class="pl-party-picker-tree" id="plPartyPickerTree" role="listbox"></div>
        <div class="pl-party-picker-empty d-none" id="plPartyPickerEmpty">No matching names</div>
        <div class="pl-party-picker-actions">
            <button type="button" class="btn btn-link btn-sm p-0" id="plPartyPickerClear">All names</button>
        </div>
    </div>
    <div id="plPartyPickerInputs">
        @foreach($selectedParties as $partyValue)
            <input type="hidden" name="parties[]" value="{{ $partyValue }}">
        @endforeach
    </div>
</div>
