var _excluded = ["portal", "visible", "maskProps", "icon", "content", "children"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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; }
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
import { createPortal } from 'react-dom';
import SpinFade from "./../SpinFade";

// 内库使用-start
import LocaleUtil from "./../../../utils/LocaleUtil";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil } from 'seedsui-react'
测试使用-start */

var Loading = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var portal = _ref.portal,
    _ref$visible = _ref.visible,
    visible = _ref$visible === void 0 ? true : _ref$visible,
    _ref$maskProps = _ref.maskProps,
    maskProps = _ref$maskProps === void 0 ? {} : _ref$maskProps,
    icon = _ref.icon,
    content = _ref.content,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  var rootRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });

  // render icon
  function getIconNode() {
    if (typeof icon === 'function') {
      return icon();
    }
    if ( /*#__PURE__*/React.isValidElement(icon)) {
      return icon;
    }

    // Default Status
    return /*#__PURE__*/React.createElement(SpinFade, null);
  }

  // 组合Node
  var Node = /*#__PURE__*/React.createElement("div", _extends({}, maskProps, {
    className: "loading-mask mask ".concat(visible ? ' active' : '').concat(maskProps.className ? ' ' + maskProps.className : ''),
    ref: rootRef
  }), children !== undefined ? children : /*#__PURE__*/React.createElement("div", _extends({
    className: "loading"
  }, props), /*#__PURE__*/React.createElement("div", {
    className: "loading-icon"
  }, getIconNode()), /*#__PURE__*/React.createElement("div", {
    className: "loading-content"
  }, content || "".concat(LocaleUtil.locale('加载中', 'SeedsUI_refreshing'), "..."))));
  if (portal) {
    return /*#__PURE__*/createPortal(Node, portal);
  }
  return Node;
});
export default Loading;