import { _ as _defineProperty } from '../../defineProperty-CrCYjjU3.js';
import { _ as _asyncToGenerator } from '../../asyncToGenerator-CPKhuIh2.js';
import ReactDOM from 'react-dom/client';
import _retryImport from '../../utils/retryImport.js';
import { jsx } from 'react/jsx-runtime';
import '../../typeof-D-UKOauR.js';

function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var jsonParse = function jsonParse(value) {
  if (typeof value !== "string") return {};
  try {
    return JSON.parse(value);
  } catch (_unused) {
    return {};
  }
};
function mount(_x) {
  return _mount.apply(this, arguments);
}
function _mount() {
  _mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(componentMap) {
    var _element$dataset;
    var element, _ref, reactClass, reactProps, importFn, props, module, Component, root, _t;
    return _regenerator().w(function (_context) {
      while (1) switch (_context.p = _context.n) {
        case 0:
          element = document.querySelector("[data-react-class]");
          if (element) {
            _context.n = 1;
            break;
          }
          return _context.a(2);
        case 1:
          if (!(((_element$dataset = element.dataset) === null || _element$dataset === void 0 ? void 0 : _element$dataset.mounted) === "true")) {
            _context.n = 2;
            break;
          }
          return _context.a(2);
        case 2:
          _ref = element.dataset || {}, reactClass = _ref.reactClass, reactProps = _ref.reactProps;
          if (reactClass) {
            _context.n = 3;
            break;
          }
          return _context.a(2);
        case 3:
          importFn = componentMap[reactClass];
          if (importFn) {
            _context.n = 4;
            break;
          }
          console.warn("WARNING: No component found for:", reactClass, componentMap);
          return _context.a(2);
        case 4:
          props = jsonParse(reactProps);
          _context.p = 5;
          _context.n = 6;
          return _retryImport(importFn);
        case 6:
          module = _context.v;
          Component = module["default"] || module;
          root = ReactDOM.createRoot(element);
          root.render(/*#__PURE__*/jsx(Component, _objectSpread({}, props)));
          if (element.dataset) element.dataset.mounted = "true";
          _context.n = 8;
          break;
        case 7:
          _context.p = 7;
          _t = _context.v;
          console.error("Failed to load component \"".concat(reactClass, "\""), _t);
        case 8:
          return _context.a(2);
      }
    }, _callee, null, [[5, 7]]);
  }));
  return _mount.apply(this, arguments);
}

export { mount as default };
//# sourceMappingURL=mount.js.map
