import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
import { ChevronDownIcon, FolderIcon } from "lucide-react";
import { type ReactNode, useState } from "react";
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
import { ProjectFavicon } from "../ProjectFavicon";
import { WorkspacePageContainer } from "../WorkspacePageContainer";
import { useEnvironments } from "../../state/environments";
import { Toggle, ToggleGroup } from "../ui/toggle-group";
import {
Combobox,
ComboboxEmpty,
ComboboxSearchInput,
ComboboxItem,
ComboboxList,
ComboboxPopup,
ComboboxTrigger,
} from "../ui/combobox";
import { selectTriggerVariants } from "../ui/select";
import { cn } from "../../lib/utils";
import { ProjectSettingsPanel, useSettingsProjectGroups } from "./ProjectSettingsPanel";
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
function ScopePicker({
label,
value,
options,
onChange,
}: {
label: "project" | "machine";
value: string | null;
options: ReadonlyArray<{ value: string; label: string; icon?: ReactNode }>;
onChange: (value: string | null) => void;
}) {
const [query, setQuery] = useState("");
const selected = options.find((option) => option.value === value);
const allIcon =
label === "project" ? : null;
const items = [{ value: "all", label: `All ${label}s`, icon: allIcon }, ...options];
return (
item.value === (value ?? "all")) ?? null}
inputValue={query}
onInputValueChange={setQuery}
onOpenChange={() => setQuery("")}
onValueChange={(next) => {
if (next) onChange(next.value === "all" ? null : next.value);
}}
>
{value === null ? allIcon : selected?.icon}
{value === null ? `All ${label}s` : (selected?.label ?? `Unavailable ${label}`)}
No matching {label}s.
{(item: (typeof items)[number]) => (
{item.icon}
{item.label}
)}
);
}
export function ProjectsSettings({
projectKey,
machineId,
onScopeChange,
}: {
projectKey: string | null;
machineId: string | null;
onScopeChange: (project: string | null, machine: string | null) => void;
}) {
const groups = useSettingsProjectGroups();
const { environments } = useEnvironments();
const machine = environments.find((environment) => environment.environmentId === machineId);
const machineOptions = environments.map((environment) => ({
value: environment.environmentId,
label: environment.label,
icon: (
),
}));
return (
{environments.length > 3 ? (
onScopeChange(projectKey, value)}
/>
) : (
{
const value = next[0];
if (value) onScopeChange(projectKey, value === "all" ? null : value);
}}
>
All machines
{machineOptions.map((option) => (
{option.icon}
{option.label}
))}
)}
({
value: group.projectKey,
label: group.displayName,
icon: ,
}))}
onChange={(value) => onScopeChange(value, machineId)}
/>
{machineId !== null && !machine ? (
This machine is no longer available.
) : projectKey === null ? (
) : (
)}
);
}