import { u as useRecordVisibilityChanges, j as jsxRuntimeExports } from "./doenetml-cB_aZGJ5.js";
import React__default, { useRef, useEffect } from "react";
import { u as useDoenetRenderer } from "./useDoenetRenderer-DN3Z9CW3.js";
import { s as sizeToCSS } from "./css-BJLDLYRJ.js";
const embed = React__default.memo(function Figure(props) {
  let { id, SVs, actions, callAction } = useDoenetRenderer(props);
  const ref = useRef(null);
  useRecordVisibilityChanges(ref, callAction, actions);
  useEffect(() => {
    if (SVs.encodedGeogebraContent) {
      let doenetSvData = SVs;
      let cIdx = id;
      let width2 = sizeToCSS(SVs.width);
      let height2 = sizeToCSS(SVs.height);
      MathJax.startup.promise.then(function() {
        let parameters = {
          id: cIdx,
          width: width2,
          height: height2,
          showResetIcon: false,
          enableLabelDrags: false,
          useBrowserForJS: true,
          showMenubar: false,
          errorDialogsActive: true,
          showToolbar: false,
          showAlgebraicInput: false,
          enableShiftDragZoom: true,
          enableRightClick: true,
          showToolBarHelp: false,
          ggbBase64: doenetSvData.encodedGeogebraContent.trim(),
          language: "en",
          country: "US",
          isPreloader: false,
          screenshotGenerator: false,
          preventFocus: false,
          fixApplet: false,
          prerelease: false,
          playButtonAutoDecide: true,
          playButton: false,
          canary: false,
          allowUpscale: false
        };
        let applet = new window.GGBApplet(parameters, true);
        applet.setHTML5Codebase("/geogebra/HTML5/5.0/web/", "true");
        applet.inject("container_" + cIdx, "preferhtml5");
      });
    }
  }, []);
  if (SVs.hidden) {
    return null;
  }
  let width = sizeToCSS(SVs.width);
  let height = sizeToCSS(SVs.height);
  if (SVs.geogebra) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "geogebra", id, ref, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
      "iframe",
      {
        scrolling: "no",
        title: "",
        src: `https://www.geogebra.org/material/iframe/id/${SVs.geogebra}/width/${width}/height/${height}/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/false/rc/false/ld/false/sdz/false/ctl/false`,
        width,
        height,
        style: { border: "0px" },
        children: " "
      }
    ) });
  } else if (SVs.encodedGeogebraContent) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "javascriptapplet", id, ref, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
      "div",
      {
        className: "geogebrawebapplet",
        id: "container_" + id,
        style: { minWidth: width, minHeight: height }
      }
    ) });
  }
  console.warn("Nothing specified to embed");
  return null;
});
export {
  embed as default
};
