// #region Imports
import { ElementValueAccessorBase } from '../../../../../Forms/Accessors/Abstracts/ElementValueAccessorBase';
// #endregion
/**
 * The `TreeElementValueAccessor` class.
 *
 * @public
 */
export class TreeElementValueAccessor extends ElementValueAccessorBase {
    // #region Methods
    /**
     * @public
     */
    hostConnected() {
        this.host.on('selectionChanged', (e) => this.writeValue(e.detail.newValue?.value ?? null));
        this.host.on('blur', () => this.onTouched());
        // we need to set the value here because the host element may have a value before the accessor is connected
        void this.host.updateComplete.then(() => {
            this.value = this.host.selectedItem?.value ?? null;
        });
    }
    /**
     * @public
     * @override
     */
    writeValue(value) {
        super.writeValue(value);
        if (value !== null) {
            this.host.select(value);
        }
        else {
            this.host.resetSelection();
        }
    }
    /**
     * @public
     * @override
     */
    resetValue() {
        super.resetValue();
        this.host.resetSelection();
    }
}
/**
 * The `treeElementValueAccessor` function for the `TreeElement`.
 * This accessor can be bind to form field controls.
 *
 * @public
 */
export const treeElementValueAccessor = (host) => new TreeElementValueAccessor(host);
//# sourceMappingURL=TreeElementValueAccessor.js.map