"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ValidatePropsController: ()=>ValidatePropsController
});
const compare_utils_cjs_namespaceObject = require("../../../utils/compare-utils.cjs");
class ValidatePropsController {
    hostConnected() {
        if (null === this.host.error) this.host.error = void 0;
    }
    hostUpdate() {
        if (this.host.error && this.host.error !== this.lastValidationError) return;
        this.currentProps = this.getProps();
        if ((0, compare_utils_cjs_namespaceObject.deepEqual)(this.currentProps, this.previousProps)) return;
        this.host.error = void 0;
        this.validateProps();
    }
    validateProps() {
        try {
            this.schema.validate(this.currentProps);
        } catch (error) {
            if (this.throwOnError) {
                this.host.error = error;
                this.lastValidationError = error;
            } else {
                const message = `Prop validation failed for component ${this.host.tagName?.toLowerCase()}: ${error.message}`;
                console.warn(message, this.host);
            }
        } finally{
            this.previousProps = this.currentProps;
        }
    }
    constructor(host, getProps, schema, throwOnError = true){
        this.host = host;
        this.getProps = getProps;
        this.schema = schema;
        this.throwOnError = throwOnError;
        host.addController(this);
    }
}
exports.ValidatePropsController = __webpack_exports__.ValidatePropsController;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ValidatePropsController"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
