import { useCallback, useState } from "react";
import { useInterval } from "ahooks";
import { Entity, PolylineGraphics, useCesium } from "resium";
import { Cartesian3, Color, PolylineArrowMaterialProperty } from "cesium";

function SurfaceAnomaly() {
  const { viewer } = useCesium();
  const [show, setShow] = useState(false);

  const showAnimate = useCallback(() => {
    const { currentTime, stopTime } = viewer.clock;
    const leftTime = Math.floor(
      stopTime.secondsOfDay - currentTime.secondsOfDay
    );

    if (leftTime < 10) {
      setShow(true);
    } else if (show) setShow(false);
  }, [show]);

  useInterval(showAnimate, 100);

  return (
    <Entity show={show}>
      <PolylineGraphics
        positions={Cartesian3.fromDegreesArrayHeights([90, -30, 0, 90, -21, 0])}
        width={10}
        material={
          new PolylineArrowMaterialProperty(Color.fromCssColorString("#000"))
        }
      />
    </Entity>
  );
}

export default SurfaceAnomaly;
