import { nothing, PropertyValues, TemplateResult } from 'lit'; import { BahtFieldBase } from '../field-base.js'; import { ReferenceOption } from '../../core/types.js'; export type { ReferenceOption } from '../../core/types.js'; /** * The lookup a field-mode picker talks to: `registry.references[field.reference]` with the * form's data already bound by ``. */ export interface FieldReferenceLookup { search: (term: string) => ReferenceOption[] | Promise; resolve?: (id: string) => ReferenceOption | null | Promise; } /** * Reference lookup: read-only input + magnifier opening a typeahead dropdown. * The host supplies the data via `fetcher(term)`; the component owns the * debounce, the dropdown, and the keyboard interaction. * * const el = document.createElement('baht-reference-picker'); * el.fetcher = (term) => api.search('sys_user', term); // Promise * el.value = '6816f79cc0a8016401c5a33be04be441'; * el.display = 'Abel Tuter'; * el.addEventListener('baht-change', (e) => onPick(e.detail)); // { value, label } * * Clearing emits `baht-change` with `{ value: '', label: '' }`. Set `href` to * render an open-record link next to the lookup button. * * **Form field** (`type: 'reference'`, set by ``): `lookup` replaces `fetcher` / * `display` — `` binds `registry.references[field.reference]` with the form data. * The value is the picked record's id (`null` when cleared), emitted as * `baht-input { key, value }`; an existing id is shown by `lookup.resolve(id)`'s label (or * raw, without a resolver). Field label / help / error as for every field. * * @fires baht-change - Standalone mode: a record was picked or cleared. `detail: { value, label }`. * @fires baht-input - Field mode: a record was picked or cleared. `detail: { key, value }`. */ export declare class BahtReferencePicker extends BahtFieldBase { /** Accessible name for the combobox + its option list (standalone; a field uses its label). */ label: string; /** Selected id (the reference's key). Field mode: `string | null`. */ value: unknown; /** Human-readable label for `value`; falls back to showing the raw id. */ display: string; placeholder: string; /** Marks the control invalid (styles + aria-invalid). */ invalid: boolean; /** Optional link to the selected record, rendered as an external-link button. */ href: string; /** Accessible name for the lookup button. */ lookupLabel: string; /** Debounce for search calls, ms (default 200). */ debounce?: number; /** Async search: term in, options out. Required for the dropdown to work (standalone). */ fetcher: ((term: string) => Promise) | null; /** Field mode: the record lookup (set by `` from `registry.references`). */ lookup: FieldReferenceLookup | null; private labels; private resolving; private open; private term; private options; private loading; private activeIndex; private inputEl; private get listboxId(); private timer; private fetchSeq; private readonly onDocMousedown; disconnectedCallback(): void; private get isField(); private get locked(); private get recordId(); protected updated(changed: PropertyValues): void; /** Field mode: look up the label of an id we have not seen picked. */ private resolveLabel; private openLookup; private close; private search; private runFetch; private pick; private clear; private emitChange; private readonly onInput; private readonly onKeydown; protected render(): TemplateResult | typeof nothing; /** ARIA wiring that differs by mode: a field points at its label / help / error. */ private comboboxAria; /** What the closed input shows: the record's label when known, else its id. */ private get inputText(); protected renderControl(): TemplateResult; private renderClear; private renderList; }