import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Loading from "@alifd/next/es/loading";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { Component, useState } from 'react';
import "./index.scss";
import { preview } from "../../../utils/index";
var SamplePreview = function SamplePreview() {
  var _useState = useState({}),
    data = _useState[0],
    setData = _useState[1];
  function init() {
    return _init.apply(this, arguments);
  }
  function _init() {
    _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var _yield$preview, url;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return preview();
          case 2:
            _yield$preview = _context.sent;
            url = _yield$preview.url;
            setData({
              url: url
            });
          case 5:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return _init.apply(this, arguments);
  }
  var url = data.url;
  if (!url) {
    init();
    return /*#__PURE__*/React.createElement(_Loading, {
      fullScreen: true
    });
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "preview-html"
  }, /*#__PURE__*/React.createElement("iframe", {
    title: "resg",
    src: data.url,
    style: {
      width: '375px',
      border: '0px',
      height: '100%'
    },
    sandbox: "allow-same-origin allow-scripts allow-popups allow-forms",
    scrolling: "auto"
  }));
};
var PreviewWindow = /*#__PURE__*/function (_Component) {
  _inheritsLoose(PreviewWindow, _Component);
  function PreviewWindow() {
    return _Component.apply(this, arguments) || this;
  }
  var _proto = PreviewWindow.prototype;
  _proto.render = function render() {
    return /*#__PURE__*/React.createElement("div", {
      className: "preview-window"
    }, /*#__PURE__*/React.createElement(SamplePreview, null));
  };
  return PreviewWindow;
}(Component);
PreviewWindow.displayName = 'PreviewWindow';
export { PreviewWindow as default };