{"version":3,"file":"PluginPage.mjs","names":["HOST_SLOTS"],"sources":["../../../src/web/components/PluginPage.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/web';\nimport { Button, EmptyState, LoadingState, PuzzleIcon, SidebarIcon } from '@agimon-ai/po-web-components';\nimport { useNavigate, useSearch } from '@tanstack/react-router';\nimport { useStore } from '@tanstack/react-store';\nimport { Children, createElement, type ReactNode } from 'react';\n\nimport { PLUGINS_ROUTE } from '../lib/dashboardRoute';\nimport { splitHostId } from '../lib/hostIdentity';\nimport { webPluginCompositionStore, webPluginMountState } from '../lib/pluginCompositions';\nimport { HOST_SLOTS, webPluginRegistryForHost } from '../lib/pluginRegistry';\nimport { pluginSlotFills } from '../lib/pluginSlotProps';\nimport { usePluginSlotProps } from '../stores/usePluginSlotProps';\n\n/**\n * The plugin page at `/page/<pageId>`: the `page` fill with that id, filling the main\n * area. The page draws its own title, so the host adds only the sidebar toggle a layout\n * with a drawer sidebar needs. `children` replaces the fill for a host-owned page such as\n * Plugins, which the layout hands in so the page keeps the same frame.\n */\nexport function PluginPage({\n  pageId,\n  sessionId,\n  workspaceId,\n  onShowSessions,\n  navigationToggle = 'mobile',\n  children,\n}: {\n  pageId: string;\n  sessionId: string | null;\n  workspaceId?: string;\n  onShowSessions?: () => void;\n  navigationToggle?: 'mobile' | 'always';\n  children?: ReactNode;\n}) {\n  const t = useT();\n  const navigate = useNavigate();\n  const pageItemId = useSearch({\n    strict: false,\n    select: (search) => (typeof search.item === 'string' ? search.item : undefined),\n  });\n  const owner = splitHostId(pageId);\n  const props = usePluginSlotProps(sessionId, undefined, undefined, workspaceId, owner?.hostId);\n  const fills =\n    owner === undefined\n      ? pluginSlotFills(HOST_SLOTS.page, sessionId, workspaceId)\n      : webPluginRegistryForHost(owner.hostId).hostSlotFills(HOST_SLOTS.page);\n  const workspaceOwner = workspaceId === undefined ? undefined : splitHostId(workspaceId);\n  const fill =\n    owner && workspaceId !== undefined && owner.hostId !== workspaceOwner?.hostId\n      ? undefined\n      : fills.find((entry) => entry.id === (owner?.localId ?? pageId));\n  // The plugin that draws this page may still be loading; only a settled composition can say it is missing.\n  const composition = useStore(webPluginCompositionStore, (state) => state);\n  const phase = webPluginMountState(\n    workspaceId === undefined ? { scope: 'host' } : { scope: 'workspace', workspaceId },\n    composition,\n  ).phase;\n  const loading = owner === undefined && (phase === 'idle' || phase === 'loading');\n  return (\n    <div data-testid={`plugin-page-${pageId}`} className=\"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden\">\n      {onShowSessions ? (\n        <div className={`shrink-0 px-3 pt-2 ${navigationToggle === 'mobile' ? 'md:hidden' : ''}`}>\n          <Button\n            variant=\"ghost\"\n            size=\"icon-md\"\n            data-testid=\"mobile-sessions-open\"\n            title={t('webDashboard.common.showSessions', 'Show sessions')}\n            aria-label={t('webDashboard.common.showSessions', 'Show sessions')}\n            onClick={onShowSessions}\n            className=\"rounded-lg bg-po-panel/60 text-po-text hover:bg-po-panel hover:text-po-hi\"\n          >\n            <SidebarIcon aria-hidden className=\"size-4\" />\n          </Button>\n        </div>\n      ) : null}\n      {/* Layouts hand in several conditional children, so an array of nulls must still fall back to the fill. */}\n      {Children.toArray(children).length > 0 ? (\n        children\n      ) : fill?.component === undefined && loading ? (\n        <LoadingState data-testid=\"plugin-page-loading\" label={t('webDashboard.pluginPage.loading', 'Loading page')} />\n      ) : fill?.component === undefined ? (\n        <EmptyState\n          icon={<PuzzleIcon />}\n          title={t('webDashboard.pluginPage.unavailableTitle', 'This page is not available')}\n          description={t(\n            'webDashboard.pluginPage.unavailableDescription',\n            'The plugin that draws it is not installed here.',\n          )}\n          action={{\n            label: t('webDashboard.pluginPage.goToPlugins', 'Go to Plugins'),\n            onAction: () => void navigate({ to: PLUGINS_ROUTE, search: { workspace: workspaceId } }),\n          }}\n        />\n      ) : (\n        createElement(fill.component, { ...props, pageItemId })\n      )}\n    </div>\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,WAAW,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