"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _Loading = _interopRequireDefault(require("../Loading"));
var _HtmlWrap = require("./HtmlWrap");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const Html = ({
  media,
  mediaVisible,
  isDetail: _isDetail = true
}) => {
  const contentElement = (0, _react.useRef)(null);
  const [url, setUrl] = (0, _react.useState)(media);
  const [iframeVisible, setIframeVisible] = (0, _react.useState)();
  const [isLoaded, setIsLoaded] = (0, _react.useState)(false);
  (0, _react.useEffect)(() => {
    const a = media.lastIndexOf('http');
    if (a === -1) {
      return;
    }
    const b = media.slice(a);
    try {
      const c = decodeURIComponent(decodeURIComponent(b));
      if (c.includes('</svg>')) {
        setIframeVisible(false);
        setUrl(`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(media)))}`);
        return;
      }
      setIframeVisible(true);
      setUrl(c);
    } catch (_unused) {
      try {
        if (media.includes('</svg>')) {
          setIframeVisible(false);
          setUrl(`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(media)))}`);
        }
      } catch (_unused2) {}
    }
  }, [media]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_HtmlWrap.HtmlWrap, {
    mediaVisible: mediaVisible,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      ref: contentElement,
      className: "hideScrollbar",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.default, {
        cssStyle: `
          display: ${_isDetail && isLoaded && 'none'};
          z-index: ${!_isDetail && isLoaded ? '-1' : '1'};
          background: ${_isDetail && 'white'};
        `
      }), iframeVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
        title: "iframe",
        src: url,
        allowFullScreen: true,
        name: "mapFrame",
        scrolling: "no",
        frameBorder: "0",
        width: "100%",
        height: "100%",
        onLoad: () => setIsLoaded(true),
        className: "htmlIframe"
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
        src: url,
        onLoad: () => setIsLoaded(true),
        className: "htmlImg"
      })]
    })
  });
};
var _default = Html;
exports.default = _default;