"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 _Loading = _interopRequireDefault(require("../Loading"));

var _excluded = ["className", "success", "description", "onSuccess", "successDelay"];

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;

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

  var _super = _createSuper(InlineLoading);

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

  (0, _createClass2.default)(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 = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
      var loadingClasses = (0, _classnames.default)("".concat(prefix, "--inline-loading"), className);

      var getLoading = function getLoading() {
        if (success) {
          setTimeout(function () {
            if (onSuccess) {
              onSuccess();
            }
          }, successDelay);
          return /*#__PURE__*/_react.default.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.default.createElement("polyline", {
            className: "".concat(prefix, "--inline-loading__checkmark"),
            points: "0.74 3.4 3.67 6.34 9.24 0.74"
          }));
        }

        return /*#__PURE__*/_react.default.createElement(_Loading.default, {
          small: true,
          withOverlay: false
        });
      };

      var loadingText = /*#__PURE__*/_react.default.createElement("p", {
        className: "".concat(prefix, "--inline-loading__text")
      }, description);

      return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
        className: loadingClasses
      }, other), /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(prefix, "--inline-loading__animation")
      }, getLoading()), description && loadingText);
    }
  }]);
  return InlineLoading;
}(_react.default.Component);

exports.default = InlineLoading;
(0, _defineProperty2.default)(InlineLoading, "propTypes", {
  /**
   * Specify a custom className to be applied to the container node
   */
  className: _propTypes.default.string,

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

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

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

  /**
   * Provide a delay for the `setTimeout` for success
   */
  successDelay: _propTypes.default.number
});
(0, _defineProperty2.default)(InlineLoading, "defaultProps", {
  success: false,
  successDelay: 1500
});