/**
 * desktop/src/shell.ts — the default login shell to spawn per host platform.
 *
 * The backend's loadConfig defaults SHELL_PATH to `$SHELL ?? /bin/zsh`, which is
 * meaningless on Windows (no $SHELL, no /bin/zsh). The desktop shell overrides
 * SHELL_PATH with this platform-aware default (see server-config.ts) so a
 * Windows install spawns PowerShell (ConPTY-friendly) instead of a bogus path.
 */

/** Windows default: PowerShell works with node-pty's ConPTY backend out of the box. */
const WINDOWS_DEFAULT_SHELL = 'powershell.exe'
/** macOS fallback when $SHELL is unset (the default login shell since Catalina). */
const MACOS_FALLBACK_SHELL = '/bin/zsh'
/** Linux / other POSIX fallback when $SHELL is unset. */
const POSIX_FALLBACK_SHELL = '/bin/bash'

/**
 * Resolve the shell to spawn for `platform`. win32 → PowerShell; darwin →
 * $SHELL or /bin/zsh; anything else (linux, etc.) → $SHELL or /bin/bash.
 */
export function defaultShellForPlatform(
  platform: NodeJS.Platform,
  env: NodeJS.ProcessEnv,
): string {
  if (platform === 'win32') return WINDOWS_DEFAULT_SHELL
  if (platform === 'darwin') return env.SHELL ?? MACOS_FALLBACK_SHELL
  return env.SHELL ?? POSIX_FALLBACK_SHELL
}
