import { useEffect, useState } from 'react'; import ToolContent from '@components/ToolContent'; import ToolCodeInput from '@components/input/ToolCodeInput'; import ToolTextResult from '@components/result/ToolTextResult'; import { compareJson } from './service'; import { ToolComponentProps } from '@tools/defineTool'; import { Grid } from '@mui/material'; type InitialValuesType = {}; const initialValues: InitialValuesType = {}; export default function JsonComparison({ title }: ToolComponentProps) { const [input1, setInput1] = useState(''); const [input2, setInput2] = useState(''); const [result, setResult] = useState(''); useEffect(() => { const compareInputs = () => { try { // Only compare if at least one input has content if (input1.trim() || input2.trim()) { const differences = compareJson( input1 || '{}', input2 || '{}', 'text' ); setResult(differences); } else { setResult(''); } } catch (error) { setResult( `Error: ${ error instanceof Error ? error.message : 'Invalid JSON format' }` ); } }; compareInputs(); }, [input1, input2]); const handleInput1Change = (value: string | undefined) => { setInput1(value ?? ''); }; const handleInput2Change = (value: string) => { setInput2(value); }; return ( {}} inputComponent={ } /> ); }