"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setPinSetNameAction = exports.exposePinAction = exports.makeRemoveUnitsAction = exports.makeRemoveUnitAction = exports.wrapMakeRemoveUnitAction = exports.makeAddUnitsAction = exports.makeMoveSubgraphOutOfAction = exports.makeMoveSubgraphIntoAction = exports.wrapMoveSubgraphOutOfData = exports.wrapMoveSubgraphIntoData = exports.makeAddUnitAction = exports.wrapAddUnitAction = exports.SET_SUB_COMPONENT_SIZE = exports.SET_COMPONENT_SIZE = exports.SET_UNIT_SIZE = exports.MOVE_SUBGRAPH_OUT_OF = exports.MOVE_SUBGRAPH_INTO = exports.COLLAPSE_UNITS = exports.EXPAND_UNIT = exports.REMOVE_UNIT_MERGES = exports.BULK_EDIT = exports.SET_UNIT_METADATA = exports.SET_METADATA = exports.SET_PIN_SET_REF = exports.SET_PIN_SET_FUNCTIONAL = exports.SET_PIN_SET_NAME = exports.SET_UNIT_ERR = exports.COVER_UNIT_PIN_SET = exports.EXPOSE_UNIT_PIN_SET = exports.SET_UNIT_PIN_IGNORED = exports.SET_UNIT_PIN_CONSTANT = exports.REMOVE_UNIT_PIN_DATA = exports.SET_UNIT_PIN_DATA = exports.PLUG_PIN = exports.UNPLUG_PIN = exports.COVER_PIN = exports.COVER_PIN_SET = exports.EXPOSE_PIN_SET = exports.EXPOSE_PIN = exports.REMOVE_MERGES = exports.REMOVE_MERGE_DATA = exports.REMOVE_MERGE = exports.REMOVE_PIN_FROM_MERGE = exports.ADD_PIN_TO_MERGE = exports.ADD_MERGES = exports.ADD_MERGE = exports.REMOVE_UNITS = exports.REMOVE_UNIT = exports.ADD_UNITS = exports.ADD_UNIT = void 0;
exports.processActions = exports.processAction = exports.reverseAction = exports.makeBulkEditAction = exports.wrapBulkEditData = exports.makeRemoveUnitMergesAction = exports.makeRemovePinFromMergeAction = exports.wrapRemovePinFromMergeData = exports.makeAddPinToMergeAction = exports.wrapAddPinToMergeData = exports.makeRemoveMergesAction = exports.makeAddMergesAction = exports.wrapRemoveMergeDataAction = exports.makeRemoveMergeAction = exports.wrapRemoveMergeActionData = exports.makeAddMergeAction = exports.wrapAddMergeActionData = exports.makeSetMetadataAction = exports.makeSetComponentSizeAction = exports.wrapSetComponentSizeAction = exports.wrapSetSubComponentSizeAction = exports.makeSetSubComponentSizeAction = exports.makeSetUnitSizeAction = exports.wrapSetUnitSizeAction = exports.makeSetUnitMetadataAction = exports.wrapSetUnitMetadataAction = exports.makeRemoveUnitPinDataAction = exports.wrapRemoveUnitPinDataAction = exports.makeSetUnitPinIgnoredAction = exports.makeSetUnitPinConstantAction = exports.makeSetUnitPinDataAction = exports.wrapSetUnitPinDataAction = exports.makeCoverPinAction = exports.wrapCoverPinAction = exports.makeUnplugPinAction = exports.wrapUnplugPinAction = exports.makePlugPinAction = exports.wrapPlugPinAction = exports.makeCoverPinSetAction = exports.wrapCoverPinSetAction = exports.makeExposePinSetAction = exports.makeCoverUnitPinSetAction = exports.wrapCoverUnitPinSet = exports.wrapExposePinSetAction = exports.makeExposeUnitPinSetAction = exports.wrapExposeUnitPinSet = exports.setPinSetFunctionalAction = void 0;
const f_1 = require("../../system/f/object/Keys/f");
const object_1 = require("../../util/object");
const spec_1 = require("../util/spec");
const C_1 = require("./C");
const D_1 = require("./D");
exports.ADD_UNIT = 'addUnitSpec';
exports.ADD_UNITS = 'addUnits';
exports.REMOVE_UNIT = 'removeUnit';
exports.REMOVE_UNITS = 'removeUnits';
exports.ADD_MERGE = 'addMerge';
exports.ADD_MERGES = 'addMerges';
exports.ADD_PIN_TO_MERGE = 'addPinToMerge';
exports.REMOVE_PIN_FROM_MERGE = 'removePinFromMerge';
exports.REMOVE_MERGE = 'removeMerge';
exports.REMOVE_MERGE_DATA = 'removeMergeData';
exports.REMOVE_MERGES = 'removeMerges';
exports.EXPOSE_PIN = 'exposePin';
exports.EXPOSE_PIN_SET = 'exposePinSet';
exports.COVER_PIN_SET = 'coverPinSet';
exports.COVER_PIN = 'coverPin';
exports.UNPLUG_PIN = 'unplugPin';
exports.PLUG_PIN = 'plugPin';
exports.SET_UNIT_PIN_DATA = 'setUnitPinData';
exports.REMOVE_UNIT_PIN_DATA = 'removeUnitPinData';
exports.SET_UNIT_PIN_CONSTANT = 'setUnitPinConstant';
exports.SET_UNIT_PIN_IGNORED = 'setUnitPinIgnored';
exports.EXPOSE_UNIT_PIN_SET = 'exposeUnitPinSet';
exports.COVER_UNIT_PIN_SET = 'coverUnitPinSet';
exports.SET_UNIT_ERR = 'setUnitErr';
exports.SET_PIN_SET_NAME = 'setPinSetName';
exports.SET_PIN_SET_FUNCTIONAL = 'setPinSetFunctional';
exports.SET_PIN_SET_REF = 'setPinSetRef';
exports.SET_METADATA = 'setMetadata';
exports.SET_UNIT_METADATA = 'setUnitMetadata';
exports.BULK_EDIT = 'bulkEdit';
exports.REMOVE_UNIT_MERGES = 'removeUnitMerges';
exports.EXPAND_UNIT = 'expandUnit';
exports.COLLAPSE_UNITS = 'collapseUnits';
exports.MOVE_SUBGRAPH_INTO = 'moveSubgraphInto';
exports.MOVE_SUBGRAPH_OUT_OF = 'moveSubgraphOutOf';
exports.SET_UNIT_SIZE = 'setUnitSize';
exports.SET_COMPONENT_SIZE = 'setComponentSize';
exports.SET_SUB_COMPONENT_SIZE = 'setSubComponentSize';
const wrapAddUnitAction = (data) => {
    return {
        type: exports.ADD_UNIT,
        data,
    };
};
exports.wrapAddUnitAction = wrapAddUnitAction;
const makeAddUnitAction = (unitId, bundle, position, pinPosition, layoutPositon, parentId, merges, plugs) => {
    return (0, exports.wrapAddUnitAction)({
        unitId,
        bundle,
        position,
        pinPosition,
        layoutPositon,
        parentId,
        merges,
        plugs,
    });
};
exports.makeAddUnitAction = makeAddUnitAction;
const wrapMoveSubgraphIntoData = (data) => {
    return {
        type: exports.MOVE_SUBGRAPH_INTO,
        data,
    };
};
exports.wrapMoveSubgraphIntoData = wrapMoveSubgraphIntoData;
const wrapMoveSubgraphOutOfData = (data) => {
    return {
        type: exports.MOVE_SUBGRAPH_OUT_OF,
        data,
    };
};
exports.wrapMoveSubgraphOutOfData = wrapMoveSubgraphOutOfData;
const makeMoveSubgraphIntoAction = (graphId, graphBundle, nextSpecId, nodeIds, nextIdMap, nextUnitPinMergeMap, nextPinIdMap, nextMergePinId, nextPlugSpec, nextSubComponentParentMap, nextSubComponentChildrenMap, nextSubComponentIndexMap) => {
    return (0, exports.wrapMoveSubgraphIntoData)({
        graphId,
        graphBundle,
        nextSpecId,
        nodeIds,
        nextIdMap,
        nextPinIdMap,
        nextMergePinId,
        nextPlugSpec,
        nextUnitPinMergeMap,
        nextSubComponentParentMap,
        nextSubComponentChildrenMap,
        nextSubComponentIndexMap,
    });
};
exports.makeMoveSubgraphIntoAction = makeMoveSubgraphIntoAction;
const makeMoveSubgraphOutOfAction = (graphId, graphBundle, nextSpecId, nodeIds, nextIdMap, nextUnitPinMergeMap, nextPinIdMap, nextMergePinId, nextPlugSpec, nextSubComponentParentMap, nextSubComponentChildrenMap, nextSubComponentIndexMap) => {
    return (0, exports.wrapMoveSubgraphOutOfData)({
        graphId,
        graphBundle,
        nextSpecId,
        nodeIds,
        nextIdMap,
        nextPinIdMap,
        nextMergePinId,
        nextPlugSpec,
        nextSubComponentParentMap,
        nextSubComponentChildrenMap,
        nextSubComponentIndexMap,
        nextUnitPinMergeMap,
    });
};
exports.makeMoveSubgraphOutOfAction = makeMoveSubgraphOutOfAction;
const makeAddUnitsAction = (units) => {
    return {
        type: exports.ADD_UNITS,
        data: {
            units,
        },
    };
};
exports.makeAddUnitsAction = makeAddUnitsAction;
const wrapMakeRemoveUnitAction = (data) => {
    return {
        type: exports.REMOVE_UNIT,
        data,
    };
};
exports.wrapMakeRemoveUnitAction = wrapMakeRemoveUnitAction;
const makeRemoveUnitAction = (unitId, bundle, position, pinPosition, layoutPositon, parentId, merges, plugs) => {
    return (0, exports.wrapMakeRemoveUnitAction)({
        unitId,
        bundle,
        position,
        pinPosition,
        layoutPositon,
        parentId,
        merges,
        plugs,
    });
};
exports.makeRemoveUnitAction = makeRemoveUnitAction;
const makeRemoveUnitsAction = (ids) => {
    return {
        type: exports.REMOVE_UNITS,
        data: { ids },
    };
};
exports.makeRemoveUnitsAction = makeRemoveUnitsAction;
const exposePinAction = (type, id, subPinId, subPin) => {
    return {
        type: exports.EXPOSE_PIN,
        data: { type, id, subPinId, subPin },
    };
};
exports.exposePinAction = exposePinAction;
const setPinSetNameAction = (type, id, functional) => {
    return {
        type: exports.SET_PIN_SET_NAME,
        data: { type, id, functional },
    };
};
exports.setPinSetNameAction = setPinSetNameAction;
const setPinSetFunctionalAction = (type, id, functional) => {
    return {
        type: exports.SET_PIN_SET_FUNCTIONAL,
        data: { type, id, functional },
    };
};
exports.setPinSetFunctionalAction = setPinSetFunctionalAction;
const wrapExposeUnitPinSet = (data) => {
    return {
        type: exports.EXPOSE_UNIT_PIN_SET,
        data,
    };
};
exports.wrapExposeUnitPinSet = wrapExposeUnitPinSet;
const makeExposeUnitPinSetAction = (unitId, type, pinId, pinSpec, position) => {
    return (0, exports.wrapExposeUnitPinSet)({ type, unitId, pinId, pinSpec, position });
};
exports.makeExposeUnitPinSetAction = makeExposeUnitPinSetAction;
const wrapExposePinSetAction = (data) => {
    return {
        type: exports.EXPOSE_PIN_SET,
        data,
    };
};
exports.wrapExposePinSetAction = wrapExposePinSetAction;
const wrapCoverUnitPinSet = (data) => {
    return {
        type: exports.COVER_UNIT_PIN_SET,
        data,
    };
};
exports.wrapCoverUnitPinSet = wrapCoverUnitPinSet;
const makeCoverUnitPinSetAction = (unitId, type, pinId, pinSpec, position) => {
    return (0, exports.wrapCoverUnitPinSet)({ type, unitId, pinId, pinSpec, position });
};
exports.makeCoverUnitPinSetAction = makeCoverUnitPinSetAction;
const makeExposePinSetAction = (type, pinId, pinSpec, data) => {
    return (0, exports.wrapExposePinSetAction)({ type, pinId, pinSpec, data });
};
exports.makeExposePinSetAction = makeExposePinSetAction;
const wrapCoverPinSetAction = (data) => {
    return {
        type: exports.COVER_PIN_SET,
        data,
    };
};
exports.wrapCoverPinSetAction = wrapCoverPinSetAction;
const makeCoverPinSetAction = (type, pinId, pinSpec) => {
    return (0, exports.wrapCoverPinSetAction)({ type, pinId, pinSpec });
};
exports.makeCoverPinSetAction = makeCoverPinSetAction;
const wrapPlugPinAction = (data) => {
    return {
        type: exports.PLUG_PIN,
        data,
    };
};
exports.wrapPlugPinAction = wrapPlugPinAction;
const makePlugPinAction = (type, pinId, subPinId, subPinSpec) => {
    return (0, exports.wrapPlugPinAction)({ type, pinId, subPinId, subPinSpec });
};
exports.makePlugPinAction = makePlugPinAction;
const wrapUnplugPinAction = (data) => {
    return {
        type: exports.UNPLUG_PIN,
        data,
    };
};
exports.wrapUnplugPinAction = wrapUnplugPinAction;
const makeUnplugPinAction = (type, pinId, subPinId, subPinSpec) => {
    return (0, exports.wrapUnplugPinAction)({ type, pinId, subPinId, subPinSpec });
};
exports.makeUnplugPinAction = makeUnplugPinAction;
const wrapCoverPinAction = (data) => {
    return {
        type: exports.COVER_PIN,
        data,
    };
};
exports.wrapCoverPinAction = wrapCoverPinAction;
const makeCoverPinAction = (type, pinId, subPinId, subPinSpec) => {
    return (0, exports.wrapCoverPinAction)({ type, pinId, subPinId, subPinSpec });
};
exports.makeCoverPinAction = makeCoverPinAction;
const wrapSetUnitPinDataAction = (data) => {
    return {
        type: exports.SET_UNIT_PIN_DATA,
        data,
    };
};
exports.wrapSetUnitPinDataAction = wrapSetUnitPinDataAction;
const makeSetUnitPinDataAction = (unitId, type, pinId, data) => {
    return (0, exports.wrapSetUnitPinDataAction)({
        unitId,
        type,
        pinId,
        data,
        lastData: undefined,
    });
};
exports.makeSetUnitPinDataAction = makeSetUnitPinDataAction;
const makeSetUnitPinConstantAction = (unitId, type, pinId, constant) => {
    return {
        type: exports.SET_UNIT_PIN_CONSTANT,
        data: {
            unitId,
            type,
            pinId,
            constant,
        },
    };
};
exports.makeSetUnitPinConstantAction = makeSetUnitPinConstantAction;
const makeSetUnitPinIgnoredAction = (unitId, type, pinId, ignored) => {
    return {
        type: exports.SET_UNIT_PIN_IGNORED,
        data: {
            unitId,
            type,
            pinId,
            ignored,
        },
    };
};
exports.makeSetUnitPinIgnoredAction = makeSetUnitPinIgnoredAction;
const wrapRemoveUnitPinDataAction = (data) => {
    return {
        type: exports.REMOVE_UNIT_PIN_DATA,
        data,
    };
};
exports.wrapRemoveUnitPinDataAction = wrapRemoveUnitPinDataAction;
const makeRemoveUnitPinDataAction = (unitId, type, pinId) => {
    return (0, exports.wrapRemoveUnitPinDataAction)({
        unitId,
        type,
        pinId,
    });
};
exports.makeRemoveUnitPinDataAction = makeRemoveUnitPinDataAction;
const wrapSetUnitMetadataAction = (data) => {
    return {
        type: exports.SET_UNIT_METADATA,
        data,
    };
};
exports.wrapSetUnitMetadataAction = wrapSetUnitMetadataAction;
const makeSetUnitMetadataAction = (unitId, path, data) => {
    return (0, exports.wrapSetUnitMetadataAction)({
        unitId,
        path,
        data,
    });
};
exports.makeSetUnitMetadataAction = makeSetUnitMetadataAction;
const wrapSetUnitSizeAction = (data) => {
    return {
        type: exports.SET_UNIT_SIZE,
        data,
    };
};
exports.wrapSetUnitSizeAction = wrapSetUnitSizeAction;
const makeSetUnitSizeAction = (unitId, width, height, prevWidth, prevHeight) => {
    return (0, exports.wrapSetUnitSizeAction)({
        unitId,
        width,
        height,
        prevWidth,
        prevHeight,
    });
};
exports.makeSetUnitSizeAction = makeSetUnitSizeAction;
const makeSetSubComponentSizeAction = (unitId, width, height, prevWidth, prevHeight) => {
    return (0, exports.wrapSetUnitSizeAction)({
        unitId,
        width,
        height,
        prevWidth,
        prevHeight,
    });
};
exports.makeSetSubComponentSizeAction = makeSetSubComponentSizeAction;
const wrapSetSubComponentSizeAction = (data) => {
    return {
        type: exports.SET_SUB_COMPONENT_SIZE,
        data,
    };
};
exports.wrapSetSubComponentSizeAction = wrapSetSubComponentSizeAction;
const wrapSetComponentSizeAction = (data) => {
    return {
        type: exports.SET_COMPONENT_SIZE,
        data,
    };
};
exports.wrapSetComponentSizeAction = wrapSetComponentSizeAction;
const makeSetComponentSizeAction = (width, height, prevWidth, prevHeight) => {
    return (0, exports.wrapSetComponentSizeAction)({
        width,
        height,
        prevWidth,
        prevHeight,
    });
};
exports.makeSetComponentSizeAction = makeSetComponentSizeAction;
const makeSetMetadataAction = (path, value) => {
    return {
        type: exports.SET_METADATA,
        data: {
            path,
            value,
        },
    };
};
exports.makeSetMetadataAction = makeSetMetadataAction;
const wrapAddMergeActionData = (data) => {
    return {
        type: exports.ADD_MERGE,
        data,
    };
};
exports.wrapAddMergeActionData = wrapAddMergeActionData;
const makeAddMergeAction = (mergeId, mergeSpec, position) => {
    return (0, exports.wrapAddMergeActionData)({
        mergeId,
        mergeSpec,
        position,
    });
};
exports.makeAddMergeAction = makeAddMergeAction;
const wrapRemoveMergeActionData = (data) => {
    return {
        type: exports.REMOVE_MERGE,
        data,
    };
};
exports.wrapRemoveMergeActionData = wrapRemoveMergeActionData;
const makeRemoveMergeAction = (mergeId, mergeSpec, position) => {
    return (0, exports.wrapRemoveMergeActionData)({
        mergeId,
        mergeSpec,
        position,
    });
};
exports.makeRemoveMergeAction = makeRemoveMergeAction;
const wrapRemoveMergeDataAction = (data) => {
    return {
        type: exports.REMOVE_MERGE_DATA,
        data,
    };
};
exports.wrapRemoveMergeDataAction = wrapRemoveMergeDataAction;
const makeAddMergesAction = (merges) => {
    return {
        type: exports.ADD_MERGES,
        data: {
            merges,
        },
    };
};
exports.makeAddMergesAction = makeAddMergesAction;
const makeRemoveMergesAction = (ids) => {
    return {
        type: exports.REMOVE_MERGES,
        data: {
            ids,
        },
    };
};
exports.makeRemoveMergesAction = makeRemoveMergesAction;
const wrapAddPinToMergeData = (data) => {
    return {
        type: exports.ADD_PIN_TO_MERGE,
        data,
    };
};
exports.wrapAddPinToMergeData = wrapAddPinToMergeData;
const makeAddPinToMergeAction = (mergeId, type, unitId, pinId) => {
    return (0, exports.wrapAddPinToMergeData)({
        mergeId,
        unitId,
        type,
        pinId,
    });
};
exports.makeAddPinToMergeAction = makeAddPinToMergeAction;
const wrapRemovePinFromMergeData = (data) => {
    return {
        type: exports.REMOVE_PIN_FROM_MERGE,
        data,
    };
};
exports.wrapRemovePinFromMergeData = wrapRemovePinFromMergeData;
const makeRemovePinFromMergeAction = (mergeId, type, unitId, pinId) => {
    return (0, exports.wrapRemovePinFromMergeData)({
        mergeId,
        unitId,
        type,
        pinId,
    });
};
exports.makeRemovePinFromMergeAction = makeRemovePinFromMergeAction;
const makeRemoveUnitMergesAction = (id) => {
    return {
        type: exports.REMOVE_UNIT_MERGES,
        data: {
            id,
        },
    };
};
exports.makeRemoveUnitMergesAction = makeRemoveUnitMergesAction;
const wrapBulkEditData = (data) => {
    return {
        type: exports.BULK_EDIT,
        data,
    };
};
exports.wrapBulkEditData = wrapBulkEditData;
const makeBulkEditAction = (actions) => {
    return (0, exports.wrapBulkEditData)({
        actions,
    });
};
exports.makeBulkEditAction = makeBulkEditAction;
const reverseAction = ({ type, data }) => {
    var _a, _b, _c, _d, _e;
    switch (type) {
        case exports.ADD_UNIT:
            return (0, exports.makeRemoveUnitAction)(data.unitId, data.bundle, data.position, data.pinPosition, data.layoutPosition, data.parentId, data.merges, data.plugs);
        case exports.ADD_UNITS:
            return (0, exports.makeRemoveUnitsAction)((0, f_1.keys)(data.units));
        case exports.REMOVE_UNIT:
            return (0, exports.makeAddUnitAction)(data.unitId, data.bundle, data.position, data.pinPosition, data.layoutPosition, data.parentId, data.merges, data.plugs);
        case exports.REMOVE_UNITS:
            return (0, exports.makeAddUnitsAction)(data.ids.reduce((acc, id) => {
                acc[id] = data.units[id];
                return acc;
            }, {}));
        case exports.REMOVE_UNIT_MERGES:
            return (0, exports.makeAddMergesAction)(data.merges);
        case exports.ADD_MERGE:
            return (0, exports.makeRemoveMergeAction)(data.mergeId, data.mergeSpec, data.position);
        case exports.ADD_MERGES:
            return (0, exports.makeRemoveMergesAction)((0, f_1.keys)(data.merges));
        case exports.ADD_PIN_TO_MERGE:
            return (0, exports.makeRemovePinFromMergeAction)(data.mergeId, data.type, data.unitId, data.pinId);
        case exports.REMOVE_MERGE:
            return (0, exports.makeAddMergeAction)(data.mergeId, data.mergeSpec, data.position);
        case exports.REMOVE_PIN_FROM_MERGE:
            return (0, exports.makeAddPinToMergeAction)(data.mergeId, data.type, data.unitId, data.pinId);
        case exports.EXPOSE_PIN_SET:
            return (0, exports.makeCoverPinSetAction)(data.type, data.pinId, data.pin);
        case exports.COVER_PIN_SET:
            return (0, exports.makeExposePinSetAction)(data.type, data.pinId, data.plug, data.data);
        case exports.PLUG_PIN:
            return (0, exports.makeUnplugPinAction)(data.type, data.pinId, data.subPinId, data.subPinSpec);
        case exports.UNPLUG_PIN:
            return (0, exports.makePlugPinAction)(data.type, data.pinId, data.subPinId, data.subPinSpec);
        case exports.SET_UNIT_PIN_CONSTANT:
            return (0, exports.makeSetUnitPinConstantAction)(data.unitId, data.type, data.pinId, !data.constant);
        case exports.SET_UNIT_PIN_DATA:
            return (0, exports.makeSetUnitPinDataAction)(data.unitId, data.type, data.pinId, undefined);
        case exports.SET_UNIT_PIN_IGNORED:
            return (0, exports.makeSetUnitPinIgnoredAction)(data.unitId, data.type, data.pinId, !data.ignored);
        case exports.EXPOSE_UNIT_PIN_SET:
            return (0, exports.makeCoverUnitPinSetAction)(data.unitId, data.type, data.pinId, data.pinSpec);
        case exports.COVER_UNIT_PIN_SET:
            return (0, exports.makeExposeUnitPinSetAction)(data.unitId, data.type, data.pinId, data.pinSpec);
        case C_1.MOVE_SUB_COMPONENT_ROOT:
            return (0, C_1.makeMoveSubComponentRootAction)(data.nextParentId, data.parentId, data.children, data.nextSlotMap, data.slotMap);
        case C_1.REORDER_SUB_COMPONENT:
            return (0, C_1.makeReorderSubComponentAction)(data.parentId, data.childId, data.to, data.from);
        case exports.MOVE_SUBGRAPH_INTO: {
            const data_ = data;
            const nextNodeIds_ = Object.assign(Object.assign({}, data.nodeIds), { unit: data.nodeIds.unit.map((unitId) => { var _a; return (_a = data.nextIdMap.unit[unitId]) !== null && _a !== void 0 ? _a : unitId; }), link: data.nodeIds.link.filter(({ unitId, type, pinId }) => {
                    if (!data.nodeIds.unit.includes(unitId)) {
                        return false;
                    }
                    return true;
                }), plug: data.nodeIds.plug.concat(data.nodeIds.link
                    .filter(({ unitId, type, pinId }) => {
                    if (!data.nodeIds.unit.includes(unitId)) {
                        return true;
                    }
                    return false;
                })
                    .map(({ unitId, type, pinId }) => {
                    return {
                        type,
                        pinId,
                        subPinId: '0',
                    };
                })) });
            const nextIdMap_ = Object.assign(Object.assign({}, data.nextIdMap), { unit: (0, object_1.revertObj)((_a = data.nextIdMap.unit) !== null && _a !== void 0 ? _a : {}), merge: (0, object_1.revertObj)((_b = data.nextIdMap.merge) !== null && _b !== void 0 ? _b : {}) });
            return (0, exports.makeMoveSubgraphOutOfAction)(data.graphId, data.graphBundle, data.nextSpecId, nextNodeIds_, nextIdMap_, data.nextUnitPinMergeMap, data.nextPinIdMap, data.nextMergePinId, data.nextPlugSpec, data.nextSubComponentParentMap, data.nextSubComponentChildrenMap, data.nextSubComponentIndexMap);
        }
        case exports.MOVE_SUBGRAPH_OUT_OF: {
            const data_ = data;
            const nextIdMap_ = Object.assign(Object.assign({}, data_.nextIdMap), { unit: (0, object_1.revertObj)((_c = data_.nextIdMap.unit) !== null && _c !== void 0 ? _c : {}), merge: (0, object_1.revertObj)((_d = data_.nextIdMap.merge) !== null && _d !== void 0 ? _d : {}) });
            const nextNodeIds_ = Object.assign(Object.assign({}, data_.nodeIds), { unit: data_.nodeIds.unit.map((unitId) => { var _a; return (_a = data_.nextIdMap.unit[unitId]) !== null && _a !== void 0 ? _a : unitId; }), merge: data_.nodeIds.merge.map((mergeId) => { var _a; return (_a = data_.nextIdMap.merge[mergeId]) !== null && _a !== void 0 ? _a : mergeId; }) });
            const nextUnitPinMergeMap_ = {};
            (0, spec_1.forEachPinOnMerges)((_e = data_.graphBundle.spec.merges) !== null && _e !== void 0 ? _e : {}, (mergeId, unitId, type, pinId) => {
                var _a;
                const nextUnitId = (_a = nextIdMap_.unit[unitId]) !== null && _a !== void 0 ? _a : unitId;
                (0, object_1.deepSet)(nextUnitPinMergeMap_, [unitId, type, pinId], mergeId);
            });
            const nextPinIdMap_ = (0, object_1.mapObjVK)((0, object_1.mapObjKeyKV)(data_.nextPinIdMap, (unitId) => {
                var _a;
                return (_a = data_.nextIdMap.unit[unitId]) !== null && _a !== void 0 ? _a : unitId;
            }), (pinIdMap) => {
                return {
                    input: (0, object_1.mapObjVK)(pinIdMap.input, (pin) => {
                        return Object.assign(Object.assign({}, pin), { merge: (0, object_1.mapObjKeyKV)(pin.merge, (unitId) => {
                                var _a;
                                return (_a = nextIdMap_.unit[unitId]) !== null && _a !== void 0 ? _a : unitId;
                            }) });
                    }),
                    output: (0, object_1.mapObjVK)(pinIdMap.output, (pin) => {
                        return Object.assign(Object.assign({}, pin), { merge: (0, object_1.mapObjKeyKV)(pin.merge, (unitId) => {
                                var _a;
                                return (_a = nextIdMap_.unit[unitId]) !== null && _a !== void 0 ? _a : unitId;
                            }) });
                    }),
                };
            });
            const nextPlugSpec_ = {
                input: (0, object_1.mapObjVK)(data_.nextPlugSpec.input, (pinSpec) => {
                    return (0, object_1.mapObjVK)(pinSpec, (subPinSpec) => {
                        var _a, _b;
                        const { mergeId, unitId } = subPinSpec;
                        if (mergeId) {
                            return Object.assign(Object.assign({}, subPinSpec), { mergeId: (_a = nextIdMap_.merge[mergeId]) !== null && _a !== void 0 ? _a : mergeId });
                        }
                        else if (unitId) {
                            return Object.assign(Object.assign({}, subPinSpec), { unitId: (_b = nextIdMap_.unit[unitId]) !== null && _b !== void 0 ? _b : unitId });
                        }
                        return subPinSpec;
                    });
                }),
                output: (0, object_1.mapObjVK)(data_.nextPlugSpec.output, (nextPlug) => {
                    return (0, object_1.mapObjVK)(nextPlug, (subPinSpec) => {
                        var _a, _b;
                        const { mergeId, unitId } = subPinSpec;
                        if (mergeId) {
                            return Object.assign(Object.assign({}, subPinSpec), { mergeId: (_a = nextIdMap_.merge[mergeId]) !== null && _a !== void 0 ? _a : mergeId });
                        }
                        else if (unitId) {
                            return Object.assign(Object.assign({}, subPinSpec), { unitId: (_b = nextIdMap_.unit[unitId]) !== null && _b !== void 0 ? _b : unitId });
                        }
                        return subPinSpec;
                    });
                }),
            };
            return (0, exports.makeMoveSubgraphIntoAction)(data_.graphId, data_.graphBundle, data_.nextSpecId, nextNodeIds_, nextIdMap_, nextUnitPinMergeMap_, nextPinIdMap_, data_.nextMergePinId, nextPlugSpec_, data_.nextSubComponentParentMap, data_.nextSubComponentChildrenMap, data_.nextSubComponentIndexMap);
        }
        case exports.BULK_EDIT:
            return (0, exports.makeBulkEditAction)([...data.actions].reverse().map(exports.reverseAction));
        case exports.SET_COMPONENT_SIZE:
            return (0, exports.makeSetComponentSizeAction)(data.prevWidth, data.prevHeight, data.width, data.height);
        case exports.SET_SUB_COMPONENT_SIZE:
            return (0, exports.makeSetSubComponentSizeAction)(data.unitId, data.prevWidth, data.prevHeight, data.width, data.height);
        case exports.SET_UNIT_SIZE:
            return (0, exports.makeSetUnitSizeAction)(data.unitId, data.prevWidth, data.prevHeight, data.width, data.height);
        case D_1.ADD_DATUM:
            return (0, D_1.makeRemoveDatumAction)(data.id, data.value);
        case D_1.SET_DATUM:
            return (0, D_1.makeSetDatumAction)(data.id, data.value, data.prevValue);
        case D_1.REMOVE_DATUM:
            return (0, D_1.makeAddDatumAction)(data.id, data.value);
        default:
            throw new Error('irreversible');
    }
};
exports.reverseAction = reverseAction;
const processAction = (action, method, fallback) => {
    var _a;
    const { type, data } = action;
    if (!method[type] && fallback) {
        throw new Error(`no method for ${type}`);
    }
    ;
    ((_a = method[type]) !== null && _a !== void 0 ? _a : fallback)(data);
};
exports.processAction = processAction;
const processActions = (actions, method, fallback) => {
    actions.forEach((action) => (0, exports.processAction)(action, method, fallback));
};
exports.processActions = processActions;
//# sourceMappingURL=G.js.map