// todo: assume this is a sub store
import { ValidationLevel } from "../../Common/IDesignValidationProvider";
import { FormMode } from "../FormDesignConstants";
import { StateManager } from "../../CommonUI/StateManagement/StateManager";
export class ControlRenderContext {
    constructor(control, editContext) {
        this.runtimeIssues = [];
        this.designIssues = [];
        this.selected = false;
        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 !== 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 !== FormMode.Runtime)
            return null;
        let highestLevel = ValidationLevel.WARNING;
        for (let issue of this.runtimeIssues) {
            if (issue.level === ValidationLevel.ERROR) {
                highestLevel = ValidationLevel.ERROR;
                break;
            }
        }
        return { text: this.getRuntimeIssueText(), highestLevel: highestLevel, issues: this.runtimeIssues };
    }
    getDesignIssueData() {
        if (this.designIssues.length === 0)
            return null;
        let highestLevel = ValidationLevel.WARNING;
        for (let issue of this.designIssues) {
            if (issue.level === ValidationLevel.ERROR) {
                highestLevel = ValidationLevel.ERROR;
                break;
            }
        }
        return { text: this.getDesignIssueText(), highestLevel: highestLevel, issues: this.designIssues };
    }
    setSelected(selected) {
        this.selected = selected;
        StateManager.changed(this);
    }
}
export class IssueData {
    constructor() {
        this.text = null;
        this.highestLevel = ValidationLevel.ERROR;
    }
}
//# sourceMappingURL=ControlRenderContext.js.map