"use strict";
const index = require("./index-C_bsiScj.js");
const vue = require("vue");
const useCountdown = (length, interval, timestampOpts = {}) => {
  const resolvedLength = vue.readonly(vue.toRef(length));
  const isPaused = vue.ref(false);
  const target = vue.ref(Date.now() + resolvedLength.value);
  const { isActive, pause, resume, timestamp } = index.useTimestamp({
    interval,
    controls: true,
    callback: (v) => {
      if (v >= target.value) {
        isPaused.value = false;
        pause();
      }
    },
    ...timestampOpts
  });
  const visibility = index.useDocumentVisibility();
  vue.watch(visibility, (newVisibility) => {
    if (newVisibility === "visible" && isActive.value && !isPaused.value) {
      if (Date.now() >= target.value) {
        isPaused.value = false;
        pause();
      }
    }
  });
  const value = vue.computed(() => target.value - timestamp.value);
  const restart = () => {
    target.value = Date.now() + resolvedLength.value;
    resume();
  };
  vue.watch(resolvedLength, () => {
    if (resolvedLength.value > 0) {
      restart();
    }
  });
  const myPause = () => {
    isPaused.value = true;
    pause();
  };
  const myResume = () => {
    isPaused.value = false;
    const remainingTime = target.value - timestamp.value;
    target.value = Date.now() + remainingTime;
    resume();
  };
  const stop = () => {
    pause();
    timestamp.value = target.value;
    isPaused.value = false;
  };
  return {
    isActive: vue.readonly(isActive),
    isPaused: vue.readonly(isPaused),
    stop,
    pause: myPause,
    resume: myResume,
    restart,
    value
  };
};
const useCountdownHover = (element, {
  modelValueIgnoresHover,
  noHoverPause,
  noResumeOnHoverLeave
}, actions) => {
  const isHovering = index.useElementHover(element);
  const onMouseEnter = () => {
    if (vue.toValue(noHoverPause)) return;
    actions.pause();
  };
  const onMouseLeave = () => {
    if (vue.toValue(noResumeOnHoverLeave)) return;
    actions.resume();
  };
  vue.watch(isHovering, (newValue) => {
    if (vue.toValue(modelValueIgnoresHover)) return;
    if (newValue) {
      onMouseEnter();
      return;
    }
    onMouseLeave();
  });
  return {
    isHovering
  };
};
exports.useCountdown = useCountdown;
exports.useCountdownHover = useCountdownHover;
//# sourceMappingURL=useCountdownHover-sffPPwQG.js.map
