"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maybeExecuteTask = exports.executeTask = exports.moveNode = void 0;
const moveNode = (map, nodeId) => {
    const { table, tasks } = map;
    const moves = [];
    const taskId = table[nodeId];
    if (!taskId) {
        return;
    }
    const task = tasks[taskId];
    moves.push(...(0, exports.maybeExecuteTask)(taskId, task, tasks));
    return moves;
};
exports.moveNode = moveNode;
const executeTask = (taskId, task, tasks) => {
    const moves = [];
    if (task.dependsOn.size === 0) {
        moves.push(...task.moves);
        for (const dependentTaskId of task.isDependencyOf) {
            const dependentTask = tasks[dependentTaskId];
            dependentTask.dependsOn.delete(taskId);
            moves.push(...(0, exports.maybeExecuteTask)(dependentTaskId, dependentTask, tasks));
        }
    }
    return moves;
};
exports.executeTask = executeTask;
const maybeExecuteTask = (taskId, task, tasks) => {
    if (task.dependsOn.size === 0) {
        return (0, exports.executeTask)(taskId, task, tasks);
    }
    return [];
};
exports.maybeExecuteTask = maybeExecuteTask;
//# sourceMappingURL=moveNode.js.map