import React, { useRef, useState, ReactNode, useEffect } from 'react'; import { Box } from '@mui/material'; import { FormikProps, FormikValues } from 'formik'; import ToolOptions, { GetGroupsType, UpdateField } from '@components/options/ToolOptions'; import ToolInputAndResult from '@components/ToolInputAndResult'; import ToolInfo from '@components/ToolInfo'; import Separator from '@components/Separator'; import ToolExamples, { CardExampleType } from '@components/examples/ToolExamples'; import { ToolComponentProps } from '@tools/defineTool'; interface ToolContentProps extends ToolComponentProps { // Input/Output components inputComponent?: ReactNode; resultComponent: ReactNode; renderCustomInput?: ( values: T, setFieldValue: (fieldName: string, value: any) => void ) => ReactNode; // Tool options initialValues: T; getGroups: GetGroupsType | null; // Computation function compute: (optionsValues: T, input: I) => void; // Tool info (optional) toolInfo?: { title: string; description?: string; }; // Input value to pass to the compute function input?: I; exampleCards?: CardExampleType[]; setInput?: React.Dispatch>; // Validation schema (optional) validationSchema?: any; } export default function ToolContent({ title, inputComponent, resultComponent, initialValues, getGroups, compute, toolInfo, exampleCards, input, setInput, validationSchema, renderCustomInput }: ToolContentProps) { const formRef = useRef>(null); const [initialized, forceUpdate] = useState(0); useEffect(() => { if (formRef.current && !initialized) { forceUpdate((n) => n + 1); } }, [initialized]); return ( {toolInfo && toolInfo.title && toolInfo.description && ( )} {exampleCards && exampleCards.length > 0 && ( <> )} ); }