// #region Imports
import { ElementValueAccessorBase } from '../../../../../Forms/Accessors/Abstracts/ElementValueAccessorBase';
// #endregion
/**
 * The `AutoCompleteBoxElementValueAccessor` class provides form value accessor
 * functionality for the `AutoCompleteBoxElement`, enabling two-way binding
 * between the autocomplete input and form controls.
 *
 * @public
 */
export class AutoCompleteBoxElementValueAccessor extends ElementValueAccessorBase {
    // #region Methods
    /**
     * Called when the host element is connected to the DOM.
     * Sets up event listeners for value changes.
     *
     * @public
     */
    hostConnected() {
        this.host.on('input', (e) => this.writeValue(e.target.value));
        this.host.on('change', (e) => this.writeValue(e.target.value));
        this.host.on('cleared', () => this.writeValue(''));
        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.value;
        });
    }
    /**
     * Writes a value to the host element.
     *
     * @public
     * @override
     * @param value - The value to write.
     */
    writeValue(value) {
        super.writeValue(value);
        this.host.value = value ?? '';
    }
    /**
     * Resets the host element to its default value.
     *
     * @public
     * @override
     */
    resetValue() {
        super.resetValue();
        this.host.value = '';
    }
}
/**
 * Factory function to create an `AutoCompleteBoxElementValueAccessor` instance.
 *
 * @public
 */
export const autoCompleteBoxElementValueAccessor = (host) => new AutoCompleteBoxElementValueAccessor(host);
//# sourceMappingURL=AutoCompleteBoxElementValueAccessor.js.map