{"version":3,"file":"dashboardRoute.mjs","names":[],"sources":["../../../src/web/lib/dashboardRoute.ts"],"sourcesContent":["import { rootRouteId, useRouterState } from '@tanstack/react-router';\n\nexport const PLUGINS_ROUTE = '/plugins';\nexport const PLUGINS_PAGE_ID = 'plugins';\n/** Po Cloud's Team pages: `/organization`, `/organization/members` and `/organization/invitations`. */\nexport const TEAM_ROUTE = '/organization';\nexport const TEAM_PAGE_ID = 'organization';\n/** Canonical URL state, available anywhere in a dashboard's application tree. */\nexport interface DashboardRoute {\n  /** `home` is `/`: the Home screen of plugin cards, shown with no session focused. */\n  kind: 'home' | 'session' | 'settings' | 'page' | 'workspace';\n  sessionId?: string;\n  tabId?: string;\n  /** The Settings section, or the Team page's (`members`, `invitations`; none for its overview). */\n  section?: string;\n  /** The plugin page at `/page/<pageId>`; the host's own Plugins and Team pages are `plugins` and `organization`. */\n  pageId?: string;\n  /** The one plugin `/plugins/<pluginId>` opens. */\n  pluginId?: string;\n  workspaceId?: string;\n}\n\ninterface DashboardRouteMatch {\n  routeId: string;\n  fullPath: string;\n  params?: unknown;\n  search?: unknown;\n}\n\n/**\n * Every field comes from the leaf match. During a transition `location.pathname` already\n * names the next route while the matches (and their params) still describe the current one,\n * so mixing them yields impossible states such as a session route without a session id.\n */\nexport function dashboardRouteFrom(state: {\n  location: { pathname: string };\n  matches: readonly DashboardRouteMatch[];\n}): DashboardRoute {\n  const match = state.matches.at(-1);\n  const params = (match?.params ?? {}) as Record<string, unknown>;\n  const search = (match?.search ?? {}) as Record<string, unknown>;\n  const path = match !== undefined && match.routeId !== rootRouteId ? match.fullPath : state.location.pathname;\n  // `/plugins` is drawn wherever a template draws a plugin page, so templates need no route of their own.\n  const plugins = path === PLUGINS_ROUTE || path.startsWith(`${PLUGINS_ROUTE}/`);\n  const team = path === TEAM_ROUTE || path.startsWith(`${TEAM_ROUTE}/`);\n  return {\n    kind:\n      path === '/'\n        ? 'home'\n        : path.startsWith('/settings')\n          ? 'settings'\n          : plugins || team || path.startsWith('/page/')\n            ? 'page'\n            : path.startsWith('/workspace/')\n              ? 'workspace'\n              : 'session',\n    sessionId: typeof params.sessionId === 'string' ? params.sessionId : undefined,\n    tabId: typeof params.tabId === 'string' ? params.tabId : undefined,\n    section: team\n      ? path.slice(TEAM_ROUTE.length + 1) || undefined\n      : typeof params.section === 'string'\n        ? params.section\n        : undefined,\n    pageId: plugins\n      ? PLUGINS_PAGE_ID\n      : team\n        ? TEAM_PAGE_ID\n        : typeof params.pageId === 'string'\n          ? params.pageId\n          : undefined,\n    pluginId: plugins && typeof params.pluginId === 'string' ? params.pluginId : undefined,\n    workspaceId:\n      typeof params.workspaceId === 'string'\n        ? params.workspaceId\n        : typeof search.workspace === 'string'\n          ? search.workspace\n          : undefined,\n  };\n}\n\nexport function useDashboardRoute(): DashboardRoute {\n  return useRouterState({ select: dashboardRouteFrom });\n}\n"],"mappings":";;AAEA,MAAa,gBAAgB;AAC7B,MAAa,kBAAkB;;AAE/B,MAAa,aAAa;AAC1B,MAAa,eAAe;;;;;;AA4B5B,SAAgB,mBAAmB,OAGhB;CACjB,MAAM,QAAQ,MAAM,QAAQ,GAAG,EAAE;CACjC,MAAM,SAAU,OAAO,UAAU,CAAC;CAClC,MAAM,SAAU,OAAO,UAAU,CAAC;CAClC,MAAM,OAAO,UAAU,KAAA,KAAa,MAAM,YAAY,cAAc,MAAM,WAAW,MAAM,SAAS;CAEpG,MAAM,UAAU,SAAA,cAA0B,KAAK,WAAW,WAAmB;CAC7E,MAAM,OAAO,SAAA,mBAAuB,KAAK,WAAW,gBAAgB;CACpE,OAAO;EACL,MACE,SAAS,MACL,SACA,KAAK,WAAW,WAAW,IACzB,aACA,WAAW,QAAQ,KAAK,WAAW,QAAQ,IACzC,SACA,KAAK,WAAW,aAAa,IAC3B,cACA;EACZ,WAAW,OAAO,OAAO,cAAc,WAAW,OAAO,YAAY,KAAA;EACrE,OAAO,OAAO,OAAO,UAAU,WAAW,OAAO,QAAQ,KAAA;EACzD,SAAS,OACL,KAAK,MAAM,EAAqB,KAAK,KAAA,IACrC,OAAO,OAAO,YAAY,WACxB,OAAO,UACP,KAAA;EACN,QAAQ,UACJ,kBACA,OACE,eACA,OAAO,OAAO,WAAW,WACvB,OAAO,SACP,KAAA;EACR,UAAU,WAAW,OAAO,OAAO,aAAa,WAAW,OAAO,WAAW,KAAA;EAC7E,aACE,OAAO,OAAO,gBAAgB,WAC1B,OAAO,cACP,OAAO,OAAO,cAAc,WAC1B,OAAO,YACP,KAAA;CACV;AACF;AAEA,SAAgB,oBAAoC;CAClD,OAAO,eAAe,EAAE,QAAQ,mBAAmB,CAAC;AACtD"}