"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _clsx = _interopRequireDefault(require("clsx"));

var _utils = require("../utils");

var _ConfigProviderContext = _interopRequireDefault(require("../config-provider/ConfigProviderContext"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || 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); }

var SpinIcon = function SpinIcon(_ref) {
  var bem = _ref.bem;
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, Array(12).fill(null) // eslint-disable-next-line react/no-array-index-key
  .map(function (_, index) {
    return /*#__PURE__*/_react.default.createElement("i", {
      key: index,
      className: (0, _clsx.default)(bem('line', String(index + 1)))
    });
  }));
};

var CircularIcon = function CircularIcon(_ref2) {
  var bem = _ref2.bem;
  return /*#__PURE__*/_react.default.createElement("svg", {
    className: (0, _clsx.default)(bem('circular')),
    viewBox: "25 25 50 50"
  }, /*#__PURE__*/_react.default.createElement("circle", {
    cx: "50",
    cy: "50",
    r: "20",
    fill: "none"
  }));
};

var BallIcon = function BallIcon(_ref3) {
  var bem = _ref3.bem;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _clsx.default)(bem('ball'))
  }, /*#__PURE__*/_react.default.createElement("div", null), /*#__PURE__*/_react.default.createElement("div", null), /*#__PURE__*/_react.default.createElement("div", null));
};

var Icon = function Icon(bem) {
  return {
    spinner: /*#__PURE__*/_react.default.createElement(SpinIcon, {
      bem: bem
    }),
    circular: /*#__PURE__*/_react.default.createElement(CircularIcon, {
      bem: bem
    }),
    ball: /*#__PURE__*/_react.default.createElement(BallIcon, {
      bem: bem
    })
  };
};

var Loading = function Loading(props) {
  var _useContext = (0, _react.useContext)(_ConfigProviderContext.default),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('loading', prefixCls),
      bem = _createNamespace[0];

  var className = props.className,
      type = props.type,
      vertical = props.vertical,
      color = props.color,
      size = props.size,
      textColor = props.textColor,
      children = props.children,
      textSize = props.textSize;
  var spinnerStyle = (0, _react.useMemo)(function () {
    return _extends({
      color: color
    }, (0, _utils.getSizeStyle)(size));
  }, [color, size]);

  var renderText = function renderText() {
    if (children) {
      return /*#__PURE__*/_react.default.createElement("span", {
        className: (0, _clsx.default)(bem('text')),
        style: {
          fontSize: (0, _utils.addUnit)(textSize),
          color: textColor != null ? textColor : color
        }
      }, children);
    }

    return null;
  };

  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _clsx.default)(className, bem([type, {
      vertical: vertical
    }])),
    style: props.style
  }, /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _clsx.default)(bem('spinner', type)),
    style: spinnerStyle
  }, Icon(bem)[type]), renderText());
};

Loading.defaultProps = {
  type: 'circular'
};
var _default = Loading;
exports.default = _default;