import { __decorate, __metadata } from "tslib";
import { DebugData, DynamicOutput, PureRelationsComponent } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { nameof } from '@jscrpt/common';
import { LogicalOrRelationsMetadataLoader } from './logicalOr.metadata';
/**
 * Logical or relations component
 */
let LogicalOrRelations = class LogicalOrRelations {
    constructor() {
        //######################### protected properties #########################
        //######################### public properties - inputs #########################
        /**
         * Condition 1 which value will used in logical or operation
         */
        this.cond1 = false;
        /**
         * Condition 2 which value will used in logical or operation
         */
        this.cond2 = false;
        /**
         * Dynamic conditions used in logical and operation
         */
        this.dynamicConditions = {};
    }
    //######################### public properties - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    get relationsOptions() {
        return this.ɵRelationsOptions;
    }
    set relationsOptions(value) {
        this.ɵRelationsOptions = value;
        this.initialize();
    }
    //######################### public methods - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    ngOnChanges(changes) {
        if (nameof('cond1') in changes ||
            nameof('cond2') in changes) {
            this.evaluateResult();
        }
    }
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
    //######################### protected methods #########################
    /**
     * Initialize logical and relations
     */
    initialize() {
        if (this.relationsOptions?.properties?.length) {
            for (const name of this.relationsOptions.properties) {
                if (name) {
                    Object.defineProperty(this, name, {
                        set: function (value) {
                            this.dynamicConditions[name] = value;
                            this.evaluateResult();
                        }
                    });
                }
            }
        }
    }
    /**
     * Evaluates conditions result
     */
    evaluateResult() {
        if (this.relationsOptions?.properties?.length) {
            for (const name of this.relationsOptions.properties) {
                if (this.dynamicConditions[name]) {
                    this.result = true;
                    return;
                }
            }
        }
        this.result = this.cond1 || this.cond2;
    }
};
__decorate([
    DynamicOutput(),
    __metadata("design:type", Object)
], LogicalOrRelations.prototype, "result", void 0);
LogicalOrRelations = __decorate([
    DebugData({
        inputs: [
            nameof('cond1'),
            nameof('cond2'),
        ],
        outputs: [
            nameof('result'),
        ],
    }),
    PureRelationsComponent(),
    RelationsEditorMetadata(LogicalOrRelationsMetadataLoader)
], LogicalOrRelations);
export { LogicalOrRelations };
//# sourceMappingURL=logicalOr.relations.js.map