import { ref, watch, onBeforeUnmount } from 'vue';
import wrapperRaf from '../../_util/raf.mjs';
import useValueTexts from './useValueTexts.mjs';

function useHoverValue(valueText, { formatList, generateConfig, locale }) {
  const innerValue = ref(null);
  let rafId;
  function setValue(val, immediately = false) {
    wrapperRaf.cancel(rafId);
    if (immediately) {
      innerValue.value = val;
      return;
    }
    rafId = wrapperRaf(() => {
      innerValue.value = val;
    });
  }
  const [, firstText] = useValueTexts(innerValue, {
    formatList,
    generateConfig,
    locale
  });
  function onEnter(date) {
    setValue(date);
  }
  function onLeave(immediately = false) {
    setValue(null, immediately);
  }
  watch(valueText, () => {
    onLeave(true);
  });
  onBeforeUnmount(() => {
    wrapperRaf.cancel(rafId);
  });
  return [firstText, onEnter, onLeave];
}

export { useHoverValue as default };
//# sourceMappingURL=useHoverValue.mjs.map
