import { jsx as t, jsxs as l } from "react/jsx-runtime";
import { useState as k, useMemo as T, isValidElement as d } from "react";
import { Classes as C } from "../../constants/selectors.js";
import { useHasHover as N } from "../../hooks/use-has-hover.js";
import { cn as u } from "../../utils/cn.js";
import { isRemoteUrl as P } from "../../utils/is-remote-url.js";
import { renderAsChild as w } from "../../utils/render-as-child.js";
import O from "../../node_modules/.pnpm/lucide-react@0.453.0_react@18.3.1/node_modules/lucide-react/dist/esm/icons/chevron-right.js";
import { TooltipProvider as j } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/provider/TooltipProvider.js";
import { TooltipRoot as H } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/root/TooltipRoot.js";
import { TooltipTrigger as R } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/trigger/TooltipTrigger.js";
import { TooltipPortal as z } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/portal/TooltipPortal.js";
import { TooltipPositioner as E } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/positioner/TooltipPositioner.js";
import { TooltipPopup as I } from "../../node_modules/.pnpm/@base-ui_react@1.1.0_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/react/esm/tooltip/popup/TooltipPopup.js";
const X = ({
  description: e,
  children: n,
  title: o,
  cta: p,
  href: a,
  className: c,
  side: x = "top",
  align: g = "center"
}) => {
  const [b, i] = k(!1), m = N(), r = L(n), v = m ? void 0 : () => {
    i((s) => !s);
  }, y = (s, _) => {
    const { reason: f } = _;
    if (m) {
      i(s);
      return;
    }
    s ? i(!0) : (f === "escape-key" || f === "outside-press") && i(!1);
  }, h = T(() => {
    if (!r)
      return o && e ? `${o}: ${e}` : o || e;
  }, [o, e, r]);
  return n == null ? null : /* @__PURE__ */ t(j, { delay: 0, children: /* @__PURE__ */ l(H, { onOpenChange: y, open: b, children: [
    /* @__PURE__ */ t(
      R,
      {
        "aria-label": h,
        className: u(
          c,
          !r && "rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2"
        ),
        onClick: v,
        render: r ? w(n) : void 0,
        children: r ? null : W(n)
      }
    ),
    /* @__PURE__ */ t(z, { children: /* @__PURE__ */ t(
      E,
      {
        align: g,
        collisionPadding: 8,
        side: x,
        sideOffset: 4,
        children: /* @__PURE__ */ l(
          I,
          {
            className: "z-50 flex max-w-[16rem] flex-col gap-1 rounded-xl border border-stone-200 bg-white px-4 py-3 shadow-[0_10px_16px_-3px_rgb(10_10_10/0.05),0_3px_10px_-2px_rgb(10_10_10/0.02)] dark:border-stone-900 dark:bg-stone-950",
            "data-component-part": "tooltip-content",
            children: [
              !!o && /* @__PURE__ */ t(
                "p",
                {
                  className: "font-medium text-stone-900 text-xs leading-4 dark:text-stone-200",
                  "data-component-part": "tooltip-title",
                  children: o
                }
              ),
              !!e && /* @__PURE__ */ t(
                "p",
                {
                  className: "text-stone-600 text-xs leading-4 dark:text-stone-400",
                  "data-component-part": "tooltip-description",
                  children: e
                }
              ),
              p && a && /* @__PURE__ */ l(
                "a",
                {
                  href: a,
                  ...P(a) ? { target: "_blank", rel: "noreferrer" } : {},
                  className: "mt-2! flex items-center gap-0.5 rounded-sm font-medium text-stone-600 text-xs leading-4 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 dark:text-stone-400 dark:hover:text-primary-light",
                  "data-component-part": "tooltip-cta",
                  children: [
                    p,
                    /* @__PURE__ */ t(
                      O,
                      {
                        "aria-hidden": "true",
                        className: "size-3",
                        strokeWidth: 2.5
                      }
                    )
                  ]
                }
              )
            ]
          }
        )
      }
    ) })
  ] }) });
}, L = (e) => d(e) ? typeof e.type == "function" || typeof e.type == "object" ? !0 : typeof e.type == "string" ? ["button", "a", "input", "select", "textarea"].includes(
  e.type.toLowerCase()
) : !1 : !1, W = (e) => d(e) ? e : /* @__PURE__ */ t(
  "span",
  {
    className: u(
      C.Tooltip,
      "underline decoration-2 decoration-stone-400 decoration-dotted underline-offset-4 dark:decoration-stone-500"
    ),
    children: e
  }
);
export {
  X as Tooltip
};
