{"version":3,"file":"UdpAppProvider.mjs","names":["React","ReactNode","useEffect","useState","SnackbarProvider","SnackbarProviderProps","ThemeProvider","AuthProvider","initializeUnityI18n","InitializeI18nOptions","storeInitialPath","storeInitialTenant","BrowserRouter","QueryProvider","UdpDevToolsOptions","query","UdpAppProviderProps","children","snackbarProps","authProps","doNotWaitForTenant","i18nOptions","devTools","SNACKBAR_HOST_STYLE","createSnackbarHost","HTMLElement","document","undefined","prototype","showPopover","el","createElement","setAttribute","style","cssText","useSnackbarTopLayerHost","$","_c","host","t0","t1","body","appendChild","scheduled","promote","queueMicrotask","isConnected","matches","hidePopover","removeAttribute","observer","MutationObserver","records","some","_temp","observe","childList","subtree","disconnect","remove","UdpAppProvider","FC","t2","snackbarHost","t3","t4","t5","t6","record","addedNodes","length"],"sources":["../../src/providers/UdpAppProvider.tsx"],"sourcesContent":["import React, { ReactNode, useEffect, useState } from 'react';\nimport { SnackbarProvider, SnackbarProviderProps } from 'notistack';\nimport { ThemeProvider } from '../utilities/theme';\nimport { AuthProvider } from '../utilities/auth/AuthProvider';\nimport { initializeUnityI18n } from '../utilities/i18n/initializeI18n';\nimport type { InitializeI18nOptions } from '../utilities/i18n/initializeI18n';\nimport { storeInitialPath } from '../utilities/redirect';\nimport { storeInitialTenant } from '../utilities/storage';\nimport { BrowserRouter } from 'react-router-dom';\nimport { QueryProvider } from './QueryProvider';\n\nexport interface UdpDevToolsOptions {\n  /** Show the React Query DevTools panel. Defaults to false. */\n  query?: boolean;\n}\n\nexport interface UdpAppProviderProps {\n  children: ReactNode;\n  /**\n   * Props forwarded to the SnackbarProvider from notistack.\n   */\n  snackbarProps?: SnackbarProviderProps;\n  /**\n   * Props forwarded to the AuthProviderWrapper.\n   */\n  authProps?: {\n    doNotWaitForTenant?: boolean;\n  };\n  /**\n   * Optional configuration overrides for the shared i18n instance.\n   */\n  i18nOptions?: InitializeI18nOptions;\n  /**\n   * Enable developer tools for debugging. All options default to false.\n   */\n  devTools?: UdpDevToolsOptions;\n}\n\n/**\n * Strip the popover UA box entirely: notistack's own container is\n * position: fixed and does all the positioning, so the host is a zero-size\n * anchor that must not paint, size, or clip anything.\n */\nconst SNACKBAR_HOST_STYLE =\n  'position:fixed;inset:auto;width:0;height:0;margin:0;padding:0;border:0;background:none;overflow:visible';\n\nconst createSnackbarHost = (): HTMLElement | undefined => {\n  if (typeof document === 'undefined') return undefined;\n  if (typeof HTMLElement.prototype.showPopover !== 'function') return undefined;\n\n  const el = document.createElement('div');\n  el.setAttribute('popover', 'manual');\n  el.style.cssText = SNACKBAR_HOST_STYLE;\n  return el;\n};\n\n/**\n * Creates the DOM element notistack portals its snackbar container into, and\n * keeps it in the browser's **top layer**.\n *\n * Why this exists: `UdpDrawer` and `UdpDialog` open a native `<dialog>` with\n * `showModal()`, which promotes them to the top layer. Top-layer elements paint\n * above every element in ordinary DOM regardless of `z-index`, so notistack's\n * container — a plain `position: fixed` element at `zIndex.snackbar` — is hidden\n * behind an open drawer or dialog. No z-index can fix that; the container has to\n * be in the top layer too, which the Popover API provides.\n *\n * Paint order inside the top layer is promotion order, so the host is\n * re-promoted (`hidePopover()` then `showPopover()`, synchronously, so nothing\n * paints in between) whenever a snackbar is added. That keeps it above whichever\n * drawer or dialog opened most recently.\n *\n * Two consequences worth knowing:\n * - While a modal drawer or dialog is open, everything outside it is inert, so a\n *   snackbar `action` button is visible but not clickable. Auto-dismiss is\n *   unaffected. Anything the user must act on belongs in a `UdpMessageBar`\n *   inside the drawer, not a toast.\n * - If a drawer opens while a snackbar is already showing, the drawer is\n *   promoted last and covers it until the next snackbar arrives.\n *\n * Returns `undefined` when the browser has no Popover API, which leaves\n * notistack rendering inline exactly as it did before.\n */\nconst useSnackbarTopLayerHost = (): HTMLElement | undefined => {\n  const [host] = useState(createSnackbarHost);\n\n  useEffect(() => {\n    if (!host) return undefined;\n\n    document.body.appendChild(host);\n\n    let scheduled = false;\n    const promote = () => {\n      if (scheduled) return;\n      scheduled = true;\n      // Coalesce to one promotion per React commit.\n      queueMicrotask(() => {\n        scheduled = false;\n        if (!host.isConnected) return;\n        try {\n          if (host.matches(':popover-open')) host.hidePopover();\n          host.showPopover();\n        } catch {\n          // Popover refused: fall back to a plain element so snackbars still\n          // render, just without top-layer promotion.\n          host.removeAttribute('popover');\n        }\n      });\n    };\n\n    // Only additions matter — a snackbar leaving cannot change what sits above it.\n    const observer = new MutationObserver((records) => {\n      if (records.some((record) => record.addedNodes.length > 0)) promote();\n    });\n    observer.observe(host, { childList: true, subtree: true });\n\n    promote();\n\n    return () => {\n      observer.disconnect();\n      host.remove();\n    };\n  }, [host]);\n\n  return host;\n};\n\n/**\n * Bundles the core UDP providers (theme, snackbar, auth) and ensures the shared\n * i18n instance is initialised exactly once. Intended to be rendered beneath a\n * react-router <Router /> so the auth provider has access to history.\n */\nexport const UdpAppProvider: React.FC<UdpAppProviderProps> = ({\n  children,\n  snackbarProps,\n  authProps,\n  i18nOptions,\n  devTools,\n}) => {\n  useEffect(() => {\n    initializeUnityI18n(i18nOptions);\n  }, [i18nOptions]);\n  // Snackbars have to live in the browser top layer or the modal <dialog>\n  // behind UdpDrawer / UdpDialog paints over them. See useSnackbarTopLayerHost.\n  const snackbarHost = useSnackbarTopLayerHost();\n  storeInitialPath();\n  storeInitialTenant();\n  return (\n    <ThemeProvider>\n      <QueryProvider showDevTools={devTools?.query}>\n        <AuthProvider {...authProps}>\n          <BrowserRouter>\n            <SnackbarProvider maxSnack={3} domRoot={snackbarHost} {...snackbarProps}>\n              {children}\n            </SnackbarProvider>\n          </BrowserRouter>\n        </AuthProvider>\n      </QueryProvider>\n    </ThemeProvider>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA2CA,MAAMuB,sBACJ;AAEF,MAAMC,2BAAoD;AACxD,KAAI,OAAOE,aAAa,YAAa,QAAOC,KAAAA;AAC5C,KAAI,OAAOF,YAAYG,UAAUC,gBAAgB,WAAY,QAAOF,KAAAA;CAEpE,MAAMG,KAAKJ,SAASK,cAAc,MAAM;AAC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