"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.Loader = void 0;
var _base = _interopRequireDefault(require("@emotion/styled/base"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react2 = require("@emotion/react");
var _reactTransitionGroup = require("react-transition-group");
var _styles = require("./styles");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
const styles = {
  disabled: process.env.NODE_ENV === "production" ? {
    name: "v06iuk-disabled",
    styles: "display:none;label:disabled;"
  } : {
    name: "v06iuk-disabled",
    styles: "display:none;label:disabled;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4816 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  },
  active: process.env.NODE_ENV === "production" ? {
    name: "1426nog-active",
    styles: "display:block;label:active;"
  } : {
    name: "1426nog-active",
    styles: "display:block;label:active;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4816 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  },
  enter: process.env.NODE_ENV === "production" ? {
    name: "1rrod3j-enter",
    styles: "opacity:0.01;label:enter;"
  } : {
    name: "1rrod3j-enter",
    styles: "opacity:0.01;label:enter;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4816 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  },
  enterActive: process.env.NODE_ENV === "production" ? {
    name: "ssvs1t-enterActive",
    styles: "opacity:1;transition:opacity 500ms ease-in;label:enterActive;"
  } : {
    name: "ssvs1t-enterActive",
    styles: "opacity:1;transition:opacity 500ms ease-in;label:enterActive;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4820 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  },
  exit: process.env.NODE_ENV === "production" ? {
    name: "t407yk-exit",
    styles: "opacity:1;label:exit;"
  } : {
    name: "t407yk-exit",
    styles: "opacity:1;label:exit;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4816 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  },
  exitActive: process.env.NODE_ENV === "production" ? {
    name: "1npgmu6-exitActive",
    styles: "opacity:0.01;transition:opacity 300ms ease-in;label:exitActive;"
  } : {
    name: "1npgmu6-exitActive",
    styles: "opacity:0.01;transition:opacity 300ms ease-in;label:exitActive;",
    map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4820 characters] */",
    toString: _EMOTION_STRINGIFIED_CSS_ERROR__
  }
};
const animations = {
  loader: (0, _react2.keyframes)`
    from {
      transform: rotate(0deg);
    }

    to {
      transform: rotate(360deg);
    }
  `
};
const LoaderText = /*#__PURE__*/(0, _base.default)("div", {
  target: "ep2bezb2",
  label: "LoaderText"
})(process.env.NODE_ENV === "production" ? {
  name: "xpdb8l",
  styles: "width:auto!important;height:auto!important;text-align:center;color:#767676;margin-top:55px;line-height:35px"
} : {
  name: "xpdb8l",
  styles: "width:auto!important;height:auto!important;text-align:center;color:#767676;margin-top:55px;line-height:35px",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4820 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
const LoaderItem = /*#__PURE__*/(0, _base.default)("div", {
  target: "ep2bezb1",
  label: "LoaderItem"
})(process.env.NODE_ENV === "production" ? {
  name: "12zl32h",
  styles: "position:absolute;white-space:nowrap;transform:translateX(-50%)"
} : {
  name: "12zl32h",
  styles: "position:absolute;white-space:nowrap;transform:translateX(-50%)",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4820 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
class Loader extends _react.default.Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "state", {
      currentItem: 0
    });
    _defineProperty(this, "setAnimation", () => {
      if (this.interval) return;
      const {
        children
      } = this.props;
      this.interval = setInterval(() => {
        const nextItem = this.state.currentItem === children.length - 1 ? 0 : this.state.currentItem + 1;
        this.setState({
          currentItem: nextItem
        });
      }, 5000);
    });
    _defineProperty(this, "renderChild", () => {
      const {
        children
      } = this.props;
      const {
        currentItem
      } = this.state;
      if (!children) {
        return null;
      } else if (typeof children == 'string') {
        return (0, _react2.jsx)(LoaderText, null, children);
      } else if (Array.isArray(children)) {
        this.setAnimation();
        return (0, _react2.jsx)(LoaderText, null, (0, _react2.jsx)(_reactTransitionGroup.CSSTransition, {
          className: {
            enter: styles.enter,
            enterActive: styles.enterActive,
            exit: styles.exit,
            exitActive: styles.exitActive
          },
          timeout: 500
        }, (0, _react2.jsx)(LoaderItem, {
          key: currentItem
        }, children[currentItem])));
      }
    });
  }
  componentWillUnmount() {
    if (this.interval) {
      clearInterval(this.interval);
    }
  }
  render() {
    const {
      className
    } = this.props;
    return (0, _react2.jsx)("div", {
      className: className
    }, this.renderChild());
  }
}
exports.Loader = Loader;
_defineProperty(Loader, "propTypes", {
  children: _propTypes.default.node,
  className: _propTypes.default.string
});
const StyledLoader = /*#__PURE__*/(0, _base.default)(Loader, {
  target: "ep2bezb0",
  label: "StyledLoader"
})("display:", props => props.active ? 'block' : 'none', ";position:absolute;top:50%;left:50%;margin:0;text-align:center;z-index:", _styles.zIndex.zIndex1000, ";transform:translateX(-50%) translateY(-50%);&:before,&:after{content:'';position:absolute;top:0%;left:50%;width:2.2857rem;height:2.2857rem;margin:0 0 0 -1.1429rem;border-radius:500rem;border-style:solid;border-width:0.2em;}&:before{border-color:rgba(0, 0, 0, 0.1);}&:after{animation:", animations.loader, " 0.6s linear;animation-iteration-count:infinite;border-color:", _styles.colors.active, " transparent transparent;box-shadow:0 0 0 1px transparent;}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4820 characters] */"));
var _default = exports.default = StyledLoader;