import { useCallback, useState } from "react";
import {
  Entity,
  LabelGraphics,
  EllipseGraphics,
  useCesium,
  CylinderGraphics,
} from "resium";
import { Color, Cartesian3, LabelStyle } from "cesium";
import { useParams } from "react-router-dom";
import { useInterval } from "ahooks";

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

  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, 1000);

  if (type !== "1") return <></>;

  return (
    <Entity
      show={show}
      name="Barotropic"
      // description="Barotropic"
      position={Cartesian3.fromDegrees(88, 60, 0)}
    >
      <EllipseGraphics
        material={new Color(0.73, 0.94, 0.95, 0.4)}
        semiMinorAxis={150000.0}
        semiMajorAxis={150000.0}
        extrudedHeight={1000000.0}
        rotation={0}
        // outline
      />
      <LabelGraphics
        position={Cartesian3.fromDegrees(88, 60, 0)}
        text={"barotropic"}
        font="24px Helvetica"
        fillColor={Color.SKYBLUE}
        outlineColor={Color.BLACK}
        outlineWidth={2}
        style={LabelStyle.FILL_AND_OUTLINE}
        eyeOffset={new Cesium.Cartesian2(0, 500000)}
      />
    </Entity>
  );
}

export default Barotropic;
