/** All built-in extension tab specs. Dynamic sprinkles are added at runtime. */
const ALL_EXTENSION_TAB_SPECS = [
  { id: 'chat', label: 'Chat' },
  { id: 'terminal', label: 'Terminal' },
  { id: 'files', label: 'Files' },
  { id: 'memory', label: 'Memory' },
] as const;

/** Built-in extension tab specs (all visible — Terminal/Memory used to be hidden). */
export const EXTENSION_TAB_SPECS = ALL_EXTENSION_TAB_SPECS;

/** Built-in tab id union. Dynamic sprinkles use arbitrary string ids. */
export type BuiltinExtensionTabId = (typeof ALL_EXTENSION_TAB_SPECS)[number]['id'];

/**
 * Extension tab id — widened to `string` so dynamic sprinkle ids (e.g. 'sprinkle-dash')
 * work without type errors. Built-in ids are still checked where needed.
 */
export type ExtensionTabId = string;

export const DEFAULT_EXTENSION_TAB_ID: ExtensionTabId = 'chat';

const BUILTIN_TAB_ID_SET = new Set<string>(ALL_EXTENSION_TAB_SPECS.map((tab) => tab.id));

/** Check if a value is a built-in extension tab id. */
export function isBuiltinExtensionTabId(value: string): value is BuiltinExtensionTabId {
  return BUILTIN_TAB_ID_SET.has(value);
}

/**
 * @deprecated Use isBuiltinExtensionTabId for strict checks.
 * This now returns true for any non-empty string (dynamic sprinkles are valid).
 */
export function isExtensionTabId(value: string): value is ExtensionTabId {
  return value.length > 0;
}

/**
 * Normalize a tab id. Returns the value if non-empty, otherwise the fallback.
 * Accepts both built-in and dynamic sprinkle ids.
 */
export function normalizeExtensionTabId(
  value: string | null | undefined,
  fallback: ExtensionTabId = DEFAULT_EXTENSION_TAB_ID
): ExtensionTabId {
  return value && value.length > 0 ? value : fallback;
}
