"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; 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); }

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

var _loading = _interopRequireDefault(require("@alifd/next/lib/loading"));

var _Bar = _interopRequireDefault(require("./Bar"));

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

var _Container = _interopRequireDefault(require("./Container"));

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

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

var _reactNprogress = require("@tanem/react-nprogress");

var _excluded = ["prefix", "size", "type", "className", "fullScreen", "visible"];

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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 _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); 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 } }); 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 _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 : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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

// 圆形加载不同尺寸大小的加载图案
// 加大号
var indicator1 = function indicator1(prefix) {
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "loading-circle")
  }, /*#__PURE__*/_react["default"].createElement("svg", {
    viewBox: "0 0 40 40",
    version: "1.1",
    xmlns: "http://www.w3.org/2000/svg",
    xmlnsXlink: "http://www.w3.org/1999/xlink"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "13\u3001Loading-\u52A0\u8F7D-*",
    stroke: "none",
    "stroke-width": "1",
    fill: "none",
    "fill-rule": "evenodd"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "Loading-\u52A0\u8F7D",
    transform: "translate(-624.000000, -659.000000)"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u5706\u5F62\u52A0\u8F7D-/-40px",
    transform: "translate(624.000000, 659.000000)"
  }, /*#__PURE__*/_react["default"].createElement("rect", {
    id: "\u77E9\u5F62",
    x: "0",
    y: "0",
    width: "40",
    height: "40"
  }), /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u7F16\u7EC4",
    transform: "translate(1.000000, 1.000000)"
  }, /*#__PURE__*/_react["default"].createElement("path", {
    d: "M19,0 C8.50658975,0 0,8.50658975 0,19 C0,29.4934102 8.50658975,38 19,38 C29.4934102,38 38,29.4934102 38,19 C38,8.50658975 29.4934102,0 19,0 Z M19,4 C27.2842712,4 34,10.7157288 34,19 C34,27.2842712 27.2842712,34 19,34 C10.7157288,34 4,27.2842712 4,19 C4,10.7157288 10.7157288,4 19,4 Z",
    id: "\u692D\u5706\u5F62",
    opacity: "0",
    "fill-rule": "nonzero"
  }), /*#__PURE__*/_react["default"].createElement("path", {
    d: "M19,0 C29.4934102,0 38,8.50658975 38,19 C38,29.4934102 29.4934102,38 19,38 C14.859153,38 10.9142651,36.6696246 7.66163236,34.2473379 C6.7757348,33.5875961 6.59239937,32.3346078 7.25214121,31.4487102 C7.91188305,30.5628126 9.16487135,30.3794772 10.0507689,31.0392191 C12.6187461,32.9516321 15.7274132,34 19,34 C27.2842712,34 34,27.2842712 34,19 C34,10.7157288 27.2842712,4 19,4 C17.8954305,4 17,3.1045695 17,2 C17,0.8954305 17.8954305,0 19,0 Z",
    id: "\u8DEF\u5F84",
    fill: "url(#linear-gradient2)"
  })))))));
}; // 大号


var indicator2 = function indicator2(prefix) {
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "loading-circle")
  }, /*#__PURE__*/_react["default"].createElement("svg", {
    viewBox: "0 0 18 18",
    version: "1.1",
    xmlns: "http://www.w3.org/2000/svg",
    xmlnsXlink: "http://www.w3.org/1999/xlink"
  }, /*#__PURE__*/_react["default"].createElement("linearGradient", {
    id: "linear-gradient2",
    x1: "0",
    y1: "0",
    x2: "0",
    y2: "1"
  }, /*#__PURE__*/_react["default"].createElement("stop", {
    className: "loading-svg-style1",
    offset: "10%"
  }), /*#__PURE__*/_react["default"].createElement("stop", {
    className: "loading-svg-style2",
    offset: "100%"
  })), ";", /*#__PURE__*/_react["default"].createElement("g", {
    id: "13\u3001Loading-\u52A0\u8F7D-*",
    stroke: "none",
    "stroke-width": "1",
    fill: "none",
    "fill-rule": "evenodd"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "Loading-\u52A0\u8F7D",
    transform: "translate(-118.000000, -664.000000)"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u5706\u5F62\u52A0\u8F7D-/-18px",
    transform: "translate(118.000000, 664.000000)"
  }, /*#__PURE__*/_react["default"].createElement("rect", {
    id: "\u77E9\u5F62",
    x: "0",
    y: "0",
    width: "18",
    height: "18"
  }), /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u7F16\u7EC4\u5907\u4EFD",
    transform: "translate(1.125000, 1.125000)"
  }, /*#__PURE__*/_react["default"].createElement("path", {
    d: "M7.875,0 C3.5257576,0 0,3.5257576 0,7.875 C0,12.2242424 3.5257576,15.75 7.875,15.75 C12.2242424,15.75 15.75,12.2242424 15.75,7.875 C15.75,3.5257576 12.2242424,0 7.875,0 Z M7.875,2.25 C10.9816017,2.25 13.5,4.76839828 13.5,7.875 C13.5,10.9816017 10.9816017,13.5 7.875,13.5 C4.76839828,13.5 2.25,10.9816017 2.25,7.875 C2.25,4.76839828 4.76839828,2.25 7.875,2.25 Z",
    id: "\u692D\u5706\u5F62",
    "fill-rule": "nonzero",
    opacity: "0",
    transform: "rotate(90deg)"
  }), /*#__PURE__*/_react["default"].createElement("path", {
    d: "M7.875,0 C12.2242424,0 15.75,3.5257576 15.75,7.875 C15.75,12.2242424 12.2242424,15.75 7.875,15.75 C6.15901718,15.75 4.52349194,15.1984349 3.1753703,14.1944675 C2.67705293,13.8233627 2.57392675,13.1185568 2.94503153,12.6202394 C3.31613632,12.1219221 4.02094224,12.0187959 4.51925961,12.3899007 C5.48226252,13.1070641 6.64741351,13.5 7.875,13.5 C10.9816017,13.5 13.5,10.9816017 13.5,7.875 C13.5,4.76839828 10.9816017,2.25 7.875,2.25 C7.25367966,2.25 6.75,1.74632034 6.75,1.125 C6.75,0.503679656 7.25367966,0 7.875,0 Z",
    id: "\u8DEF\u5F84",
    fill: "url(#linear-gradient2)"
  })))))));
}; // 中号


var indicator3 = function indicator3(prefix) {
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "loading-circle")
  }, /*#__PURE__*/_react["default"].createElement("svg", {
    viewBox: "0 0 16 16",
    version: "1.1",
    xmlns: "http://www.w3.org/2000/svg",
    xmlnsXlink: "http://www.w3.org/1999/xlink"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "13\u3001Loading-\u52A0\u8F7D-*",
    stroke: "none",
    "stroke-width": "1",
    fill: "none",
    "fill-rule": "evenodd"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "Loading-\u52A0\u8F7D",
    transform: "translate(-623.000000, -496.000000)"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u5706\u5F62\u52A0\u8F7D-/-16px",
    transform: "translate(623.000000, 496.000000)"
  }, /*#__PURE__*/_react["default"].createElement("rect", {
    id: "\u77E9\u5F62",
    x: "0",
    y: "0",
    width: "16",
    height: "16"
  }), /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u7F16\u7EC4\u5907\u4EFD",
    transform: "translate(1.000000, 1.000000)"
  }, /*#__PURE__*/_react["default"].createElement("path", {
    d: "M7,0 C3.13400675,0 0,3.13400675 0,7 C0,10.8659932 3.13400675,14 7,14 C10.8659932,14 14,10.8659932 14,7 C14,3.13400675 10.8659932,0 7,0 Z M7,2 C9.76142375,2 12,4.23857625 12,7 C12,9.76142375 9.76142375,12 7,12 C4.23857625,12 2,9.76142375 2,7 C2,4.23857625 4.23857625,2 7,2 Z",
    id: "\u692D\u5706\u5F62",
    fill: "#979797",
    "fill-rule": "nonzero",
    opacity: "0"
  }), /*#__PURE__*/_react["default"].createElement("path", {
    d: "M7,0 C10.8659932,0 14,3.13400675 14,7 C14,10.8659932 10.8659932,14 7,14 C5.47468194,14 4.02088172,13.5097199 2.82255138,12.6173045 C2.3796026,12.2874335 2.28793488,11.6609394 2.61780581,11.2179906 C2.94767673,10.7750418 3.57417088,10.6833741 4.01711965,11.013245 C4.87312224,11.6507236 5.90881201,12 7,12 C9.76142375,12 12,9.76142375 12,7 C12,4.23857625 9.76142375,2 7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 Z",
    id: "\u8DEF\u5F84",
    fill: "url(#linear-gradient2)"
  })))))));
}; // 小号


var indicator4 = function indicator4(prefix) {
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "loading-circle")
  }, /*#__PURE__*/_react["default"].createElement("svg", {
    viewBox: "0 0 12 12",
    version: "1.1",
    xmlns: "http://www.w3.org/2000/svg",
    xmlnsXlink: "http://www.w3.org/1999/xlink"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "13\u3001Loading-\u52A0\u8F7D-*",
    stroke: "none",
    "stroke-width": "1",
    fill: "none",
    "fill-rule": "evenodd"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "Loading-\u52A0\u8F7D",
    transform: "translate(-118.000000, -496.000000)"
  }, /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u5706\u5F62\u52A0\u8F7D-/-12px",
    transform: "translate(118.000000, 496.000000)"
  }, /*#__PURE__*/_react["default"].createElement("rect", {
    id: "\u77E9\u5F62",
    x: "0",
    y: "0",
    width: "12",
    height: "12"
  }), /*#__PURE__*/_react["default"].createElement("g", {
    id: "\u7F16\u7EC4\u5907\u4EFD",
    transform: "translate(0.750000, 0.750000)"
  }, /*#__PURE__*/_react["default"].createElement("path", {
    d: "M5.25,0 C2.35050506,0 0,2.35050506 0,5.25 C0,8.14949494 2.35050506,10.5 5.25,10.5 C8.14949494,10.5 10.5,8.14949494 10.5,5.25 C10.5,2.35050506 8.14949494,0 5.25,0 Z M5.25,1.5 C7.32106781,1.5 9,3.17893219 9,5.25 C9,7.32106781 7.32106781,9 5.25,9 C3.17893219,9 1.5,7.32106781 1.5,5.25 C1.5,3.17893219 3.17893219,1.5 5.25,1.5 Z",
    id: "\u692D\u5706\u5F62",
    fill: "#979797",
    "fill-rule": "nonzero",
    opacity: "0"
  }), /*#__PURE__*/_react["default"].createElement("path", {
    d: "M5.25,0 C8.14949494,0 10.5,2.35050506 10.5,5.25 C10.5,8.14949494 8.14949494,10.5 5.25,10.5 C4.10601145,10.5 3.01566129,10.1322899 2.11691354,9.46297835 C1.78470195,9.21557516 1.71595116,8.74570455 1.96335435,8.41349296 C2.21075754,8.08128138 2.68062816,8.01253059 3.01283974,8.25993378 C3.65484168,8.73804272 4.43160901,9 5.25,9 C7.32106781,9 9,7.32106781 9,5.25 C9,3.17893219 7.32106781,1.5 5.25,1.5 C4.83578644,1.5 4.5,1.16421356 4.5,0.75 C4.5,0.335786438 4.83578644,0 5.25,0 Z",
    id: "\u8DEF\u5F84",
    fill: "url(#linear-gradient2)"
  })))))));
}; // 全局线性加载组件


var Progress = function Progress(_ref) {
  var isAnimating = _ref.isAnimating;

  var _useNProgress = (0, _reactNprogress.useNProgress)({
    isAnimating: isAnimating
  }),
      animationDuration = _useNProgress.animationDuration,
      isFinished = _useNProgress.isFinished,
      progress = _useNProgress.progress;

  return /*#__PURE__*/_react["default"].createElement(_Container["default"], {
    animationDuration: animationDuration,
    isFinished: isFinished
  }, /*#__PURE__*/_react["default"].createElement(_Bar["default"], {
    animationDuration: animationDuration,
    progress: progress
  }));
};

var Loading = /*#__PURE__*/function (_Component) {
  _inherits(Loading, _Component);

  var _super = _createSuper(Loading);

  function Loading() {
    var _this;

    _classCallCheck(this, Loading);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "state", {
      isAnimating: false,
      key: 0
    });

    return _this;
  }

  _createClass(Loading, [{
    key: "render",
    value: function render() {
      var _cls2;

      var _this$props = this.props,
          _this$props$prefix = _this$props.prefix,
          prefix = _this$props$prefix === void 0 ? 'next-' : _this$props$prefix,
          _this$props$size = _this$props.size,
          size = _this$props$size === void 0 ? 'large' : _this$props$size,
          _this$props$type = _this$props.type,
          type = _this$props$type === void 0 ? 'circle' : _this$props$type,
          className = _this$props.className,
          fullScreen = _this$props.fullScreen,
          _this$props$visible = _this$props.visible,
          visible = _this$props$visible === void 0 ? true : _this$props$visible,
          otherProps = _objectWithoutProperties(_this$props, _excluded);

      var loading_indicator;

      if (size === 'xl' || fullScreen) {
        loading_indicator = indicator1(prefix);
      } else if (size === 'large') {
        loading_indicator = indicator2(prefix);
      } else if (size === 'medium') {
        loading_indicator = indicator3(prefix);
      } else if (size === 'small') {
        loading_indicator = indicator4(prefix);
      }

      if (type === 'global_linear') {
        var _cls;

        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Progress, {
          isAnimating: visible,
          key: this.state.key
        }), /*#__PURE__*/_react["default"].createElement(_loading["default"], _extends({
          size: "large"
        }, otherProps, {
          indicator: loading_indicator,
          visible: visible,
          className: (0, _classnames["default"])(className, (_cls = {}, _defineProperty(_cls, "".concat(prefix, "loading-default"), true), _defineProperty(_cls, "".concat(prefix, "loading-large"), true), _defineProperty(_cls, "".concat(prefix, "loading-global-circle"), true), _cls))
        })));
      }

      return /*#__PURE__*/_react["default"].createElement(_loading["default"], _extends({
        fullScreen: fullScreen,
        size: size
      }, otherProps, {
        indicator: type === 'circle' ? loading_indicator : undefined,
        visible: visible,
        className: (0, _classnames["default"])(className, (_cls2 = {}, _defineProperty(_cls2, "".concat(prefix, "loading-xl"), size === 'xl' || fullScreen), _defineProperty(_cls2, "".concat(prefix, "loading-large"), size === 'large' && !fullScreen), _defineProperty(_cls2, "".concat(prefix, "loading-medium"), size === 'medium'), _defineProperty(_cls2, "".concat(prefix, "loading-small"), size === 'small'), _defineProperty(_cls2, "".concat(prefix, "loading-linear"), type === 'linear'), _defineProperty(_cls2, "".concat(prefix, "loading-default"), type === 'circle'), _cls2))
      }));
    }
  }]);

  return Loading;
}(_react.Component);

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

exports["default"] = _default;