{"version":3,"sources":["../src/react/FeedbackProvider.tsx"],"sourcesContent":["/** @jsxImportSource react */\nimport { createContext, useContext, useEffect, useRef, useState } from 'react'\nimport type { ReactNode } from 'react'\n\nimport { createFeedback, type InternalConfig } from '../core'\nimport { withErrorTracking, type ErrorTrackingOptions } from '../modules/error-tracking'\nimport type { FeedbackApi, QaMeterConfig } from '../types'\n\nconst FeedbackContext = createContext<FeedbackApi | null>(null)\n\ninterface FeedbackProviderProps extends InternalConfig {\n  children?: ReactNode\n  /**\n   * Opt-in QA Meter second FAB — set `qaMeter={{ source: '/qa-status.json' }}`.\n   * Inherited from FeedbackConfig and forwarded via `...config`; redeclared\n   * here so editors surface the docs on hover.\n   */\n  qaMeter?: QaMeterConfig\n  /**\n   * Auto-capture uncaught errors + unhandled rejections as synthetic\n   * reports (see `withErrorTracking`). On by default — the happy path is\n   * batteries-included. Pass `false` to opt out, or an options object to\n   * tune the cooldown / sampling / rate caps.\n   */\n  errorTracking?: boolean | ErrorTrackingOptions\n}\n\nexport function FeedbackProvider({\n  children,\n  errorTracking = true,\n  ...config\n}: FeedbackProviderProps) {\n  const apiRef = useRef<FeedbackApi | null>(null)\n  const [api, setApi] = useState<FeedbackApi | null>(null)\n\n  useEffect(() => {\n    const instance = createFeedback(config)\n    if (errorTracking !== false) {\n      withErrorTracking(instance, errorTracking === true ? undefined : errorTracking)\n    }\n    apiRef.current = instance\n    setApi(instance)\n    return () => {\n      instance.shutdown()\n      apiRef.current = null\n      setApi(null)\n    }\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [config.apiKey])\n\n  // Only render children once the api instance is ready so useFeedback()\n  // never sees a null context value.\n  if (!api) return null\n\n  return <FeedbackContext.Provider value={api}>{children}</FeedbackContext.Provider>\n}\n\nexport { FeedbackContext }\n\nexport function useFeedback(): FeedbackApi {\n  const api = useContext(FeedbackContext)\n  if (!api) throw new Error('useFeedback must be used inside <FeedbackProvider>')\n  return api\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,eAAe,YAAY,WAAW,QAAQ,gBAAgB;AAqD9D;AA9CT,IAAM,kBAAkB,cAAkC,IAAI;AAmBvD,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,gBAAgB;AAAA,EAChB,GAAG;AACL,GAA0B;AACxB,QAAM,SAAS,OAA2B,IAAI;AAC9C,QAAM,CAAC,KAAK,MAAM,IAAI,SAA6B,IAAI;AAEvD,YAAU,MAAM;AACd,UAAM,WAAW,eAAe,MAAM;AACtC,QAAI,kBAAkB,OAAO;AAC3B,wBAAkB,UAAU,kBAAkB,OAAO,SAAY,aAAa;AAAA,IAChF;AACA,WAAO,UAAU;AACjB,WAAO,QAAQ;AACf,WAAO,MAAM;AACX,eAAS,SAAS;AAClB,aAAO,UAAU;AACjB,aAAO,IAAI;AAAA,IACb;AAAA,EAEF,GAAG,CAAC,OAAO,MAAM,CAAC;AAIlB,MAAI,CAAC,IAAK,QAAO;AAEjB,SAAO,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,KAAM,UAAS;AACzD;AAIO,SAAS,cAA2B;AACzC,QAAM,MAAM,WAAW,eAAe;AACtC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,oDAAoD;AAC9E,SAAO;AACT;","names":[]}