"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolPM = exports.defaultToolVM = void 0;
exports.makeToolPM = makeToolPM;
const core_1 = require("@vived/core");
const ToolEntity_1 = require("../Entities/ToolEntity");
exports.defaultToolVM = {
    label: "",
    enabled: false,
    selected: false,
    show: false,
    shortcutLabel: "",
    tooltipLabel: "",
};
class ToolPM extends core_1.AppObjectPM {
    static get(id, appObjects) {
        return appObjects.get(id)?.getComponent(ToolPM.type);
    }
}
exports.ToolPM = ToolPM;
ToolPM.type = "ToolPM";
function makeToolPM(appObject) {
    return new ToolPMImp(appObject);
}
class ToolPMImp extends ToolPM {
    get tool() {
        return this.getCachedLocalComponent(ToolEntity_1.ToolEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.enabled !== b.enabled)
            return false;
        if (a.label !== b.label)
            return false;
        if (a.selected !== b.selected)
            return false;
        if (a.show !== b.show)
            return false;
        if (a.shortcutLabel !== b.shortcutLabel)
            return false;
        if (a.tooltipLabel !== b.tooltipLabel)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, ToolPM.type);
        this.onToolChange = () => {
            if (!this.tool)
                return;
            const { state, label, shortcutLabel } = this.tool;
            let enabled = false;
            if (state === ToolEntity_1.ToolState.ACTIVE || state === ToolEntity_1.ToolState.ENABLED) {
                enabled = true;
            }
            const selected = state === ToolEntity_1.ToolState.ACTIVE ? true : false;
            const show = state === ToolEntity_1.ToolState.HIDDEN ? false : true;
            const tooltipLabel = `${label} [${shortcutLabel}]`;
            const vm = {
                enabled,
                label,
                selected,
                show,
                shortcutLabel,
                tooltipLabel,
            };
            this.doUpdateView(vm);
        };
        this.tool?.addChangeObserver(this.onToolChange);
        this.onToolChange();
    }
}
//# sourceMappingURL=ToolPM.js.map