import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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";
var _excluded = ["children", "className", "loading", "running", "timerRef"];

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

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Box from '../box';
import Icon from '../icon';
import LoadingSpinner from '../loadingSpinner';
import { Monospaced, UITextBody } from '../typography';
import { IconTimerMediumOutline } from '@teamleader/ui-icons';
import cx from 'classnames';
import theme from './theme.css';
/** @type {React.ComponentType<any>} */

var Timer = /*#__PURE__*/function (_PureComponent) {
  _inherits(Timer, _PureComponent);

  var _super = _createSuper(Timer);

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

    return _super.apply(this, arguments);
  }

  _createClass(Timer, [{
    key: "render",
    value: function render() {
      var _cx;

      var _this$props = this.props,
          children = _this$props.children,
          className = _this$props.className,
          loading = _this$props.loading,
          running = _this$props.running,
          timerRef = _this$props.timerRef,
          others = _objectWithoutProperties(_this$props, _excluded);

      var classNames = cx(theme['timer'], (_cx = {}, _defineProperty(_cx, theme['is-loading'], loading), _defineProperty(_cx, theme['is-running'], running), _cx), className);
      return /*#__PURE__*/React.createElement(Box, _extends({}, others, {
        borderRadius: "rounded",
        className: classNames,
        "data-teamleader-ui": "timer",
        element: "button",
        alignItems: "center",
        display: "flex",
        ref: timerRef,
        paddingHorizontal: 2
      }), /*#__PURE__*/React.createElement(Icon, {
        color: running ? 'violet' : 'teal',
        tint: "darkest"
      }, /*#__PURE__*/React.createElement(IconTimerMediumOutline, null)), loading ? /*#__PURE__*/React.createElement(Box, {
        flex: 1,
        display: "flex",
        justifyContent: "center"
      }, /*#__PURE__*/React.createElement(LoadingSpinner, {
        color: running ? 'violet' : 'neutral',
        size: "small"
      })) : /*#__PURE__*/React.createElement(UITextBody, {
        element: Monospaced,
        marginLeft: 2,
        color: running ? 'violet' : 'teal'
      }, children));
    }
  }]);

  return Timer;
}(PureComponent);

Timer.defaultProps = {
  loading: false,
  running: false
};
export default Timer;