{"version":3,"file":"use-internal-link-BiVnNEEC.mjs","names":[],"sources":["../../widgets/src/hooks/use-internal-link.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useWidgetInteraction } from \"../contexts/WidgetInteractionContext\";\nimport { isBrowserHandledClick } from \"../lib/browser-click\";\n\nexport interface InternalLink {\n  /**\n   * Click handler for the anchor. Navigates in-app when the href points at a\n   * screen in this portal, and does nothing otherwise so the browser follows\n   * the link as authored — including for Cmd/Ctrl/Shift/Alt and middle clicks,\n   * which asked for a new tab or window.\n   *\n   * Returns whether the click was handled in-app, so a caller with follow-up of\n   * its own (closing a modal, say) only runs it when the user is actually\n   * staying on this page.\n   */\n  followInternally: (e: React.MouseEvent) => boolean;\n}\n\n/**\n * Resolve links that widget authors typed as plain URLs but that point back\n * into this portal (e.g. \"/profile\"). Following them as real links reloads the\n * document — or worse, opens a new tab — which throws away the in-session\n * referrer the mobile header's back button is derived from, stranding the user\n * on the destination screen. Navigating in-app instead keeps a way back.\n *\n * Returns a resolver rather than the link itself so widgets can call it per\n * item while rendering a list (carousel slides, link rows), where a hook can't\n * go. Pass undefined to opt a link out, e.g. one the author set to open in a\n * new tab.\n */\nexport function useInternalLinks(): (href: string | undefined) => InternalLink {\n  const { onNavigate, resolveInternalSlug } = useWidgetInteraction();\n\n  return useCallback(\n    (href: string | undefined) => {\n      const slug = href ? resolveInternalSlug?.(href) : undefined;\n\n      return {\n        followInternally: (e: React.MouseEvent) => {\n          if (!slug || !onNavigate || isBrowserHandledClick(e)) return false;\n          e.preventDefault();\n          onNavigate(slug);\n          return true;\n        },\n      };\n    },\n    [onNavigate, resolveInternalSlug],\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,SAAgB,mBAA+D;CAC7E,MAAM,EAAE,YAAY,wBAAwB,sBAAsB;AAElE,QAAO,aACJ,SAA6B;EAC5B,MAAM,OAAO,OAAO,sBAAsB,KAAK,GAAG,KAAA;AAElD,SAAO,EACL,mBAAmB,MAAwB;AACzC,OAAI,CAAC,QAAQ,CAAC,cAAc,sBAAsB,EAAE,CAAE,QAAO;AAC7D,KAAE,gBAAgB;AAClB,cAAW,KAAK;AAChB,UAAO;KAEV;IAEH,CAAC,YAAY,oBAAoB,CAClC"}