// #region Imports
// #endregion
/**
 * @public
 * @abstract
 */
export class ElementValidatorBase {
    // #region Fields
    _host;
    _messageResolver;
    _observer;
    _onChange;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `ElementValidatorBase` class.
     *
     * @public
     */
    constructor(host, messageResolver) {
        this._host = host;
        this._messageResolver = messageResolver ?? null;
        this._onChange = (_value) => {
            console.log('ElementValidatorBase.registerOnValidatorChange');
        };
        this._observer = new MutationObserver(() => {
            // this._onChange();
            console.log('ElementValidatorBase._observer');
        });
    }
    /**
     * Returns the element that the validator is attached to.
     *
     * @protected
     * @readonly
     */
    get host() {
        return this._host;
    }
    /**
     * Returns the message resolver function.
     *
     * @protected
     * @readonly
     */
    get messageResolver() {
        return this._messageResolver;
    }
    /**
     * @public
     */
    hostConnected() {
        this._observer.observe(this.host, {
            attributes: true,
            attributeFilter: this.attributes
        });
    }
    /**
     * @public
     */
    hostDisconnected() {
        this._observer.disconnect();
    }
    /**
     * @public
     */
    registerOnValidatorChange(fn) {
        this._onChange = fn;
    }
    /**
     * @protected
     */
    getMessage(error) {
        let message = null;
        for (const [, v] of Object.entries(error ?? {})) {
            if (Array.isArray(v)) {
                message = this._messageResolver?.(v[1]) ?? null;
                break;
            }
        }
        message ??= this._messageResolver?.({}) ?? null;
        if (error) {
            return [error, message];
        }
        return null;
    }
}
//# sourceMappingURL=ElementValidatorBase.js.map