import { h } from "@stencil/core";
import { Constants } from "../../Constants";
import { ThreeUtils } from "../../utils";
export const Nodes = ({ boundingSphereRadius, camera, cameraPosition, controlsType, fontSize, graphEnabled, nodes, selected }, _children) => (() => {
    return Array.from(nodes).map((n) => {
        const [nodeId, node] = n;
        const frustrumDistance = ThreeUtils.getFrustrumSpaceDistance(camera, ThreeUtils.stringToVector3(node.position), cameraPosition);
        // Previous method: scaling nodes relative to view
        // const entityScale =
        //   (frustrumDistance / boundingSphereRadius) *
        //   Constants.frustrumScaleFactor;
        // New method: nodes are consistent (using scale determined by Constants nodeSize)
        const entityScale = 1;
        const textEntityScale = (frustrumDistance / boundingSphereRadius) *
            Constants.frustrumScaleFactor;
        const textOffset = new THREE.Vector3(0, 3 * entityScale, 0);
        textOffset.multiplyScalar(node.scale);
        return (h("a-entity", { "al-child-hover-visible": true, id: nodeId + "-parent" },
            h("a-entity", { position: node.position, id: nodeId + "-title-anchor", "al-billboard": `
              controlsType: ${controlsType};
              cameraPosition: ${ThreeUtils.vector3ToString(camera.position)};
              worldPosition: ${ThreeUtils.vector3ToString(ThreeUtils.stringToVector3(node.position).add(textOffset.clone()))};
            ` },
                h("a-entity", { text: `
                value: ${node.title};
                side: double;
                align: center;
                baseline: bottom;
                anchor: center;
                width: ${fontSize * boundingSphereRadius};
                zOffset: ${0.0000001};
              `, position: ThreeUtils.vector3ToString(textOffset), "al-render-overlaid": true, visible: `${selected === nodeId}`, id: `${nodeId}-label`, "al-background": `
                  text: ${node.title};
                  boundingRadius: ${fontSize * boundingSphereRadius};
              `, scale: ` ${textEntityScale} ${textEntityScale} ${textEntityScale};` })),
            h("a-entity", { "data-raycastable": true, id: nodeId, position: node.position, "al-node": `
              scale: ${node.scale};
              selected: ${selected === nodeId};
              graphEnabled: ${graphEnabled};
            `, scale: ` ${entityScale} ${entityScale} ${entityScale};` })));
    });
})();
