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 { LogicalAndRelationsMetadataLoader } from './logicalAnd.metadata';
/**
 * Logical and relations component
 */
let LogicalAndRelations = class LogicalAndRelations {
    constructor() {
        //######################### protected properties #########################
        //######################### protected methods #########################
        //######################### public properties - inputs #########################
        /**
         * Condition 1 which value will used in logical and operation
         */
        this.cond1 = false;
        /**
         * Condition 2 which value will used in logical and operation
         */
        this.cond2 = false;
        /**
         * Dynamic conditions used in logical and operation
         */
        this.dynamicConditions = {};
        //######################### public properties - dynamic outputs #########################
        /**
         * Logical and result value
         */
        this.result = false;
    }
    //######################### 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) {
            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 = false;
                    return;
                }
            }
        }
        this.result = this.cond1 && this.cond2;
    }
};
__decorate([
    DynamicOutput(),
    __metadata("design:type", Object)
], LogicalAndRelations.prototype, "result", void 0);
LogicalAndRelations = __decorate([
    DebugData({
        inputs: [
            nameof('cond1'),
            nameof('cond2'),
        ],
        outputs: [
            nameof('result'),
        ],
    }),
    PureRelationsComponent(),
    RelationsEditorMetadata(LogicalAndRelationsMetadataLoader)
], LogicalAndRelations);
export { LogicalAndRelations };
//# sourceMappingURL=logicalAnd.relations.js.map