import type { WorkspaceIdentity } from '../../components/Workspace';

/**
 * The dashboard-state key a terminal panel stores its `panelId → sessionId` map under.
 *
 * Three wrappers used to derive this from the raw workspace key by three different rules, and two of them
 * left the prefix on: `ws-host-terminals-ws-layout-my-dash` parses back out as a dashboard called
 * `ws-layout-my-dash`, which the server then created, and which showed up in the Dashboards list as a real
 * dashboard. One rule, in one place, is the fix for that class — and the framework now hands over the
 * parsed id rather than a string to re-parse, so there is nothing left here to get wrong.
 *
 * Screens fall back to `-default`, which is the behaviour `TerminalWrapper` already had: a screen has no
 * dashboard row to hang the map on, and panel ids are unique across the app.
 */
export function terminalStateKey(prefix: string, workspace: WorkspaceIdentity | null): string {
  const id = workspace?.kind === 'dashboard' ? workspace.id : 'default';
  return `ws-${prefix}-${id}`;
}
