{"version":3,"file":"RouterView.cjs","names":["useRoute","useRouteDepth","ROUTE_DEPTH_REACT_CONTEXT","useRef","GlobalContext","ROUTE_DEPTH_CONTEXT_KEY"],"sources":["../../../src/router/RouterView/RouterView.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport { ROUTE_DEPTH_CONTEXT_KEY, routeDive, type SelectedRoute } from '@pastweb/tools';\nimport { useBeforeMount } from '../../useBeforeMount';\nimport { useRef } from '../../useRef';\nimport { GlobalContext } from '../../GlobalContext';\nimport { ROUTE_DEPTH_REACT_CONTEXT } from '../constants';\nimport { useRoute } from '../useRoute';\nimport { useRouteDepth } from '../useRouteDepth';\nimport type { ViewComponent } from '../types';\nimport type { RouterViewProps } from './types';\n\n/**\n * Renders the view component selected for the current route depth.\n *\n * Nested `RouterView` instances increment the route depth through\n * `GlobalContext`, allowing child routes to render their own views.\n *\n * @param props - View name, optional route transform, and props passed to the rendered view.\n * @returns The selected view or `null` when no matching view exists.\n *\n * @example\n * ```tsx\n * <RouterView name=\"main\" />\n * ```\n */\nexport function RouterView({ name = 'default', beforeShow, ...rest }: RouterViewProps) {\n  const route = useRoute();\n  const routeDepth = useRouteDepth();\n  const providerDepth = useContext(ROUTE_DEPTH_REACT_CONTEXT);\n  const depth = useRef<number>(-1);\n\n  useBeforeMount(() => {\n    depth.value = routeDepth + 1;\n  });\n\n  if (depth.value > 10) return null;\n  const selected = routeDive(route as SelectedRoute, depth.value) as SelectedRoute;\n  const { views } = beforeShow ? beforeShow(selected) : selected;\n  const View = (views as Record<string, ViewComponent>)[name] as ViewComponent;\n\n  const content = (\n    <ROUTE_DEPTH_REACT_CONTEXT.Provider value={depth.value}>\n      {View ? <View {...rest} /> : null}\n    </ROUTE_DEPTH_REACT_CONTEXT.Provider>\n  );\n\n  if (providerDepth !== undefined) return content;\n\n  return (\n    <GlobalContext update={{ [ROUTE_DEPTH_CONTEXT_KEY]: depth.value }}>\n      {content}\n    </GlobalContext>\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,WAAW,EAAE,OAAO,WAAW,YAAY,GAAG,QAAyB;CACrF,MAAM,QAAQA,iCAAAA,SAAS;CACvB,MAAM,aAAaC,2CAAAA,cAAc;CACjC,MAAM,iBAAA,GAAA,MAAA,WAAA,CAA2BC,yBAAAA,yBAAyB;CAC1D,MAAM,QAAQC,sBAAAA,OAAe,EAAE;CAE/B,sCAAA,qBAAqB;EACnB,MAAM,QAAQ,aAAa;CAC7B,CAAC;CAED,IAAI,MAAM,QAAQ,IAAI,OAAO;CAC7B,MAAM,YAAA,GAAA,eAAA,UAAA,CAAqB,OAAwB,MAAM,KAAK;CAC9D,MAAM,EAAE,UAAU,aAAa,WAAW,QAAQ,IAAI;CACtD,MAAM,OAAQ,MAAwC;CAEtD,MAAM,UACJ,iBAAA,GAAA,kBAAA,IAAA,CAACD,yBAAAA,0BAA0B,UAA3B;EAAoC,OAAO,MAAM;YAC9C,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,EAAM,GAAI,KAAO,CAAA,IAAI;CACK,CAAA;CAGtC,IAAI,kBAAkB,KAAA,GAAW,OAAO;CAExC,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACE,sBAAAA,eAAD;EAAe,QAAQ,GAAGC,eAAAA,0BAA0B,MAAM,MAAM;YAC7D;CACY,CAAA;AAEnB"}