/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { memo, useCallback, useState } from 'react' import { type UseFormReturn } from 'react-hook-form' import { Code2, Eye, HelpCircle } from 'lucide-react' import { useTranslation } from 'react-i18next' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from '@/components/ui/accordion' import { Button } from '@/components/ui/button' import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, } from '@/components/ui/sheet' import { Switch } from '@/components/ui/switch' import { Textarea } from '@/components/ui/textarea' import { sideDrawerContentClassName, sideDrawerFormClassName, sideDrawerHeaderClassName, } from '@/components/drawer-layout' import { SettingsForm, SettingsSwitchContent, SettingsSwitchItem, } from '../components/settings-form-layout' import { SettingsPageActionsPortal } from '../components/settings-page-context' import { GroupRatioVisualEditor } from './group-ratio-visual-editor' import { GroupSpecialUsableRulesEditor } from './group-special-usable-editor' type GroupFormValues = { GroupRatio: string TopupGroupRatio: string UserUsableGroups: string GroupGroupRatio: string AutoGroups: string DefaultUseAutoGroup: boolean GroupSpecialUsableGroup: string } type GroupRatioFormProps = { form: UseFormReturn onSave: (values: GroupFormValues) => Promise isSaving: boolean } export const GroupRatioForm = memo(function GroupRatioForm({ form, onSave, isSaving, }: GroupRatioFormProps) { const { t } = useTranslation() const [editMode, setEditMode] = useState<'visual' | 'json'>('visual') const [guideOpen, setGuideOpen] = useState(false) const handleFieldChange = useCallback( (field: keyof GroupFormValues, value: string) => { form.setValue(field, value, { shouldValidate: true, shouldDirty: true, }) }, [form] ) const toggleEditMode = useCallback(() => { setEditMode((prev) => (prev === 'visual' ? 'json' : 'visual')) }, []) return (
{editMode === 'visual' ? (
handleFieldChange(field as keyof GroupFormValues, value) } /> handleFieldChange('GroupSpecialUsableGroup', value) } /> ( {t('Default to auto groups')} {t( 'When enabled, newly created tokens start in the first auto group.' )} )} />
) : ( ( {t('Group ratios')}