import { computed, getCurrentInstance, onBeforeUnmount, onMounted, resolveDynamicComponent, toRef } from "vue";
import { propsFactory } from "@veno-ui/utils";
function useRoute() {
  const vm = getCurrentInstance();
  return computed(() => vm?.proxy?.$route);
}
function useRouter() {
  return getCurrentInstance()?.proxy?.$router;
}
function useRouterHistory() {
  const router = useRouter();
  const isWebHashHistory = computed(() => router && router.options.history.base.includes("#"));
  return {
    isWebHashHistory
  };
}
function useLink(props, attrs) {
  const RouterLink = resolveDynamicComponent("RouterLink");
  const isLink = computed(() => !!(props.href || props.to));
  const isClickable = computed(() => {
    return isLink?.value || !!(attrs.onClick || attrs.onClickOnce);
  });
  if (typeof RouterLink === "string") {
    return {
      isLink,
      isClickable,
      href: toRef(props, "href")
    };
  }
  const link = props.to ? RouterLink.useLink(props) : void 0;
  return {
    ...link,
    isLink,
    isClickable,
    href: computed(() => props.to ? link?.route.value.href : props.href)
  };
}
const makeRouterProps = propsFactory({
  href: String,
  replace: Boolean,
  to: [String, Object]
}, "router");
function useBackButton(cb) {
  const router = useRouter();
  let popped = false;
  let removeGuard;
  onMounted(() => {
    window.addEventListener("popstate", onPopstate);
    removeGuard = router?.beforeEach((to, from, next) => {
      setTimeout(() => popped ? cb(next) : next());
    });
  });
  onBeforeUnmount(() => {
    window.removeEventListener("popstate", onPopstate);
    removeGuard?.();
  });
  function onPopstate(e) {
    if (e.state?.replaced)
      return;
    popped = true;
    setTimeout(() => popped = false);
  }
}
export {
  makeRouterProps,
  useBackButton,
  useLink,
  useRoute,
  useRouter,
  useRouterHistory
};
//# sourceMappingURL=index.mjs.map
