import { AppObjectPM } from "@vived/core";
import { ToolEntity, ToolState } from "../Entities/ToolEntity";
export const defaultToolVM = {
    label: "",
    enabled: false,
    selected: false,
    show: false,
    shortcutLabel: "",
    tooltipLabel: "",
};
export class ToolPM extends AppObjectPM {
    static get(id, appObjects) {
        return appObjects.get(id)?.getComponent(ToolPM.type);
    }
}
ToolPM.type = "ToolPM";
export function makeToolPM(appObject) {
    return new ToolPMImp(appObject);
}
class ToolPMImp extends ToolPM {
    get tool() {
        return this.getCachedLocalComponent(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 === ToolState.ACTIVE || state === ToolState.ENABLED) {
                enabled = true;
            }
            const selected = state === ToolState.ACTIVE ? true : false;
            const show = state === 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