{"version":3,"file":"WidgetInteractionContext-D9dBJ-39.cjs","names":[],"sources":["../../widgets/src/contexts/WidgetInteractionContext.tsx"],"sourcesContent":["import React, {\n  createContext,\n  useContext,\n  useMemo,\n  type ReactNode,\n} from \"react\";\n\nexport interface WidgetInteractionItem {\n  id: string | number;\n  [key: string]: unknown;\n}\n\ninterface WidgetInteractionContextValue {\n  onItemClick?: (item: WidgetInteractionItem) => void;\n  /** Navigate to an internal screen by slug */\n  onNavigate?: (slug: string) => void;\n  /** Build a full href for a screen slug (for <a> tags) */\n  buildHref?: (slug: string) => string;\n  /**\n   * Inverse of `buildHref`: resolve a URL-mode link that points at a screen in\n   * this portal back to its slug, so it can be followed in-app rather than as\n   * a document load. Returns undefined for links that leave the portal.\n   */\n  resolveInternalSlug?: (href: string) => string | undefined;\n  /**\n   * Whether navigating to `slug` would land on a real screen in this portal\n   * rather than \"Page Not Found\" — opt-in screens (contacts, messages) only\n   * render when their nav item is present. Widgets should not offer a deep-link\n   * this returns false for. Undefined (e.g. in the builder preview) means\n   * reachability is unknown, so treat every link as navigable.\n   */\n  canNavigateTo?: (slug: string) => boolean;\n}\n\nconst WidgetInteractionContext = createContext<WidgetInteractionContextValue>(\n  {},\n);\n\nexport interface WidgetInteractionProviderProps {\n  onItemClick?: (item: WidgetInteractionItem) => void;\n  onNavigate?: (slug: string) => void;\n  buildHref?: (slug: string) => string;\n  resolveInternalSlug?: (href: string) => string | undefined;\n  canNavigateTo?: (slug: string) => boolean;\n  children: ReactNode;\n}\n\nexport function WidgetInteractionProvider({\n  onItemClick,\n  onNavigate,\n  buildHref,\n  resolveInternalSlug,\n  canNavigateTo,\n  children,\n}: WidgetInteractionProviderProps): React.JSX.Element {\n  const value = useMemo(() => {\n    const ctx: WidgetInteractionContextValue = {};\n    if (onItemClick) ctx.onItemClick = onItemClick;\n    if (onNavigate) ctx.onNavigate = onNavigate;\n    if (buildHref) ctx.buildHref = buildHref;\n    if (resolveInternalSlug) ctx.resolveInternalSlug = resolveInternalSlug;\n    if (canNavigateTo) ctx.canNavigateTo = canNavigateTo;\n    return ctx;\n  }, [onItemClick, onNavigate, buildHref, resolveInternalSlug, canNavigateTo]);\n  return (\n    <WidgetInteractionContext.Provider value={value}>\n      {children}\n    </WidgetInteractionContext.Provider>\n  );\n}\n\nexport function useWidgetInteraction(): WidgetInteractionContextValue {\n  return useContext(WidgetInteractionContext);\n}\n"],"mappings":";;;;;AAkCA,MAAM,4BAAA,GAAA,MAAA,eACJ,EAAE,CACH;AAWD,SAAgB,0BAA0B,EACxC,aACA,YACA,WACA,qBACA,eACA,YACoD;CACpD,MAAM,SAAA,GAAA,MAAA,eAAsB;EAC1B,MAAM,MAAqC,EAAE;AAC7C,MAAI,YAAa,KAAI,cAAc;AACnC,MAAI,WAAY,KAAI,aAAa;AACjC,MAAI,UAAW,KAAI,YAAY;AAC/B,MAAI,oBAAqB,KAAI,sBAAsB;AACnD,MAAI,cAAe,KAAI,gBAAgB;AACvC,SAAO;IACN;EAAC;EAAa;EAAY;EAAW;EAAqB;EAAc,CAAC;AAC5E,QACE,iBAAA,GAAA,kBAAA,KAAC,yBAAyB,UAA1B;EAA0C;EACvC;EACiC,CAAA;;AAIxC,SAAgB,uBAAsD;AACpE,SAAA,GAAA,MAAA,YAAkB,yBAAyB"}