"use client"; import { Accordion, ActionIcon, LoadingOverlay, SegmentedControl, Textarea, } from "@mantine/core"; import { useForm } from "@mantine/form"; import { IconArrowDownRight, IconMinus, IconPlus, IconRobot, IconRotateClockwise, } from "@tabler/icons-react"; import React, { useCallback, useEffect, useRef } from "react"; import useDebounce from "../hooks/debounce"; import FieldSet from "./FieldSet"; import Label from "./Label"; import SelectInput from "./SelectInput"; import SlideInput from "./SliderInput"; import TextInput from "./TextInput"; export const Controls = React.memo(({ remoteParams, onData }) => { const init = useRef(false); const form = useForm({ initialValues: { prompt: "", negative_prompt: "", steps: 1, guidance: 0.1, seed: 45678, resolution: "720", }, }); const debounce = useDebounce(); const handleChange = useCallback((v) => onData(v), [onData]); useEffect(() => { if (!remoteParams) return; if (!init.current) { form.setValues(remoteParams); init.current = true; } }, [form, remoteParams]); useEffect(() => { if (!form) return; form.isDirty() && debounce(() => handleChange(form.values), 500); }, [form, debounce, handleChange]); return (