"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

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

var _js = require("../../globals/js");

var _FeatureFlags = require("../../internal/FeatureFlags");

var _excluded = ["active", "className", "withOverlay", "small"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

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

var prefix = _js.settings.prefix;
/** Loading spinners are used when retrieving data or performing slow computations, and help to notify users that loading is underway. */

var Loading = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2.default)(Loading, _React$Component);

  var _super = _createSuper(Loading);

  function Loading() {
    (0, _classCallCheck2.default)(this, Loading);
    return _super.apply(this, arguments);
  }

  (0, _createClass2.default)(Loading, [{
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props = this.props,
          active = _this$props.active,
          className = _this$props.className,
          withOverlay = _this$props.withOverlay,
          small = _this$props.small,
          other = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
      var loadingClasses = (0, _classnames.default)("".concat(prefix, "--loading"), className, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--loading--small"), small), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--loading--stop"), !active), _classNames));
      var overlayClasses = (0, _classnames.default)("".concat(prefix, "--loading-overlay"), (0, _defineProperty2.default)({}, "".concat(prefix, "--loading-overlay--stop"), !active));

      var loading = /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, other, {
        "aria-live": active ? 'assertive' : 'off',
        className: loadingClasses
      }), /*#__PURE__*/_react.default.createElement("svg", {
        className: "".concat(prefix, "--loading__svg"),
        viewBox: "-75 -75 150 150"
      }, /*#__PURE__*/_react.default.createElement("title", null, "Loading"), _FeatureFlags.componentsX && small ? /*#__PURE__*/_react.default.createElement("circle", {
        className: "".concat(prefix, "--loading__background"),
        cx: "0",
        cy: "0",
        r: "37.5"
      }) : null, /*#__PURE__*/_react.default.createElement("circle", {
        className: _FeatureFlags.componentsX ? "".concat(prefix, "--loading__stroke") : null,
        cx: "0",
        cy: "0",
        r: "37.5"
      })));

      return withOverlay ? /*#__PURE__*/_react.default.createElement("div", {
        className: overlayClasses
      }, loading) : loading;
    }
  }]);
  return Loading;
}(_react.default.Component);

exports.default = Loading;
(0, _defineProperty2.default)(Loading, "propTypes", {
  /**
   * Specify whether you want the loading indicator to be spinning or not
   */
  active: _propTypes.default.bool,

  /**
   * Provide an optional className to be applied to the containing node
   */
  className: _propTypes.default.string,

  /**
   * Specify whether you want the loader to be applied with an overlay
   */
  withOverlay: _propTypes.default.bool,

  /**
   * Specify whether you would like the small variant of <Loading>
   */
  small: _propTypes.default.bool
});
(0, _defineProperty2.default)(Loading, "defaultProps", {
  active: true,
  withOverlay: true,
  small: false
});