"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.GlobalLoaderView = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));var _react = _interopRequireWildcard(require("react"));

var _Emotion = require("../../lib/theming/Emotion");
var _ZIndex = require("../../internal/ZIndex");
var _ThemeContext = require("../../lib/theming/ThemeContext");

var _CommonWrapper = require("../../internal/CommonWrapper");

var _GlobalLoaderView = require("./GlobalLoaderView.styles");
var _useParams = require("./useParams");var _excluded = ["expectedResponseTime", "delayBeforeHide", "status", "disableAnimations"];




















var GlobalLoaderView = exports.GlobalLoaderView = function GlobalLoaderView(_ref)





{var expectedResponseTime = _ref.expectedResponseTime,delayBeforeHide = _ref.delayBeforeHide,status = _ref.status,disableAnimations = _ref.disableAnimations,rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
  var ref = (0, _react.useRef)(null);
  var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
  var _useGlobalLoaderWidth = (0, _useParams.useGlobalLoaderWidth)(status, ref),width = _useGlobalLoaderWidth.width,startWidth = _useGlobalLoaderWidth.startWidth,fullWidth = _useGlobalLoaderWidth.fullWidth;
  var _useGlobalLoaderPosit = (0, _useParams.useGlobalLoaderPosition)(ref),left = _useGlobalLoaderPosit.left;

  var getAnimationClass = function getAnimationClass(status) {
    if (!disableAnimations) {
      switch (status) {
        case 'success':
          return _GlobalLoaderView.animations.successAnimation(delayBeforeHide, width, left);
        case 'accept':
          if (startWidth < fullWidth * 0.8) {
            return _GlobalLoaderView.animations.acceptAnimation(theme, startWidth, expectedResponseTime, width, left);
          }
          return _GlobalLoaderView.animations.slowAcceptAnimation(theme, startWidth, width, left);
        case 'error':
          return _GlobalLoaderView.animations.errorAnimation(theme);
        case 'standard':
          return _GlobalLoaderView.animations.standardAnimation(theme, expectedResponseTime);
      }
    }

    if (disableAnimations) {
      switch (status) {
        case 'success':
          return _GlobalLoaderView.styles.successWithoutAnimation();
        case 'accept':
          return _GlobalLoaderView.animations.acceptWithoutAnimation(startWidth);
        case 'error':
          return _GlobalLoaderView.styles.errorWithoutAnimation();
        case 'standard':
          return _GlobalLoaderView.styles.standardWithoutAnimation();
      }
    }
  };

  return /*#__PURE__*/(
    _react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({}, rest, { "data-status": status }), /*#__PURE__*/
    _react.default.createElement(_ZIndex.ZIndex, { priority: "GlobalLoader", className: _GlobalLoaderView.styles.outer(theme) }, /*#__PURE__*/
    _react.default.createElement("div", { ref: ref, className: (0, _Emotion.cx)(_GlobalLoaderView.styles.inner(theme), getAnimationClass(status)) })
    )
    ));

};