import _ from "lodash";
import * as Core from "@intelligentgraphics/ig.gfx.core";
/**
 * The class responsible for placing objects at a wall.
 * This class only works with walls where the depth of the wall is smaller than height and length!
 */
var AtWallPlacement = /** @class */ (function () {
    /**
     * The constructor.
     * @param insertedId
     * @param wallId
     * @param offset
     */
    function AtWallPlacement(insertedId, wallId, offset) {
        this.componentId = insertedId;
        this.wallId = wallId;
        this.offset = offset;
    }
    AtWallPlacement.prototype.getTransformation = function () {
        var wall = Core.State.API.SetupWall(this.wallId);
        var wallBounds = Core.State.API.GetAbstractBounds(this.wallId);
        var normal = Core.Vector.Normalize3(wall.rightNormal);
        var sortedDirections = _(wallBounds.getDirections()).sortBy(Core.Vector.Magnitude3);
        // The smallest direction is the thickness of the wall
        var wallThickness = Core.Vector.Magnitude3(sortedDirections.first());
        // The other two directions are the height and width of the wall.
        // We get the direction of the wall by choosing the one with the smaller y component
        var wallDirection = sortedDirections
            .tail()
            .sortBy("y")
            .first();
        var wallOffset = Core.Vector.ScalarMultiply3(this.offset, wallDirection);
        var wallTransformation = Core.getWorldTransformation(this.wallId);
        var newPosition = Core.Vector.Add3(Core.Vector.Add3(wallTransformation.position, Core.Vector.ScalarMultiply3(wallThickness, normal)), wallOffset);
        return {
            position: newPosition,
            rotation: wallTransformation.rotation,
        };
    };
    return AtWallPlacement;
}());
export default AtWallPlacement;
