import { Trans, useLingui } from "@lingui/react"; import { useQueryClient } from "@tanstack/react-query"; import { type FC, useId } from "react"; import { useConfig } from "@/app/hooks/useConfig"; import { Checkbox } from "@/components/ui/checkbox"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useFeatureFlags } from "@/hooks/useFeatureFlags"; import { useTheme } from "@/hooks/useTheme"; import { projectDetailQuery, projectListQuery } from "../lib/api/queries"; import type { SupportedLocale } from "../lib/i18n/schema"; interface SettingsControlsProps { openingProjectId: string; showLabels?: boolean; showDescriptions?: boolean; className?: string; } export const SettingsControls: FC = ({ openingProjectId, showLabels = true, showDescriptions = true, className = "", }: SettingsControlsProps) => { const checkboxId = useId(); const enterKeyBehaviorId = useId(); const permissionModeId = useId(); const localeId = useId(); const themeId = useId(); const { config, updateConfig } = useConfig(); const queryClient = useQueryClient(); const { theme } = useTheme(); const { i18n } = useLingui(); const { isFlagEnabled } = useFeatureFlags(); const isToolApprovalAvailable = isFlagEnabled("tool-approval"); const handleHideNoUserMessageChange = async () => { const newConfig = { ...config, hideNoUserMessageSession: !config?.hideNoUserMessageSession, }; updateConfig(newConfig, { onSuccess: async () => { await queryClient.refetchQueries({ queryKey: projectListQuery.queryKey, }); }, }); }; const handleUnifySameTitleChange = async () => { const newConfig = { ...config, unifySameTitleSession: !config?.unifySameTitleSession, }; updateConfig(newConfig, { onSuccess: async () => { await queryClient.refetchQueries({ queryKey: projectDetailQuery(openingProjectId).queryKey, }); }, }); }; const handleEnterKeyBehaviorChange = async (value: string) => { const newConfig = { ...config, enterKeyBehavior: value as | "shift-enter-send" | "enter-send" | "command-enter-send", }; updateConfig(newConfig); }; const handlePermissionModeChange = async (value: string) => { const newConfig = { ...config, permissionMode: value as | "acceptEdits" | "bypassPermissions" | "default" | "plan", }; updateConfig(newConfig); }; const handleLocaleChange = async (value: SupportedLocale) => { const newConfig = { ...config, locale: value, }; updateConfig(newConfig); }; const handleThemeChange = async (value: "light" | "dark" | "system") => { const newConfig = { ...config, theme: value, }; updateConfig(newConfig); }; return (
{showLabels && ( )}
{showDescriptions && (

)}
{showLabels && ( )}
{showDescriptions && (

)}
{showLabels && ( )} {showDescriptions && (

)}
{showLabels && ( )} {showDescriptions && isToolApprovalAvailable && (

)} {showDescriptions && !isToolApprovalAvailable && (

)}
{showLabels && ( )} {showDescriptions && (

)}
{showLabels && ( )} {showDescriptions && (

)}
); };