import { n as useTimestamp, p as useDocumentVisibility, q as useElementHover } from "./index-nMtnPEP0.mjs";
import { readonly, toRef, ref, watch, computed, toValue } from "vue";
const useCountdown = (length, interval, timestampOpts = {}) => {
  const resolvedLength = readonly(toRef(length));
  const isPaused = ref(false);
  const target = ref(Date.now() + resolvedLength.value);
  const { isActive, pause, resume, timestamp } = useTimestamp({
    interval,
    controls: true,
    callback: (v) => {
      if (v >= target.value) {
        isPaused.value = false;
        pause();
      }
    },
    ...timestampOpts
  });
  const visibility = useDocumentVisibility();
  watch(visibility, (newVisibility) => {
    if (newVisibility === "visible" && isActive.value && !isPaused.value) {
      if (Date.now() >= target.value) {
        isPaused.value = false;
        pause();
      }
    }
  });
  const value = computed(() => target.value - timestamp.value);
  const restart = () => {
    target.value = Date.now() + resolvedLength.value;
    resume();
  };
  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: readonly(isActive),
    isPaused: readonly(isPaused),
    stop,
    pause: myPause,
    resume: myResume,
    restart,
    value
  };
};
const useCountdownHover = (element, {
  modelValueIgnoresHover,
  noHoverPause,
  noResumeOnHoverLeave
}, actions) => {
  const isHovering = useElementHover(element);
  const onMouseEnter = () => {
    if (toValue(noHoverPause)) return;
    actions.pause();
  };
  const onMouseLeave = () => {
    if (toValue(noResumeOnHoverLeave)) return;
    actions.resume();
  };
  watch(isHovering, (newValue) => {
    if (toValue(modelValueIgnoresHover)) return;
    if (newValue) {
      onMouseEnter();
      return;
    }
    onMouseLeave();
  });
  return {
    isHovering
  };
};
export {
  useCountdownHover as a,
  useCountdown as u
};
//# sourceMappingURL=useCountdownHover-iDB53fJr.mjs.map
