{"version":3,"sources":["../../src/loader/react/FeedbackProvider.tsx"],"sourcesContent":["/** @jsxImportSource react */\n/**\n * React provider for the loader path (@mhosaic/feedback/loader/react).\n *\n * Mirrors the direct-import path's <FeedbackProvider> exactly — same\n * props, same `useFeedback()` hook, same rendering semantics — but uses\n * the loader's createFeedback under the hood, so the host's bundle\n * doesn't include the widget code (it gets fetched at runtime from the\n * Mhosaic-controlled bundle URL).\n *\n * Subtle difference vs the direct-import provider:\n *   The deferred handle is available SYNCHRONOUSLY (so we can render\n *   children immediately instead of waiting for the bundle to load).\n *   useFeedback() returns the deferred handle from first paint; method\n *   calls queue until the bundle attaches. The direct-import provider\n *   used to delay rendering children until the api instance was ready;\n *   the loader doesn't need that delay since the deferred handle\n *   already absorbs the lag.\n */\n\nimport { createContext, useContext, useEffect, useState } from 'react'\nimport type { ReactNode } from 'react'\n\nimport { createFeedback } from '../index'\nimport type { ErrorTrackingOptions } from '../../modules/error-tracking'\nimport type { FeedbackApi, FeedbackConfig } from '../../types'\n\nconst FeedbackContext = createContext<FeedbackApi | null>(null)\n\ninterface FeedbackProviderProps extends FeedbackConfig {\n  children?: ReactNode\n  /**\n   * Auto-capture uncaught errors + unhandled rejections as synthetic\n   * reports. On the loader path the runtime bundle arms this itself, so we\n   * DON'T wrap host-side (that would double-register, once on the deferred\n   * handle and once on the real instance). Instead we forward the host's\n   * preference to the bundle. Leave it unset to let the project's manifest\n   * flag decide (which itself defaults on); pass `false` to opt out, or an\n   * options object to tune the cooldown / sampling / rate caps.\n   */\n  errorTracking?: boolean | ErrorTrackingOptions\n}\n\nexport function FeedbackProvider({\n  children,\n  errorTracking,\n  ...config\n}: FeedbackProviderProps) {\n  const [api, setApi] = useState<FeedbackApi | null>(null)\n\n  useEffect(() => {\n    // Forward errorTracking into the loader config — the bundle is the\n    // single arm point. `undefined` (the default) defers to the manifest.\n    const instance = createFeedback({ ...config, errorTracking })\n    setApi(instance)\n    return () => {\n      instance.shutdown()\n      setApi(null)\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [config.apiKey])\n\n  // Unlike the direct-import provider, render children immediately —\n  // the deferred handle is sync-available, queued calls replay once\n  // the bundle attaches.\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":";;;;;AAoBA,SAAS,eAAe,YAAY,WAAW,gBAAgB;AA6CtD;AAtCT,IAAM,kBAAkB,cAAkC,IAAI;AAgBvD,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA0B;AACxB,QAAM,CAAC,KAAK,MAAM,IAAI,SAA6B,IAAI;AAEvD,YAAU,MAAM;AAGd,UAAM,WAAW,eAAe,EAAE,GAAG,QAAQ,cAAc,CAAC;AAC5D,WAAO,QAAQ;AACf,WAAO,MAAM;AACX,eAAS,SAAS;AAClB,aAAO,IAAI;AAAA,IACb;AAAA,EAEF,GAAG,CAAC,OAAO,MAAM,CAAC;AAKlB,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":[]}