import { ITabulator } from '../../../../../../types/src/table';
import { default as Cell } from '../../core/cell/Cell';
import { default as CxOption } from '../../../../../../atoms/src/components/option/option.ts';
import { default as CxSelect } from '../../../../../../atoms/src/components/select/select.ts';
import { ListEditorParams } from '../../core/types';
import { default as Edit } from './Edit';

interface ListItem {
    element?: CxOption;
    group?: boolean;
    isFallbackOption?: boolean;
    itemParams?: any;
    label: string;
    level: number;
    options?: ListItem[];
    original: any;
    sanitizedValue: string;
    selected: boolean;
    value: string | number | boolean;
    visible: boolean;
}
interface ListParams extends ListEditorParams {
    closedByDefault?: boolean;
    emptyValue: any;
    freeWidth?: boolean;
    placeholder?: string;
    prefixElement?: HTMLElement | string;
    verticalNavigation: 'editor' | 'table' | 'hybrid';
}
type SuccessCallback = (value: any) => void;
type CancelCallback = () => void;
type OnRenderedCallback = (callback: () => void) => void;
type ListInputValues = Record<string, string> | ListItem[] | Array<string | number>;
export default class List {
    table: ITabulator;
    cell: Cell;
    params: ListParams;
    data: ListItem[];
    _itemsMap: Map<string, ListItem>;
    displayItems: ListItem[];
    currentItems: ListItem[];
    focusedItem: ListItem | null;
    input: CxSelect;
    initialValue: any;
    initialValues: string[];
    /**
     * Whether the cell is a header cell, used for header filter of type list
     */
    isHeaderFilter: boolean;
    typing: boolean;
    listIteration: number;
    lastAction: string;
    actions: {
        cancel: CancelCallback;
        success: SuccessCallback;
    };
    private readonly fetchApi;
    constructor(editor: Edit, cell: Cell, onRendered: OnRenderedCallback, success: SuccessCallback, cancel: CancelCallback, editorParams: ListEditorParams);
    /**
     * cx-select only accepts string values without spaces
     * @param value - The value to sanitize
     */
    sanitizeValue(value: any): string;
    _initializeValue(): Promise<void>;
    _getSanitizedInitialValues(initialValue: any): string[];
    _onRendered(): Promise<void>;
    clickStop(e: MouseEvent): void;
    /**
     * Refreshes {@link List._itemsMap} from {@link List.data} (O(n) once per options parse).
     */
    _rebuildItemsMap(): void;
    handleCxInputChange(): Promise<void>;
    createPrefixElement(): HTMLElement | null;
    _createSelectElement(): CxSelect;
    _initializeParams(params: ListEditorParams): ListParams;
    _bindInputEvents(input: CxSelect): void;
    _inputClick(e: MouseEvent): void;
    _inputBlur(e: FocusEvent): void;
    _inputKeyDown(e: KeyboardEvent): void;
    _keyEnter(): void;
    _keyEsc(): void;
    headerFilterInitialListGen(): void;
    rebuildOptionsList(): Promise<void>;
    _generateOptions(): Promise<ListItem[]>;
    _ajaxRequest(url: string, term: string): Promise<ListInputValues>;
    _uniqueColumnValues(field?: string): string[];
    _emptyValueCheck(value: any): boolean;
    _parseList(inputValues: ListInputValues | Record<string, any>): ListItem[];
    /**
     * Ensures a fallback option exists when `fallbackOption.value` is configured.
     * If the value is already declared in `values`, the existing item is tagged
     * with `isFallbackOption` so visual customisation (divider, prefix) still applies.
     * Otherwise a new auto-generated item is appended using the raw value as its label.
     */
    _appendFallbackOptionItem(data: ListItem[]): void;
    /**
     * Checks recursively whether grouped/flat list items already contain
     * a given sanitized option value.
     */
    _hasListItemValue(items: ListItem[], sanitizedValue: string): boolean;
    /**
     * Finds and returns the first leaf item matching the given sanitized value,
     * searching recursively through groups. Returns undefined when not found.
     */
    _findListItem(items: ListItem[], sanitizedValue: string): ListItem | undefined;
    _parseListItem(option: any, level: number): ListItem;
    _parseListGroup(option: any, level: number): ListItem;
    _sortOptions(options: ListItem[]): ListItem[];
    _sortGroup(sorter: (a: string, b: string) => number, options: ListItem[]): void;
    _defaultSortFunction(as: string, bs: string): number;
    _clearList(): void;
    _buildList(data: ListItem[]): void;
    /**
     * Builds listbox content to match cx-select grouping (see Select docs): `<small>` labels and
     * `<cx-divider>` between sections; only leaf rows are `<cx-option>`.
     */
    _appendListItemSequence(items: ListItem[]): void;
    _appendDivider(): void;
    _appendSectionLabel(label: string): void;
    _appendLeafOption(item: ListItem): void;
    formatItemLabel(item: ListItem, el: HTMLElement): HTMLElement | string;
    _cancel(): void;
    _chooseItem(item: ListItem, silent?: boolean): void;
    _getCommittedOutput(): any;
    /**
     * Resolves the selected values once so preserved fallback arrays are not
     * inserted into a single selected-option slot.
     */
    _getCommittedMultipleOutput(options: HTMLElement[]): any[];
    _getMappedOptionOutput(sanitized: string): any;
    _getPreservedInputValueOutput(value: any): any;
    _getPreservedFallbackMultipleOutput(sanitizedOptions: string[]): {
        hasValue: false;
    } | {
        hasValue: true;
        value: any[];
    };
    /**
     * Checks for a preserved unmatched editor value when the selected option is
     * the configured fallback option used for undeclared values.
     */
    _hasPreservedFallbackOptionOutput(sanitized: string): boolean;
    _hasPreservedUnmatchedInputValue(inputValues: any[], sanitizedFallbackOptionValue: string): boolean;
    _resolveValue(commitItem?: ListItem): void;
}
export {};
