// #region Imports
import { ElementValueAccessorBase } from '../../../../../Forms/Accessors/Abstracts/ElementValueAccessorBase';
// #endregion
/**
 * The `ToggleSwitchElementValueAccessor` class.
 *
 * @public
 */
export class ToggleSwitchElementValueAccessor extends ElementValueAccessorBase {
    // #region Methods
    /**
     * @public
     */
    hostConnected() {
        this.host.on('checked', () => this.value = true);
        this.host.on('unchecked', () => this.value = false);
        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.isChecked);
        });
    }
    /**
     * @public
     * @override
     */
    writeValue(value) {
        super.writeValue(value);
        this.host.isChecked = value;
    }
    /**
     * @public
     * @override
     */
    resetValue() {
        super.resetValue();
        this.host.reset();
    }
}
/**
 * @public
 */
export const toggleSwitchElementValueAccessor = (host) => new ToggleSwitchElementValueAccessor(host);
//# sourceMappingURL=ToggleSwitchElementValueAccessor.js.map