"use client"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; export type SourceMode = "workspace" | "remote" | "scratch"; function resolveMode(useRemote: boolean, noRepository: boolean): SourceMode { if (noRepository) return "scratch"; if (useRemote) return "remote"; return "workspace"; } type SourceModeSwitchProps = { useRemote: boolean; noRepository: boolean; onToggleRemote?: () => void; onToggleNoRepository?: () => void; }; type ControlledSourceModeOption = { value: T; label: string; testId: string; legacyTestId?: string; }; type ControlledSourceModeSwitchProps = { mode: T; options: readonly ControlledSourceModeOption[]; onModeChange: (mode: T) => void; touchSized?: boolean; }; export function ControlledSourceModeSwitch({ mode, options, onModeChange, touchSized = false, }: ControlledSourceModeSwitchProps) { const { t } = useTranslation(); return (
{options.map((option) => { const isActive = mode === option.value; return ( ); })}
); } /** * Three-mode segmented control rendered at the right edge of the chip row: * - Repo : pick a workspace repository (default) * - Remote : paste a GitHub URL (Task 4 renamed "url" → "remote") * - None : run in a scratch workspace or a folder you pick * * Switching modes calls the underlying single-mode togglers in the right * order so we never end up in two modes at once. Hidden when no togglers * are provided (e.g. locked-fields wrapper). */ export function SourceModeSwitch({ useRemote, noRepository, onToggleRemote, onToggleNoRepository, }: SourceModeSwitchProps) { const { t } = useTranslation(); if (!onToggleRemote && !onToggleNoRepository) return null; const mode = resolveMode(useRemote, noRepository); const setMode = (next: SourceMode) => switchMode({ from: mode, to: next, onToggleRemote, onToggleNoRepository, }); return (
); } function switchMode({ from, to, onToggleRemote, onToggleNoRepository, }: { from: SourceMode; to: SourceMode; onToggleRemote?: () => void; onToggleNoRepository?: () => void; }) { if (from === to) return; if (to === "remote") { if (from === "scratch") onToggleNoRepository?.(); onToggleRemote?.(); return; } if (to === "scratch") { if (from === "remote") onToggleRemote?.(); onToggleNoRepository?.(); return; } // workspace if (from === "remote") onToggleRemote?.(); else if (from === "scratch") onToggleNoRepository?.(); }