"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _loading = _interopRequireDefault(require("@alifd/next/lib/loading"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _react = require("react");
require("./index.scss");
var _index2 = require("../../../utils/index");
var SamplePreview = function SamplePreview() {
  var _useState = (0, _react.useState)({}),
    data = _useState[0],
    setData = _useState[1];
  function init() {
    return _init.apply(this, arguments);
  }
  function _init() {
    _init = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
      var _yield$preview, url;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return (0, _index2.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["default"], {
      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) {
  (0, _inheritsLoose2["default"])(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;
}(_react.Component);
exports["default"] = PreviewWindow;
PreviewWindow.displayName = 'PreviewWindow';