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 = ["className", "success", "description", "onSuccess", "successDelay"];

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 Loading from '../Loading';
var prefix = settings.prefix;

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

  var _super = _createSuper(InlineLoading);

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

    return _super.apply(this, arguments);
  }

  _createClass(InlineLoading, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          success = _this$props.success,
          description = _this$props.description,
          onSuccess = _this$props.onSuccess,
          successDelay = _this$props.successDelay,
          other = _objectWithoutProperties(_this$props, _excluded);

      var loadingClasses = classNames("".concat(prefix, "--inline-loading"), className);

      var getLoading = function getLoading() {
        if (success) {
          setTimeout(function () {
            if (onSuccess) {
              onSuccess();
            }
          }, successDelay);
          return /*#__PURE__*/React.createElement("svg", {
            className: "".concat(prefix, "--inline-loading__checkmark-container ").concat(prefix, "--inline-loading__svg"),
            xmlns: "http://www.w3.org/2000/svg",
            viewBox: "0 0 10 10"
          }, /*#__PURE__*/React.createElement("polyline", {
            className: "".concat(prefix, "--inline-loading__checkmark"),
            points: "0.74 3.4 3.67 6.34 9.24 0.74"
          }));
        }

        return /*#__PURE__*/React.createElement(Loading, {
          small: true,
          withOverlay: false
        });
      };

      var loadingText = /*#__PURE__*/React.createElement("p", {
        className: "".concat(prefix, "--inline-loading__text")
      }, description);
      return /*#__PURE__*/React.createElement("div", _extends({
        className: loadingClasses
      }, other), /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefix, "--inline-loading__animation")
      }, getLoading()), description && loadingText);
    }
  }]);

  return InlineLoading;
}(React.Component);

_defineProperty(InlineLoading, "propTypes", {
  /**
   * Specify a custom className to be applied to the container node
   */
  className: PropTypes.string,

  /**
   * Specify whether the load was successful
   */
  success: PropTypes.bool,

  /**
   * Specify the description for the inline loading text
   */
  description: PropTypes.string,

  /**
   * Provide an optional handler to be invoked when <InlineLoading> is
   * successful
   */
  onSuccess: PropTypes.func,

  /**
   * Provide a delay for the `setTimeout` for success
   */
  successDelay: PropTypes.number
});

_defineProperty(InlineLoading, "defaultProps", {
  success: false,
  successDelay: 1500
});

export { InlineLoading as default };