"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IssueData = exports.ControlRenderContext = void 0;
// todo: assume this is a sub store
const IDesignValidationProvider_1 = require("@appglue/common/dist/Common/IDesignValidationProvider");
const FormDesignConstants_1 = require("./FormDesignConstants");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
class ControlRenderContext {
    editContext;
    runtimeIssues = [];
    designIssues = [];
    control;
    selected = false;
    constructor(control, editContext) {
        this.control = control;
        this.editContext = editContext;
    }
    getRuntimeIssueText() {
        let issueText = null;
        if (this.runtimeIssues && this.runtimeIssues.length !== 0) {
            if (this.runtimeIssues.length === 1) {
                issueText = this.runtimeIssues[0].issue;
            }
            else {
                issueText = "Issues (" + this.runtimeIssues.length + ")";
            }
        }
        return issueText;
    }
    getDesignIssueText() {
        let issueText = null;
        if (this.designIssues && this.designIssues.length !== 0) {
            if (this.designIssues.length === 1) {
                issueText = this.designIssues[0].issue;
            }
            else {
                issueText = "Issues (" + this.designIssues.length + ")";
            }
        }
        return issueText;
    }
    getRuntimeIssueData() {
        if (this.editContext.mode !== FormDesignConstants_1.FormMode.Runtime)
            return null;
        if (this.runtimeIssues.length === 0)
            return null;
        // do not return if we are not in runtime mode
        if (this.editContext && this.editContext.mode !== FormDesignConstants_1.FormMode.Runtime)
            return null;
        let highestLevel = IDesignValidationProvider_1.ValidationLevel.WARNING;
        for (let issue of this.runtimeIssues) {
            if (issue.level === IDesignValidationProvider_1.ValidationLevel.ERROR) {
                highestLevel = IDesignValidationProvider_1.ValidationLevel.ERROR;
                break;
            }
        }
        return { text: this.getRuntimeIssueText(), highestLevel: highestLevel, issues: this.runtimeIssues };
    }
    getDesignIssueData() {
        if (this.designIssues.length === 0)
            return null;
        let highestLevel = IDesignValidationProvider_1.ValidationLevel.WARNING;
        for (let issue of this.designIssues) {
            if (issue.level === IDesignValidationProvider_1.ValidationLevel.ERROR) {
                highestLevel = IDesignValidationProvider_1.ValidationLevel.ERROR;
                break;
            }
        }
        return { text: this.getDesignIssueText(), highestLevel: highestLevel, issues: this.designIssues };
    }
    setSelected(selected) {
        this.selected = selected;
        StateManager_1.StateManager.changed(this);
    }
}
exports.ControlRenderContext = ControlRenderContext;
class IssueData {
    text = null;
    highestLevel = IDesignValidationProvider_1.ValidationLevel.ERROR;
    issues;
}
exports.IssueData = IssueData;
//# sourceMappingURL=ControlRenderContext.js.map