{"version":3,"sources":["../src/react/HwChat.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { HwChatElement } from '../element/HwChat.js';\nimport '../element/HwChat.js'; // side-effect: registers <hw-chat>\nimport type { AuthProvider } from '../core/types.js';\n\nexport interface HwChatProps {\n  chatId: string;\n  apiBase?: string;\n  authEndpoint?: string;\n  authProvider?: AuthProvider;\n  theme?: 'dark' | 'light' | 'auto';\n  primaryColor?: string;\n  /**\n   * When set, a mic button appears in the header and clicking it\n   * starts a live voice call against this provider-side agent id.\n   */\n  voiceAgentId?: string;\n  /** Voice agent platform — defaults to 'elevenlabs'. */\n  voiceProvider?: 'elevenlabs' | 'vapi' | 'retell';\n  /** Override the CDN URL the widget loads the voice SDK from. */\n  voiceSdkUrl?: string;\n  /** Pass through a style object — the Web Component is a block element. */\n  style?: React.CSSProperties;\n  className?: string;\n}\n\nexport function HwChat({\n  chatId,\n  apiBase,\n  authEndpoint,\n  authProvider,\n  theme,\n  primaryColor,\n  voiceAgentId,\n  voiceProvider,\n  voiceSdkUrl,\n  style,\n  className,\n}: HwChatProps): JSX.Element {\n  const ref = useRef<HwChatElement | null>(null);\n\n  // authProvider is a function — can't ride on an HTML attribute. Assign as\n  // a property after the element mounts, and whenever the provider changes.\n  useEffect(() => {\n    if (!ref.current) return;\n    ref.current.authProvider = authProvider ?? null;\n  }, [authProvider]);\n\n  // React 18 doesn't know about custom element attributes by default, so we\n  // bypass its type-checker with a type-cast on the intrinsic element.\n  const Tag = 'hw-chat' as unknown as 'div';\n\n  return (\n    <Tag\n      ref={ref as any}\n      // camelCase → kebab-case attributes the Web Component observes\n      {...{\n        'chat-id': chatId,\n        ...(apiBase ? { 'api-base': apiBase } : {}),\n        ...(authEndpoint ? { 'auth-endpoint': authEndpoint } : {}),\n        ...(theme ? { theme } : {}),\n        ...(primaryColor ? { 'primary-color': primaryColor } : {}),\n        ...(voiceAgentId ? { 'voice-agent-id': voiceAgentId } : {}),\n        ...(voiceProvider ? { 'voice-provider': voiceProvider } : {}),\n        ...(voiceSdkUrl ? { 'voice-sdk-url': voiceSdkUrl } : {}),\n      }}\n      style={style}\n      className={className}\n    />\n  );\n}\n"],"mappings":"6BAAA,OAAS,aAAAA,EAAW,UAAAC,MAAc,QAqD9B,cAAAC,MAAA,oBA3BG,SAASC,EAAO,CACrB,OAAAC,EACA,QAAAC,EACA,aAAAC,EACA,aAAAC,EACA,MAAAC,EACA,aAAAC,EACA,aAAAC,EACA,cAAAC,EACA,YAAAC,EACA,MAAAC,EACA,UAAAC,CACF,EAA6B,CAC3B,IAAMC,EAAMC,EAA6B,IAAI,EAI7C,OAAAC,EAAU,IAAM,CACTF,EAAI,UACTA,EAAI,QAAQ,aAAeR,GAAgB,KAC7C,EAAG,CAACA,CAAY,CAAC,EAOfL,EAHU,UAGT,CACC,IAAKa,EAGH,UAAWX,EACX,GAAIC,EAAU,CAAE,WAAYA,CAAQ,EAAI,CAAC,EACzC,GAAIC,EAAe,CAAE,gBAAiBA,CAAa,EAAI,CAAC,EACxD,GAAIE,EAAQ,CAAE,MAAAA,CAAM,EAAI,CAAC,EACzB,GAAIC,EAAe,CAAE,gBAAiBA,CAAa,EAAI,CAAC,EACxD,GAAIC,EAAe,CAAE,iBAAkBA,CAAa,EAAI,CAAC,EACzD,GAAIC,EAAgB,CAAE,iBAAkBA,CAAc,EAAI,CAAC,EAC3D,GAAIC,EAAc,CAAE,gBAAiBA,CAAY,EAAI,CAAC,EAExD,MAAOC,EACP,UAAWC,EACb,CAEJ","names":["useEffect","useRef","jsx","HwChat","chatId","apiBase","authEndpoint","authProvider","theme","primaryColor","voiceAgentId","voiceProvider","voiceSdkUrl","style","className","ref","useRef","useEffect"]}