"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
const useMathJax = mathJaxSource => {
  const [isLoading, setIsLoading] = (0, _react.useState)(true);
  (0, _react.useEffect)(() => {
    if (!mathJaxSource) {
      setIsLoading(false);
      return;
    }
    window.MathJax = {
      options: {
        enableMenu: false
      },
      tex: {
        inlineMath: [['$', '$']],
        displayMath: [['$$', '$$']]
      },
      svg: {
        fontCache: 'global'
      }
    };
    if (!document.querySelector('#mathjax')) {
      const script = document.createElement('script');
      script.src = mathJaxSource;
      script.id = 'mathjax';
      document.body.appendChild(script);
      script.onload = () => {
        setIsLoading(false);
      };
    }
    return () => {
      const script = document.getElementById('mathjax');
      script && script.parentNode.removeChild(script);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  return {
    isLoadingMathJax: isLoading
  };
};
var _default = exports.default = useMathJax;