"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Core = require("@intelligentgraphics/ig.gfx.core");
var ThreeJS = require("@intelligentgraphics/ig.gfx.threejs");
var Planning = require("@intelligentgraphics/ig.gfx.planning");
var _ = require("lodash");
var MAX_ROTATION_DIFF_DEG = 10;
exports.closestWallWithRotation = function (id) {
    //var tWallId = IG_GFX_Planning.WallUtilities.closestWall(id);
    var walls = Planning.Environment.getInstance().getWalls();
    if (walls.length === 0) {
        return undefined;
    }
    var componentABB = ThreeJS.AbstractBoundingBox.CreateFromGfxId(id);
    var componentPoints = componentABB.getPoints();
    var distanceAvgToComponent = function (wallId) {
        return Planning.WallUtilities.distanceAverageOfPointsToWall(componentPoints, wallId);
    };
    var wallId = _(walls)
        .sortBy(distanceAvgToComponent)
        .filter(function (w) {
        return (Math.abs(Core.State.API.GetYRotation(id) -
            Core.State.API.GetYRotation(w)) < MAX_ROTATION_DIFF_DEG);
    })
        .head();
    return wallId;
};
