"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var _overlay = _interopRequireDefault(require("../overlay"));

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

var _util = require("../util");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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); }

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); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } 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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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; }

/* eslint-disable react/prefer-stateless-function */

/** Loading */
var Loading =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Loading, _React$Component);

  function Loading() {
    _classCallCheck(this, Loading);

    return _possibleConstructorReturn(this, _getPrototypeOf(Loading).apply(this, arguments));
  }

  _createClass(Loading, [{
    key: "render",
    value: function render() {
      var _classNames2, _classNames3, _classNames4;

      var _this$props = this.props,
          tip = _this$props.tip,
          visible = _this$props.visible,
          children = _this$props.children,
          className = _this$props.className,
          style = _this$props.style,
          indicator = _this$props.indicator,
          color = _this$props.color,
          prefix = _this$props.prefix,
          fullScreen = _this$props.fullScreen,
          onVisibleChange = _this$props.onVisibleChange,
          tipAlign = _this$props.tipAlign,
          size = _this$props.size,
          inline = _this$props.inline,
          rtl = _this$props.rtl;
      var indicatorDom = null;
      var dotCls = "".concat(prefix, "loading-dot");

      if (indicator) {
        indicatorDom = indicator;
      } else {
        var _classNames;

        var backgroundColor = color;
        var fusionReactorCls = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "loading-dot-container"), true), _defineProperty(_classNames, "".concat(prefix, "loading-dot-container-").concat(size), true), _classNames));
        indicatorDom = _react["default"].createElement("div", {
          className: fusionReactorCls,
          dir: rtl ? 'rtl' : undefined
        }, _react["default"].createElement("span", {
          className: dotCls,
          style: {
            backgroundColor: backgroundColor
          }
        }), _react["default"].createElement("span", {
          className: dotCls,
          style: {
            backgroundColor: backgroundColor
          }
        }), _react["default"].createElement("span", {
          className: dotCls,
          style: {
            backgroundColor: backgroundColor
          }
        }));
      }

      var loadingCls = (0, _classnames["default"])((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "loading"), true), _defineProperty(_classNames2, "".concat(prefix, "open"), visible), _defineProperty(_classNames2, "".concat(prefix, "loading-inline"), inline), _defineProperty(_classNames2, className, className), _classNames2));
      var tipCls = (0, _classnames["default"])((_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "loading-tip"), true), _defineProperty(_classNames3, "".concat(prefix, "loading-tip-fullscreen"), fullScreen), _defineProperty(_classNames3, "".concat(prefix, "loading-right-tip"), tipAlign === 'right'), _classNames3));

      var others = _util.obj.pickOthers(Loading.propTypes, this.props);

      var contentCls = (0, _classnames["default"])((_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefix, "loading-component"), visible), _defineProperty(_classNames4, "".concat(prefix, "loading-wrap"), true), _classNames4));
      return fullScreen ? [children, _react["default"].createElement(_overlay["default"], _extends({
        key: "overlay",
        hasMask: true,
        align: "cc cc"
      }, others, {
        className: className,
        style: style,
        visible: visible,
        onRequestClose: onVisibleChange
      }), _react["default"].createElement("div", {
        className: tipCls
      }, _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-indicator")
      }, indicatorDom), _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-tip-content")
      }, tip), _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-tip-placeholder")
      }, tip)))] : _react["default"].createElement("div", _extends({
        className: loadingCls,
        style: style
      }, _util.obj.pickAttrs(others)), visible ? _react["default"].createElement("div", {
        className: tipCls
      }, _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-indicator")
      }, indicatorDom), _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-tip-content")
      }, tip), _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-tip-placeholder")
      }, tip)) : null, _react["default"].createElement("div", {
        className: contentCls
      }, visible ? _react["default"].createElement("div", {
        className: "".concat(prefix, "loading-masker")
      }) : null, children));
    }
  }]);

  return Loading;
}(_react["default"].Component);

_defineProperty(Loading, "propTypes", {
  /**
   * 样式前缀
   */
  prefix: _propTypes["default"].string,

  /**
   * 自定义内容
   */
  tip: _propTypes["default"].any,

  /**
   * 自定义内容位置
   * @enumdesc 出现在动画右边, 出现在动画下面
   */
  tipAlign: _propTypes["default"].oneOf(['right', 'bottom']),

  /**
   * loading 状态, 默认 true
   */
  visible: _propTypes["default"].bool,
  onVisibleChange: _propTypes["default"].func,

  /**
   * 自定义class
   */
  className: _propTypes["default"].string,

  /**
   * 自定义内联样式
   */
  style: _propTypes["default"].object,

  /**
   * 设置动画尺寸
   * @description 仅仅对默认动画效果起作用
   * @enumdesc 大号, 中号
   */
  size: _propTypes["default"].oneOf(['large', 'medium']),

  /**
   * 自定义动画
   */
  indicator: _propTypes["default"].any,

  /**
   * 动画颜色
   */
  color: _propTypes["default"].string,

  /**
   * 全屏展示
   */
  fullScreen: _propTypes["default"].bool,

  /**
   * 子元素
   */
  children: _propTypes["default"].any,

  /**
   * should loader be displayed inline
   */
  inline: _propTypes["default"].bool,
  rtl: _propTypes["default"].bool
});

_defineProperty(Loading, "defaultProps", {
  prefix: 'next-',
  visible: true,
  onVisibleChange: _util.func.noop,
  tipAlign: 'bottom',
  size: 'medium',
  inline: true
});

var _default = _configProvider["default"].config(Loading);

exports["default"] = _default;