import { useConfig as b } from "./useConfig.js";
import { combineUrlAndPath as d } from "@scalar/helpers/url/merge-urls";
import { slug as i } from "github-slugger";
import { inject as y, ref as l } from "vue";
const P = Symbol(), U = l(!1), x = l(""), k = l(""), T = (f) => {
  const { isIntersectionEnabled: p, hash: r, hashPrefix: u } = y(P, {
    isIntersectionEnabled: U,
    hash: x,
    hashPrefix: k
  }), t = f ?? b(), c = (e) => {
    var a;
    if (!t.value.pathRouting)
      return "";
    const n = new RegExp("^" + ((a = t.value.pathRouting) == null ? void 0 : a.basePath) + "/?");
    return decodeURIComponent(e.replace(n, ""));
  }, v = (e = r.value) => {
    var h;
    const n = (h = e.match(/(tag\/[^/]+)/)) == null ? void 0 : h[0], a = e.startsWith("model") ? "models" : "", o = e.startsWith("webhook") ? "webhooks" : "";
    return n || a || o;
  }, g = () => t.value.pathRouting ? c(window.location.pathname) : (
    // Must remove the prefix from the hash as the internal hash value should be pure
    decodeURIComponent(window.location.hash.replace(/^#/, "")).slice(u.value.length)
  ), m = () => r.value = g(), $ = (e, n = window.location.href) => {
    const a = new URL(n);
    t.value.pathRouting ? a.pathname = d(t.value.pathRouting.basePath, e) : a.hash = u.value + e, r.value = e, window.history.replaceState({}, "", a);
  }, I = (e, n = window.location.href, a = window.location.search) => {
    const o = new URL(n);
    return t.value.pathRouting ? o.pathname = d(t.value.pathRouting.basePath, e) : o.hash = u.value + e, o.search = a, o.toString();
  }, w = (e = r.value) => `${u.value}${e}`, S = (e) => typeof t.value.generateHeadingSlug == "function" ? `${t.value.generateHeadingSlug(e)}` : e.slug ? `description/${e.slug}` : "", R = (e, n) => {
    if (!(e != null && e.name))
      return "models";
    const a = n ? `${s(n)}/` : "";
    return typeof t.value.generateModelSlug == "function" ? `${a}model/${t.value.generateModelSlug(e)}` : `${a}model/${i(e.name)}`;
  }, s = (e) => typeof t.value.generateTagSlug == "function" ? `tag/${t.value.generateTagSlug(e)}` : `tag/${i(e.name ?? "")}`;
  return {
    hash: r,
    /** Sets the prefix for the hash */
    setHashPrefix: (e) => {
      u.value = e;
    },
    /**
     * Gets the full hash with the prefix
     * @param hashTarget The hash to target with the return
     * @returns The full hash
     */
    getFullHash: w,
    /**
     * Gets the hashed url with the prefix
     * @param replacementHash The hash to replace the current hash with
     * @param url The url to get the hashed url from
     * @returns The hashed url
     */
    getHashedUrl: I,
    /**
     * Replaces the URL state with the new url and hash
     * Replacement is used so that hash changes don't trigger the url hash watcher and cause a scroll
     */
    replaceUrlState: $,
    getReferenceId: g,
    getWebhookId: (e, n) => {
      if (!(e != null && e.name))
        return "webhooks";
      const a = n ? `${s(n)}/` : "";
      return typeof t.value.generateWebhookSlug == "function" ? `${a}webhook/${t.value.generateWebhookSlug(e)}` : `${a}webhook/${e.method}/${i(e.name)}`;
    },
    getModelId: R,
    getHeadingId: S,
    getOperationId: (e, n) => typeof t.value.generateOperationSlug == "function" ? `${s(n)}/${t.value.generateOperationSlug({
      path: e.path,
      operationId: e.operationId,
      method: e.method,
      summary: e.summary
    })}` : `${s(n)}/${e.method}${e.path}`,
    getPathRoutingId: c,
    getSectionId: v,
    getTagId: s,
    isIntersectionEnabled: p,
    updateHash: m
  };
};
export {
  P as NAV_STATE_SYMBOL,
  T as useNavState
};
