"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildMoves = exports.applyMoves_ = exports.applyMoves = void 0;
const G_1 = require("../../spec/actions/G");
const clone_1 = require("../../util/clone");
const moveLink_1 = require("./moveLink");
const moveMerge_1 = require("./moveMerge");
const movePlug_1 = require("./movePlug");
const moveUnit_1 = require("./moveUnit");
const applyMoves = (specs, source, target, moves) => {
    const source_ = (0, clone_1.clone)(source);
    const target_ = (0, clone_1.clone)(target);
    for (const move of moves) {
        if (move.in) {
            (0, G_1.act)(specs, target_, move.action.type, move.action.data);
        }
        else {
            (0, G_1.act)(specs, source_, move.action.type, move.action.data);
        }
    }
    return { source: source_, target: target_ };
};
exports.applyMoves = applyMoves;
const applyMoves_ = (specs, source, target, moves) => {
    for (const move of moves) {
        if (move.in) {
            (0, G_1.act)(specs, target, move.action.type, move.action.data);
        }
        else {
            (0, G_1.act)(specs, source, move.action.type, move.action.data);
        }
    }
};
exports.applyMoves_ = applyMoves_;
const buildMoves = (selection, map) => {
    const moves = [];
    for (const unitId of selection.unit ?? []) {
        moves.push(...(0, moveUnit_1.moveUnit)(map, unitId));
    }
    for (const mergeId of selection.merge ?? []) {
        moves.push(...(0, moveMerge_1.moveMerge)(map, mergeId));
    }
    for (const { unitId, type, pinId } of selection.link ?? []) {
        moves.push(...(0, moveLink_1.moveLink)(map, unitId, type, pinId));
    }
    for (const { type, pinId, subPinId } of selection.plug ?? []) {
        moves.push(...(0, movePlug_1.movePlug)(map, type, pinId, subPinId));
    }
    return moves;
};
exports.buildMoves = buildMoves;
//# sourceMappingURL=buildMoves.js.map