@php
    $pickerId = $pickerId ?? ('coaParentPicker_' . uniqid());
    $inputName = $inputName ?? 'parent_id';
    $inputValue = $inputValue ?? '';
    $placeholder = $placeholder ?? '— No Parent (Top Level) —';
    $allowAddNew = !empty($allowAddNew);
    $compact = !empty($compact);
@endphp
<div class="coa-parent-picker {{ $compact ? 'coa-parent-picker--compact' : '' }}"
     id="{{ $pickerId }}"
     data-coa-parent-picker
     data-placeholder="{{ $placeholder }}">
    <input type="hidden"
           name="{{ $inputName }}"
           value="{{ $inputValue }}"
           class="coa-parent-picker-input">
    <button type="button"
            class="coa-parent-picker-toggle form-select text-start"
            aria-haspopup="listbox"
            aria-expanded="false">
        <span class="coa-parent-picker-label">{{ $placeholder }}</span>
        <i class="bi bi-chevron-down coa-parent-picker-caret"></i>
    </button>
    <div class="coa-parent-picker-menu d-none">
        <div class="coa-parent-picker-search">
            <i class="bi bi-search"></i>
            <input type="search"
                   class="form-control form-control-sm coa-parent-picker-search-input"
                   placeholder="Search by code or name…"
                   autocomplete="off">
        </div>
        <div class="coa-parent-picker-columns">
            <span></span>
            <span>Code</span>
            <span>Name</span>
            <span>Type</span>
        </div>
        <div class="coa-parent-picker-tree" role="listbox"></div>
        <div class="coa-parent-picker-empty d-none">No matching accounts</div>
        <div class="coa-parent-picker-actions">
            @if($allowAddNew)
            <button type="button" class="btn btn-link btn-sm p-0 coa-parent-picker-add">Add New</button>
            @endif
            <button type="button" class="btn btn-link btn-sm p-0 coa-parent-picker-clear ms-auto">Clear</button>
        </div>
    </div>
</div>
