import { Entity, PolylineGraphics, useCesium } from "resium";
import { Cartesian3 } from "cesium";
import { useParams } from "react-router-dom";
import { min } from "lodash-es";

function Updraft() {
  const { viewer } = useCesium();
  const { type } = useParams();

  if (type !== "1") return <></>;
  return (
    <Entity
      id={"Updraft"}
      position={Cartesian3.fromDegrees(-34.0707383, 60.7117244, 100)}
    >
      <PolylineGraphics
        positions={
          new Cesium.CallbackProperty(function (time, result) {
            const { currentTime, startTime } = viewer.clock;
            const passTime = currentTime.secondsOfDay - startTime.secondsOfDay;
            const height = 100000 * passTime;
            return Cesium.Cartesian3.fromDegreesArrayHeights(
              [-55, 58, 0, -55, 58, min([height, 1000000])],
              Cesium.Ellipsoid.WGS84,
              result
            );
          }, false)
        }
        width={30}
        material={new Cesium.PolylineArrowMaterialProperty(Cesium.Color.RED)}
      />
    </Entity>
  );
}

export default Updraft;
