'use strict';

var index = require('./index-C_OnxXhP.js');
var index_esm = require('./index.esm-C1i_NocP.js');

const ruleGateCss = () => `:host{display:contents}:host([hidden]){display:none}`;

const RuleGate = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.shouldRender = false;
    }
    componentWillLoad() {
        this.compileAndEvaluate();
    }
    onRuleChange() {
        this.compileAndEvaluate();
    }
    onScopeChange() {
        this.compileAndEvaluate();
    }
    render() {
        return (index.h(index.Host, { key: '365df6908301371b8b964671382ad936971b6624', hidden: !this.shouldRender }, index.h("slot", { key: 'ca7c2a9febf0189dfae882a2ae894d1d0262a213' })));
    }
    get ruleRegistry() {
        return this.platform.get(index_esm.n.RuleRegistry);
    }
    compileAndEvaluate() {
        var _a;
        if (!this.rule) {
            this.shouldRender = true;
            return;
        }
        try {
            const compiled = this.ruleRegistry.compile(this.rule);
            const scope = (_a = this.scope) !== null && _a !== void 0 ? _a : this.ruleRegistry.scope({ host: this.host });
            this.shouldRender = compiled(scope);
        }
        catch (error) {
            console.warn('rule-gate failed to compile rule; hiding slot', {
                rule: this.rule,
                error,
            });
            this.shouldRender = false;
        }
    }
    get host() { return index.getElement(this); }
    static get watchers() { return {
        "rule": [{
                "onRuleChange": 0
            }],
        "scope": [{
                "onScopeChange": 0
            }]
    }; }
};
RuleGate.style = ruleGateCss();

exports.limebb_rule_gate = RuleGate;
