/**
 * Copyright Aquera Inc 2025
 *
 * This source code is licensed under the BSD-3-Clause license found in the
 * LICENSE file in the root directory of this source tree.
 */
export class ComboboxSelectionManager {
    static createOptionsFromValues(value, data, getDisplayText, getItemValue) {
        if (!value || (Array.isArray(value) && value.length === 0)) {
            return [];
        }
        const values = Array.isArray(value) ? value : [value];
        const valueFn = getItemValue || ((item) => item?.value ?? item);
        return values.map(valueItem => {
            const item = data.find((d) => {
                const iv = valueFn(d);
                return String(iv) === String(valueItem);
            });
            const displayText = item ? getDisplayText(item) : valueItem;
            return {
                value: valueItem,
                selected: true,
                getTextLabel: () => {
                    if (typeof displayText === 'string' && /<[^>]+>/.test(displayText)) {
                        const div = document.createElement('div');
                        div.innerHTML = displayText;
                        return div.textContent || div.innerText || '';
                    }
                    return displayText;
                },
            };
        });
    }
    static toggleMultiValue(currentValues, optionValue) {
        if (currentValues.includes(optionValue)) {
            return currentValues.filter(v => v !== optionValue);
        }
        return [...currentValues, optionValue];
    }
    static removeValue(currentValues, removeValue) {
        return currentValues.filter(v => v !== removeValue);
    }
}
//# sourceMappingURL=selection-manager.js.map