// #region Imports
import { ElementValueAccessorBase } from '../../../../../Forms/Accessors/Abstracts/ElementValueAccessorBase';
// #endregion
/**
 * The `ColorEditorSwatchElementValueAccessor` class provides form value accessor
 * functionality for the `ColorEditorSwatchElement`, enabling two-way binding
 * between the color swatch and form controls.
 *
 * @public
 */
export class ColorEditorSwatchElementValueAccessor extends ElementValueAccessorBase {
    // #region Methods
    /**
     * Called when the host element is connected to the DOM.
     * Sets up event listeners for color changes.
     *
     * @public
     */
    hostConnected() {
        this.host.on('blur', () => this.onTouched());
        // Sync the initial host value without triggering onChange, because
        // the host element may already have a value before the accessor is connected.
        void this.host.updateComplete.then(() => {
            this.writeValue(this.host.color);
        });
    }
    /**
     * Writes a value to the host element.
     *
     * @public
     * @override
     * @param value - The color value to write.
     */
    writeValue(value) {
        super.writeValue(value);
        this.host.color = value ?? '#ff0000';
    }
    /**
     * Resets the host element to its default value.
     *
     * @public
     * @override
     */
    resetValue() {
        super.resetValue();
        this.host.color = '#ff0000';
    }
}
/**
 * Factory function to create a `ColorEditorSwatchElementValueAccessor` instance.
 *
 * @public
 */
export const colorEditorSwatchElementValueAccessor = (host) => new ColorEditorSwatchElementValueAccessor(host);
//# sourceMappingURL=ColorEditorSwatchElementValueAccessor.js.map