import { ToolRepository } from "../../Tools";
import { doRedo, doUndo } from "../Controllers";
import { makeUndoRedoEntity } from "../Entities";
import { makeHasRedoPM, makeHasUndoPM } from "../PM";
import { UndoRedoToolStatesHook } from "../UCs";
export function setupUndoRedo(appObjects) {
    const ao = appObjects.getOrCreate("UndoRedo");
    // Entity
    const undoRedo = makeUndoRedoEntity(ao);
    // UCs
    new UndoRedoToolStatesHook(ao);
    // PMs
    makeHasUndoPM(ao);
    makeHasRedoPM(ao);
    // Setup Tools
    const toolRepo = ToolRepository.get(appObjects);
    if (!toolRepo) {
        appObjects.submitWarning("setupHideable", "Unable to find tool repo");
        return ao;
    }
    let modifierKeyPrefix = "Ctrl";
    if (navigator.platform.indexOf("Mac") === 0 ||
        navigator.platform === "iPhone") {
        modifierKeyPrefix = "⌘";
    }
    const undoTool = toolRepo.makeToolFromData({
        toolType: "UNDO",
        isDefault: false,
        label: "Undo",
        shortcutLabel: `${modifierKeyPrefix} + z`,
        hotkeys: [
            { keyCode: "KeyZ", control: true },
            { keyCode: "KeyZ", meta: true },
        ],
    });
    undoTool.registerAction(() => doUndo(appObjects));
    const redoTool = toolRepo.makeToolFromData({
        toolType: "REDO",
        isDefault: false,
        label: "Redo",
        shortcutLabel: `${modifierKeyPrefix} + Shift + z`,
        hotkeys: [
            { keyCode: "KeyY", control: true },
            { keyCode: "KeyY", meta: true },
            { keyCode: "KeyZ", control: true, shift: true },
            { keyCode: "KeyZ", meta: true, shift: true },
        ],
    });
    redoTool.registerAction(() => doRedo(appObjects));
    return ao;
}
//# sourceMappingURL=setupUndoRedo.js.map