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