import { h } from "@stencil/core";
import { DisplayMode } from "../../enums";
import { ThreeUtils, Utils } from "../../utils";
export const BoundingBox = ({ boundingBox, boundingBoxEnabled, cb, color, displayMode, graphEnabled, mesh, srcLoaded, targetEntity }, _children) => (() => {
    if (!srcLoaded) {
        return null;
    }
    else {
        if (!mesh) {
            return null;
        }
        const size = new THREE.Vector3();
        boundingBox.getSize(size);
        const meshGeom = mesh.geometry;
        let position;
        if (displayMode === DisplayMode.VOLUME) {
            position = targetEntity.object3D.position
                .clone()
                .add(Utils.getGeometryCenter(meshGeom));
            return (h("a-entity", { "data-raycastable": true, position: ThreeUtils.vector3ToString(position), "al-bounding-box": `
              scale: ${ThreeUtils.vector3ToString(size)};
              color: ${color};
              enabled: ${boundingBoxEnabled};
            `, "al-node-spawner": `
              graphEnabled: ${graphEnabled};
            `, ref: ref => cb(ref) }));
        }
        else if (displayMode === DisplayMode.SLICES) {
            position = targetEntity.object3D.position
                .clone()
                .add(Utils.getGeometryCenter(meshGeom));
            return (h("a-entity", { position: ThreeUtils.vector3ToString(position), "al-bounding-box": `
              scale: ${ThreeUtils.vector3ToString(size)};
              color: ${color};
              enabled: ${boundingBoxEnabled};
            `, ref: ref => cb(ref) }));
        }
        else {
            const center = boundingBox.getCenter(new THREE.Vector3());
            position = new THREE.Vector3();
            position.x -= targetEntity.object3D.position.x - center.x;
            position.y -= targetEntity.object3D.position.y - center.y;
            position.z -= targetEntity.object3D.position.z - center.z;
            return (h("a-entity", { position: ThreeUtils.vector3ToString(position), "al-bounding-box": `
              scale: ${ThreeUtils.vector3ToString(size)};
              color: ${color};
              enabled: ${boundingBoxEnabled};
            `, ref: ref => cb(ref) }));
        }
    }
})();
