import React from 'react';

/* TYPES */

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */

/* HOOK */
/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function useTimer(config) {
  var timer = React.useRef(null);
  return {
    cancel: function cancel() {
      timer.current && clearTimeout(timer.current);
    },
    reset: function reset() {
      timer.current && clearTimeout(timer.current);
    },
    setTimer: function setTimer(callback, duration) {
      timer.current && clearTimeout(timer.current);
      timer.current = window.setTimeout(callback, duration);
    },
    timerId: timer.current
  };
}

/* RENDER PROP */

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function Timer(_ref) {
  var children = _ref.children;
  var timer = useTimer({});
  return typeof children === 'function' ? children(timer) : children;
}

/* CONTEXT */

var noop = function noop(method) {
  return function () {
    return console.warn("Could not call `".concat(method, "`, please wrap your component in a `<TimerProvider>`"));
  };
};

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export var TimerContext = /*#__PURE__*/React.createContext({
  cancel: noop('cancel'),
  reset: noop('reset'),
  setTimer: noop('setTimer'),
  timerId: null
});

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function TimerProvider(_ref2) {
  var children = _ref2.children;
  return /*#__PURE__*/React.createElement(TimerContext.Provider, {
    value: useTimer({})
  }, children);
}

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function useTimerContext() {
  return React.useContext(TimerContext);
}
//# sourceMappingURL=Timer.js.map