export const newBalOption = (option, options) => {
    const data = Object.assign(Object.assign({}, option), { disabled: false, invalid: false, selected: false, focused: false, hidden: false, multiline: false });
    if (options) {
        data.disabled = options.disabled === undefined ? data.disabled : options.disabled;
        data.invalid = options.invalid === undefined ? data.invalid : options.invalid;
        data.selected = options.selected === undefined ? data.selected : options.selected;
        data.focused = options.focused === undefined ? data.focused : options.focused;
        data.hidden = options.hidden === undefined ? data.hidden : options.hidden;
        data.multiline = options.multiline === undefined ? data.multiline : options.multiline;
    }
    return data;
};
export const mapOption = (option) => {
    return newBalOption({
        value: option.value,
        label: option.label,
    }, option);
};
export class DropdownOptionUtil {
    connectedCallback(component) {
        this.component = component;
        this.optionChanged();
    }
    async componentWillRender() {
        if (this.component.listEl) {
            this.component.nativeOptions = await this.component.listEl.getValues();
        }
    }
    hasPropOptions() {
        return this.component.options && this.component.options.length > 0;
    }
    async optionChanged() {
        this.component.rawOptions = this.component.options.map(mapOption);
        await this.component.valueUtil.updateInputContent();
    }
    async listenToOptionChange(ev) {
        var _a;
        const newSelectedValues = (await ((_a = this.component.listEl) === null || _a === void 0 ? void 0 : _a.getSelectedValues())) || [];
        this.component.valueUtil.updateRawValueBySelection(newSelectedValues);
        if (!this.component.multiple) {
            this.component.popupUtil.collapseList();
            if (this.component.hasFocus) {
                this.component.balBlur.emit(new FocusEvent('blur', { relatedTarget: this.component.el }));
                this.component.hasFocus = false;
            }
        }
    }
}
