import React, { useEffect, useMemo, useState } from 'react'; import { useForm } from 'react-hook-form'; import { Modal, TextInput, Textarea, Select, Button, Flex, Stack, Checkbox, } from '@mantine/core'; import { addOutputProfile, BUILT_IN_COMMANDS, COMMAND_EXAMPLES, getResolver, toCommandSelection, updateOutputProfile, } from '../../utils/forms/OutputProfileUtils'; const OutputProfile = ({ profile = null, isOpen, onClose }) => { const [commandSelection, setCommandSelection] = useState('ffmpeg'); const defaultValues = useMemo( () => ({ name: profile?.name || '', command: profile?.command || 'ffmpeg', parameters: profile?.parameters || '', is_active: profile?.is_active ?? true, }), [profile] ); const { register, handleSubmit, formState: { errors, isSubmitting }, reset, setValue, watch, } = useForm({ defaultValues, resolver: getResolver(), }); useEffect(() => { reset(defaultValues); setCommandSelection(toCommandSelection(profile?.command || 'ffmpeg')); }, [defaultValues, reset, profile]); const onSubmit = async (values) => { if (profile?.id) { await updateOutputProfile({ id: profile.id, ...values }); } else { await addOutputProfile(values); } reset(); onClose(); }; if (!isOpen) return <>; const isLocked = profile ? profile.locked : false; const isCustom = commandSelection === '__custom__'; const isActiveValue = watch('is_active'); return (