import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["active", "className", "withOverlay", "small"];

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

/**
 * Copyright IBM Corp. 2016, 2018
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import { settings } from '../../globals/js';
import { componentsX } from '../../internal/FeatureFlags';
var prefix = 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) {
  _inherits(Loading, _React$Component);

  var _super = _createSuper(Loading);

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

    return _super.apply(this, arguments);
  }

  _createClass(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 = _objectWithoutProperties(_this$props, _excluded);

      var loadingClasses = classNames("".concat(prefix, "--loading"), className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "--loading--small"), small), _defineProperty(_classNames, "".concat(prefix, "--loading--stop"), !active), _classNames));
      var overlayClasses = classNames("".concat(prefix, "--loading-overlay"), _defineProperty({}, "".concat(prefix, "--loading-overlay--stop"), !active));
      var loading = /*#__PURE__*/React.createElement("div", _extends({}, other, {
        "aria-live": active ? 'assertive' : 'off',
        className: loadingClasses
      }), /*#__PURE__*/React.createElement("svg", {
        className: "".concat(prefix, "--loading__svg"),
        viewBox: "-75 -75 150 150"
      }, /*#__PURE__*/React.createElement("title", null, "Loading"), componentsX && small ? /*#__PURE__*/React.createElement("circle", {
        className: "".concat(prefix, "--loading__background"),
        cx: "0",
        cy: "0",
        r: "37.5"
      }) : null, /*#__PURE__*/React.createElement("circle", {
        className: componentsX ? "".concat(prefix, "--loading__stroke") : null,
        cx: "0",
        cy: "0",
        r: "37.5"
      })));
      return withOverlay ? /*#__PURE__*/React.createElement("div", {
        className: overlayClasses
      }, loading) : loading;
    }
  }]);

  return Loading;
}(React.Component);

_defineProperty(Loading, "propTypes", {
  /**
   * Specify whether you want the loading indicator to be spinning or not
   */
  active: PropTypes.bool,

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

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

  /**
   * Specify whether you would like the small variant of <Loading>
   */
  small: PropTypes.bool
});

_defineProperty(Loading, "defaultProps", {
  active: true,
  withOverlay: true,
  small: false
});

export { Loading as default };