import type { EnvironmentId } from "@t3tools/contracts"; import { ScaleIcon } from "lucide-react"; import { memo, useMemo } from "react"; import type { EnvironmentOption } from "./BranchToolbar.logic"; import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon"; import { composerFloatingLayerProps } from "./chat/composerEventScope"; import { Select, SelectGroup, SelectGroupLabel, SelectItem, SelectPopup, SelectTrigger, SelectValue, } from "./ui/select"; interface BranchToolbarEnvironmentSelectorProps { autoEnvironmentLabel?: string | undefined; onAutoEnvironment?: (() => void) | undefined; envLocked: boolean; environmentId: EnvironmentId; availableEnvironments: readonly EnvironmentOption[]; // Absent when there is only one environment to show: the indicator still // renders (as a static label) so remote projects are always identifiable. onEnvironmentChange?: (environmentId: EnvironmentId) => void; } export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvironmentSelector({ autoEnvironmentLabel, onAutoEnvironment, envLocked, environmentId, availableEnvironments, onEnvironmentChange, }: BranchToolbarEnvironmentSelectorProps) { const activeEnvironment = useMemo(() => { return availableEnvironments.find((env) => env.environmentId === environmentId) ?? null; }, [availableEnvironments, environmentId]); const environmentItems = useMemo( () => [ ...(onAutoEnvironment ? [{ value: "auto", label: autoEnvironmentLabel ?? "Auto balance" }] : []), ...availableEnvironments.map((env) => ({ value: env.environmentId, label: env.label, })), ], [availableEnvironments, autoEnvironmentLabel, onAutoEnvironment], ); // The static label carries the xs control's height (h-7 sm:h-6) as well as // its padding: the composer context strip has no min-height of its own, and // the glass seam joining it to the composer assumes a fixed strip height, so // a shorter label would drag the seam out of line whenever this label is the // only thing in the strip. if (envLocked || onEnvironmentChange === undefined) { return ( {activeEnvironment?.label ?? "Run on"} ); } return ( ); });