import { a as D, j as e } from "./DocsApp-CEu0IOyd.js";
import { useCallback as c } from "react";
import { useNavigate as A, useLocation as Q } from "react-router-dom";
import { C as W, a as _, b as J, c as k, d as C, e as t, f as y, g as w, h as f, i as v, j as P, k as d } from "./context-menu-BX0jqPJI.js";
const K = {
  "zh-cn": {
    page: "页面",
    copyUrl: "复制当前链接",
    copyTitle: "复制页面标题",
    copyMarkdownLink: "复制 Markdown 链接",
    copySelectedText: "复制",
    openInNewTab: "在新标签页打开",
    reload: "刷新",
    printPage: "打印页面",
    scrollToTop: "回到顶部",
    scrollToBottom: "滚动到底部",
    site: "站点",
    goHome: "返回首页",
    quickNav: "快速跳转",
    docsIndex: "文档首页",
    guide: "指南",
    introduction: "简介",
    installation: "安装",
    quickStart: "快速开始",
    configuration: "配置",
    language: "语言",
    appearance: "外观",
    theme: "主题",
    light: "浅色",
    dark: "深色",
    system: "跟随系统",
    resetThemePref: "重置主题偏好"
  },
  en: {
    page: "Page",
    copyUrl: "Copy Current URL",
    copyTitle: "Copy Page Title",
    copyMarkdownLink: "Copy Markdown Link",
    copySelectedText: "Copy",
    openInNewTab: "Open in New Tab",
    reload: "Reload",
    printPage: "Print Page",
    scrollToTop: "Scroll to Top",
    scrollToBottom: "Scroll to Bottom",
    site: "Site",
    goHome: "Go Home",
    quickNav: "Quick Navigation",
    docsIndex: "Docs Index",
    guide: "Guide",
    introduction: "Introduction",
    installation: "Installation",
    quickStart: "Quick Start",
    configuration: "Configuration",
    language: "Language",
    appearance: "Appearance",
    theme: "Theme",
    light: "Light",
    dark: "Dark",
    system: "System",
    resetThemePref: "Reset Theme Preference"
  }
}, x = {
  enabled: !0,
  page: {
    copyUrl: !0,
    copyTitle: !0,
    copyMarkdownLink: !0,
    copySelectedText: !0,
    openInNewTab: !0,
    reload: !0,
    printPage: !0,
    scrollToTop: !0,
    scrollToBottom: !0
  },
  site: {
    goHome: !0,
    quickNav: !0,
    language: !0
  },
  appearance: {
    theme: !0,
    resetThemePref: !0
  }
};
function ee({
  children: b,
  config: S
}) {
  const l = A(), m = Q(), { theme: N, setTheme: g } = D(), s = c(async (a) => {
    if (navigator.clipboard && window.isSecureContext)
      await navigator.clipboard.writeText(a);
    else {
      const n = document.createElement("textarea");
      n.value = a, n.style.position = "fixed", n.style.left = "-9999px", n.style.top = "-9999px", document.body.appendChild(n), n.focus(), n.select();
      try {
        document.execCommand("copy");
      } finally {
        document.body.removeChild(n);
      }
    }
  }, []), L = c(async () => {
    try {
      await s(window.location.href);
    } catch {
    }
  }, [s]), B = c(async () => {
    try {
      await s(document.title || "");
    } catch {
    }
  }, [s]), q = c(async () => {
    try {
      const a = document.title || "Docs", n = window.location.href;
      await s(`[${a}](${n})`);
    } catch {
    }
  }, [s]), H = c(async () => {
    try {
      const a = window.getSelection()?.toString() || "";
      a && await s(a);
    } catch {
    }
  }, [s]), U = c(() => {
    window.open(window.location.href, "_blank");
  }, []), R = c(() => {
    window.location.reload();
  }, []), z = c(() => l("/"), [l]), u = m.pathname.startsWith("/en") ? "en" : "zh-cn", o = K[u], M = c(
    (a) => {
      const n = m.pathname.split("/").filter(Boolean);
      n.length > 0 && (n[0] === "en" || n[0] === "zh-cn") ? n[0] = a : n.unshift(a), l("/" + n.join("/"));
    },
    [m.pathname, l]
  ), G = c(() => window.scrollTo({ top: 0, behavior: "smooth" }), []), E = c(
    () => window.scrollTo({ top: document.documentElement.scrollHeight, behavior: "smooth" }),
    []
  ), F = c(() => window.print(), []), r = c((a) => l(`/${u}/${a}`), [l, u]), O = c(() => {
    try {
      localStorage.removeItem("vite-ui-theme");
    } catch {
    }
  }, []), p = S?.enabled === !1 ? null : { ...x, ...S };
  if (!p)
    return /* @__PURE__ */ e.jsx("div", { className: "min-h-screen", children: b });
  const i = { ...x.page, ...p.page }, h = { ...x.site, ...p.site }, T = { ...x.appearance, ...p.appearance }, j = Object.values(i).some(Boolean), I = Object.values(h).some(Boolean), $ = Object.values(T).some(Boolean);
  return /* @__PURE__ */ e.jsxs(W, { children: [
    /* @__PURE__ */ e.jsx(_, { asChild: !0, children: /* @__PURE__ */ e.jsx("div", { className: "min-h-screen", children: b }) }),
    /* @__PURE__ */ e.jsxs(J, { children: [
      j && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
        /* @__PURE__ */ e.jsx(k, { children: o.page }),
        /* @__PURE__ */ e.jsxs(C, { children: [
          i.copyUrl && /* @__PURE__ */ e.jsx(t, { onClick: L, children: o.copyUrl }),
          i.copyTitle && /* @__PURE__ */ e.jsx(t, { onClick: B, children: o.copyTitle }),
          i.copyMarkdownLink && /* @__PURE__ */ e.jsx(t, { onClick: q, children: o.copyMarkdownLink }),
          i.copySelectedText && /* @__PURE__ */ e.jsx(t, { onClick: H, children: o.copySelectedText }),
          i.openInNewTab && /* @__PURE__ */ e.jsx(t, { onClick: U, children: o.openInNewTab }),
          i.reload && /* @__PURE__ */ e.jsx(t, { onClick: R, children: o.reload }),
          i.printPage && /* @__PURE__ */ e.jsx(t, { onClick: F, children: o.printPage }),
          (i.scrollToTop || i.scrollToBottom) && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
            /* @__PURE__ */ e.jsx(y, {}),
            i.scrollToTop && /* @__PURE__ */ e.jsx(t, { onClick: G, children: o.scrollToTop }),
            i.scrollToBottom && /* @__PURE__ */ e.jsx(t, { onClick: E, children: o.scrollToBottom })
          ] })
        ] })
      ] }),
      I && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
        j && /* @__PURE__ */ e.jsx(y, {}),
        /* @__PURE__ */ e.jsx(k, { children: o.site }),
        /* @__PURE__ */ e.jsxs(C, { children: [
          h.goHome && /* @__PURE__ */ e.jsx(t, { onClick: z, children: o.goHome }),
          h.quickNav && /* @__PURE__ */ e.jsxs(w, { children: [
            /* @__PURE__ */ e.jsx(f, { children: o.quickNav }),
            /* @__PURE__ */ e.jsxs(v, { children: [
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("index"), children: o.docsIndex }),
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("guide"), children: o.guide }),
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("guide/introduction"), children: o.introduction }),
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("guide/installation"), children: o.installation }),
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("guide/quick-start"), children: o.quickStart }),
              /* @__PURE__ */ e.jsx(t, { onClick: () => r("guide/configuration"), children: o.configuration })
            ] })
          ] }),
          h.language && /* @__PURE__ */ e.jsxs(w, { children: [
            /* @__PURE__ */ e.jsx(f, { children: o.language }),
            /* @__PURE__ */ e.jsx(v, { children: /* @__PURE__ */ e.jsxs(P, { value: u, children: [
              /* @__PURE__ */ e.jsx(d, { value: "en", onClick: () => M("en"), children: "English" }),
              /* @__PURE__ */ e.jsx(d, { value: "zh-cn", onClick: () => M("zh-cn"), children: "简体中文" })
            ] }) })
          ] })
        ] })
      ] }),
      $ && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
        (j || I) && /* @__PURE__ */ e.jsx(y, {}),
        /* @__PURE__ */ e.jsx(k, { children: o.appearance }),
        /* @__PURE__ */ e.jsxs(C, { children: [
          T.theme && /* @__PURE__ */ e.jsxs(w, { children: [
            /* @__PURE__ */ e.jsx(f, { children: o.theme }),
            /* @__PURE__ */ e.jsx(v, { children: /* @__PURE__ */ e.jsxs(P, { value: N, children: [
              /* @__PURE__ */ e.jsx(d, { value: "light", onClick: () => g("light"), children: o.light }),
              /* @__PURE__ */ e.jsx(d, { value: "dark", onClick: () => g("dark"), children: o.dark }),
              /* @__PURE__ */ e.jsx(d, { value: "system", onClick: () => g("system"), children: o.system })
            ] }) })
          ] }),
          T.resetThemePref && /* @__PURE__ */ e.jsx(t, { onClick: O, children: o.resetThemePref })
        ] })
      ] })
    ] })
  ] });
}
export {
  ee as GlobalContextMenu
};
