import { getCurrentInstance, resolveDynamicComponent, computed, toRef, onMounted, onBeforeUnmount } from "vue";
import { propsFactory } from "../../utils/dist/index.mjs";
function useRoute() {
  const vm = getCurrentInstance();
  return computed(() => {
    var _a;
    return (_a = vm == null ? void 0 : vm.proxy) == null ? void 0 : _a.$route;
  });
}
function useRouter() {
  var _a, _b;
  return (_b = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy) == null ? void 0 : _b.$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 == null ? void 0 : 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 == null ? void 0 : 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 == null ? void 0 : router.beforeEach((to, from, next) => {
      setTimeout(() => popped ? cb(next) : next());
    });
  });
  onBeforeUnmount(() => {
    window.removeEventListener("popstate", onPopstate);
    removeGuard == null ? void 0 : removeGuard();
  });
  function onPopstate(e) {
    var _a;
    if ((_a = e.state) == null ? void 0 : _a.replaced)
      return;
    popped = true;
    setTimeout(() => popped = false);
  }
}
export {
  makeRouterProps,
  useBackButton,
  useLink,
  useRoute,
  useRouter,
  useRouterHistory
};
//# sourceMappingURL=index.mjs.map
