function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["type", "loading", "pageProps", "error", "title", "pageMap"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React from 'react';
import Helmet from 'react-helmet';
import SVG from '@teamix/svg';
import PageContainer from '../../page-container';
import PageHeader from '../../page-header';
import { ProSkeletonRaw } from '../../skeleton';
import { usePrefixCls } from '@teamix/utils';
import { PageMap } from '.';
var cls = usePrefixCls('teamix-pro-nocode');
var Loading = function Loading(props) {
  return /*#__PURE__*/React.createElement(PageContainer, _objectSpread({
    header: /*#__PURE__*/React.createElement(PageHeader, {
      loading: true,
      title: "",
      breadcrumb: []
    }),
    content: /*#__PURE__*/React.createElement(ProSkeletonRaw.Content, null)
  }, props));
};
var Error = function Error(_ref) {
  var message = _ref.message,
    type = _ref.type;
  var ErrorSvg = type === '404' ? SVG.Status404 : SVG.BrowserError;
  return /*#__PURE__*/React.createElement("div", {
    className: cls('empty')
  }, /*#__PURE__*/React.createElement(ErrorSvg, {
    width: 160,
    height: 160
  }), /*#__PURE__*/React.createElement("p", null, message || '页面加载失败'));
};
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
  _inherits(ErrorBoundary, _React$Component);
  var _super = _createSuper(ErrorBoundary);
  function ErrorBoundary(props) {
    var _this;
    _classCallCheck(this, ErrorBoundary);
    _this = _super.call(this, props);
    _this.state = {
      error: false
    };
    return _this;
  }
  _createClass(ErrorBoundary, [{
    key: "render",
    value: function render() {
      if (this.state.error) {
        return /*#__PURE__*/React.createElement(Error, {
          message: this.state.error.message
        });
      }
      return this.props.children;
    }
  }], [{
    key: "getDerivedStateFromError",
    value: function getDerivedStateFromError(error) {
      console.error(error);
      return {
        error: error
      };
    }
  }]);
  return ErrorBoundary;
}(React.Component);
export var PageRenderer = function PageRenderer(props) {
  var type = props.type,
    loading = props.loading,
    pageProps = props.pageProps,
    error = props.error,
    title = props.title,
    pageMap = props.pageMap,
    others = _objectWithoutProperties(props, _excluded);
  if (error) {
    return /*#__PURE__*/React.createElement(Error, {
      message: error.message
    });
  }
  if (!type) {
    return /*#__PURE__*/React.createElement(Loading, _objectSpread({}, others));
  }
  var Page = PageMap[type] || (pageMap === null || pageMap === void 0 ? void 0 : pageMap[type]);
  if (!Page) {
    return /*#__PURE__*/React.createElement(Error, {
      message: "\u9519\u8BEF\u7684\u9875\u9762\u7C7B\u578B",
      type: "404"
    });
  }
  return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Helmet, {
    title: title
  }), /*#__PURE__*/React.createElement(Page, _objectSpread({
    loading: loading,
    pageProps: pageProps || {}
  }, others)));
};
export default PageRenderer;