import React, { useEffect, useRef, useState } from 'react';
import Loading from "../Loading";
import { HtmlWrap } from "./HtmlWrap";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const Html = ({
  media,
  mediaVisible,
  isDetail: _isDetail = true
}) => {
  const contentElement = useRef(null);
  const [url, setUrl] = useState(media);
  const [iframeVisible, setIframeVisible] = useState();
  const [isLoaded, setIsLoaded] = useState(false);
  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__*/_jsx(HtmlWrap, {
    mediaVisible: mediaVisible,
    children: /*#__PURE__*/_jsxs("div", {
      ref: contentElement,
      className: "hideScrollbar",
      children: [/*#__PURE__*/_jsx(Loading, {
        cssStyle: `
          display: ${_isDetail && isLoaded && 'none'};
          z-index: ${!_isDetail && isLoaded ? '-1' : '1'};
          background: ${_isDetail && 'white'};
        `
      }), iframeVisible ? /*#__PURE__*/_jsx("iframe", {
        title: "iframe",
        src: url,
        allowFullScreen: true,
        name: "mapFrame",
        scrolling: "no",
        frameBorder: "0",
        width: "100%",
        height: "100%",
        onLoad: () => setIsLoaded(true),
        className: "htmlIframe"
      }) : /*#__PURE__*/_jsx("img", {
        src: url,
        onLoad: () => setIsLoaded(true),
        className: "htmlImg"
      })]
    })
  });
};
export default Html;