{"version":3,"file":"WorkspacePage.mjs","names":[],"sources":["../../../src/web/components/WorkspacePage.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/web';\nimport { AlertIcon, FolderIcon } from '@agimon-ai/po-web-components';\nimport { useStore } from '@tanstack/react-store';\nimport { createElement } from 'react';\n\nimport { retryWebPluginCompositions, webPluginCompositionStore, webPluginMountState } from '../lib/pluginCompositions';\nimport { dashboardTileFills } from '../lib/pluginRegistry';\nimport { usePluginSlotProps } from '../stores/usePluginSlotProps';\nimport { useWebPluginRegistry } from '../stores/useWebPluginRegistry';\nimport { workspacesStore } from '../stores/workspacesStore';\nimport type { DashboardTileView } from './DashboardTileGrid';\nimport { HomeView } from './HomePage';\n\nexport interface WorkspaceViewProps {\n  title: string;\n  state?: 'ready' | 'loading' | 'missing' | 'unavailable' | 'error';\n  error?: string;\n  tiles?: readonly DashboardTileView[];\n  onShowSessions?: () => void;\n  /** Reloads the workspace's apps after they failed to load. */\n  onRetry?: () => void;\n  navigationToggle?: 'mobile' | 'always';\n}\n\n/** The same tile surface as Home, with explicit workspace delivery states. */\nexport function WorkspaceView({\n  title,\n  state = 'ready',\n  error,\n  tiles = [],\n  onRetry,\n  ...navigation\n}: WorkspaceViewProps) {\n  const t = useT();\n  const messages = {\n    ready: [\n      t('webDashboard.workspace.emptyTitle', 'Nothing in this workspace yet'),\n      t('webDashboard.workspace.emptyDescription', 'Apps for this workspace will show up here.'),\n    ],\n    loading: [\n      t('webDashboard.workspace.loadingTitle', 'Loading workspace'),\n      t('webDashboard.workspace.loadingDescription', 'Your workspace is getting ready.'),\n    ],\n    missing: [\n      t('webDashboard.workspace.missingTitle', 'Workspace not found'),\n      t(\n        'webDashboard.workspace.missingDescription',\n        'This workspace may have been removed. Choose another from the session list.',\n      ),\n    ],\n    unavailable: [\n      t('webDashboard.workspace.unavailableTitle', 'Workspace unavailable'),\n      t(\n        'webDashboard.workspace.unavailableDescription',\n        'Po cannot open this workspace right now. Reconnect to its host and try again.',\n      ),\n    ],\n    error: [\n      t('webDashboard.workspace.errorTitle', 'Workspace apps could not load'),\n      error ?? t('webDashboard.workspace.errorDescription', 'Reconnect to this host and try again.'),\n    ],\n  } as const;\n  return (\n    <HomeView\n      {...navigation}\n      title={title}\n      tiles={state === 'ready' ? tiles : []}\n      emptyTitle={messages[state][0]}\n      emptyDescription={messages[state][1]}\n      empty={\n        state === 'missing'\n          ? {\n              size: 'page',\n              icon: <FolderIcon />,\n              ...(navigation.onShowSessions === undefined\n                ? {}\n                : {\n                    action: {\n                      label: t('webDashboard.common.showSessions', 'Show sessions'),\n                      onAction: navigation.onShowSessions,\n                    },\n                  }),\n            }\n          : state === 'error'\n            ? {\n                tone: 'error',\n                icon: <AlertIcon />,\n                ...(onRetry === undefined\n                  ? {}\n                  : { action: { label: t('webDashboard.common.retry', 'Retry'), onAction: onRetry } }),\n              }\n            : undefined\n      }\n    />\n  );\n}\n\n/** Reads the explicit workspace mount, never the unrelated focused session. The host loads its composition. */\nexport function WorkspacePage({\n  workspaceId,\n  ...navigation\n}: { workspaceId: string } & Pick<WorkspaceViewProps, 'onShowSessions' | 'navigationToggle'>) {\n  const t = useT();\n  useWebPluginRegistry();\n  const workspace = useStore(workspacesStore, (state) => state.byId[workspaceId]);\n  const hydrated = useStore(workspacesStore, (state) => state.hydrated);\n  const mount = { scope: 'workspace', workspaceId } as const;\n  const composition = useStore(webPluginCompositionStore, (state) => state);\n  const readiness = webPluginMountState(mount, composition);\n  const props = usePluginSlotProps(null, undefined, undefined, workspaceId);\n  const tiles: DashboardTileView[] = dashboardTileFills(mount).flatMap((fill) => {\n    if (fill.component === undefined) return [];\n    const data = fill.data;\n    const destination = data.open;\n    const open = destination?.kind === 'page' ? props.openPage : props.openSettings;\n    return [\n      {\n        id: JSON.stringify([fill.pluginId, fill.id]),\n        title: data.title,\n        icon: data.icon,\n        size: data.size ?? 'small',\n        column: data.column,\n        ...(destination === undefined || open === undefined ? {} : { onOpen: () => open(destination.id) }),\n        body: createElement(fill.component, props),\n      },\n    ];\n  });\n  const state = !hydrated\n    ? 'loading'\n    : workspace === undefined\n      ? 'missing'\n      : workspace.available === false\n        ? 'unavailable'\n        : readiness.phase === 'error'\n          ? 'error'\n          : readiness.phase !== 'ready'\n            ? 'loading'\n            : 'ready';\n  return (\n    <WorkspaceView\n      {...navigation}\n      title={workspace?.name ?? t('webDashboard.workspace.fallbackTitle', 'Workspace')}\n      state={state}\n      error={readiness.error}\n      tiles={tiles}\n      // A failed retry is recorded in the mount state this page already reads.\n      onRetry={() => void retryWebPluginCompositions().catch(() => undefined)}\n    />\n  );\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,cAAc,EAC5B,OACA,QAAQ,SACR,OACA,QAAQ,CAAC,GACT,SACA,GAAG,cACkB;CACrB,MAAM,IAAI,KAAK;CACf,MAAM,WAAW;EACf,OAAO,CACL,EAAE,qCAAqC,+BAA+B,GACtE,EAAE,2CAA2C,4CAA4C,CAC3F;EACA,SAAS,CACP,EAAE,uCAAuC,mBAAmB,GAC5D,EAAE,6CAA6C,kCAAkC,CACnF;EACA,SAAS,CACP,EAAE,uCAAuC,qBAAqB,GAC9D,EACE,6CACA,6EACF,CACF;EACA,aAAa,CACX,EAAE,2CAA2C,uBAAuB,GACpE,EACE,iDACA,+EACF,CACF;EACA,OAAO,CACL,EAAE,qCAAqC,+BAA+B,GACtE,SAAS,EAAE,2CAA2C,uCAAuC,CAC/F;CACF;CACA,OACE,oBAAC,UAAD;EACE,GAAI;EACG;EACP,OAAO,UAAU,UAAU,QAAQ,CAAC;EACpC,YAAY,SAAS,MAAM,CAAC;EAC5B,kBAAkB,SAAS,MAAM,CAAC;EAClC,OACE,UAAU,YACN;GACE,MAAM;GACN,MAAM,oBAAC,YAAD,CAAa,CAAA;GACnB,GAAI,WAAW,mBAAmB,KAAA,IAC9B,CAAC,IACD,EACE,QAAQ;IACN,OAAO,EAAE,oCAAoC,eAAe;IAC5D,UAAU,WAAW;GACvB,EACF;EACN,IACA,UAA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