import type { EnvironmentId } from "@t3tools/contracts";
import { CloudIcon, MonitorIcon } from "lucide-react";
import { memo, useMemo } from "react";
import type { EnvironmentOption } from "./BranchToolbar.logic";
import {
Select,
SelectGroup,
SelectGroupLabel,
SelectItem,
SelectPopup,
SelectTrigger,
SelectValue,
} from "./ui/select";
interface BranchToolbarEnvironmentSelectorProps {
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({
envLocked,
environmentId,
availableEnvironments,
onEnvironmentChange,
}: BranchToolbarEnvironmentSelectorProps) {
const activeEnvironment = useMemo(() => {
return availableEnvironments.find((env) => env.environmentId === environmentId) ?? null;
}, [availableEnvironments, environmentId]);
const environmentItems = useMemo(
() =>
availableEnvironments.map((env) => ({
value: env.environmentId,
label: env.label,
})),
[availableEnvironments],
);
// 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?.isPrimary ? (
) : (
)}
{activeEnvironment?.label ?? "Run on"}
);
}
return (
);
});