import {useState} from 'react'
import FlowEditor from '../components/flow/FlowEditor.tsx'
import type {GraphData} from '../components/flow/types.ts'

function Test() {
  // language=JSON
  const [graphData] = useState<GraphData>(JSON.parse('{"nodes":[{"id":"QxNrkChBWQ","type":"loop-node","position":{"x":890,"y":119},"data":{},"measured":{"width":1049,"height":382},"selected":false,"dragging":false,"width":1049,"height":382,"resizing":false},{"id":"MzEitlOusl","type":"llm-node","position":{"x":52.27803164309171,"y":130},"data":{},"measured":{"width":256,"height":108},"selected":false,"dragging":false,"extent":"parent","parentId":"QxNrkChBWQ"},{"id":"bivXSpiLaI","type":"code-node","position":{"x":100,"y":188},"data":{},"measured":{"width":256,"height":108},"selected":false,"dragging":false},{"id":"JsUwvjkJCW","type":"switch-node","position":{"x":495,"y":219},"data":{},"measured":{"width":256,"height":134},"selected":true,"dragging":false},{"id":"sRWQqqshAE","type":"llm-node","position":{"x":938,"y":551},"data":{},"measured":{"width":256,"height":108},"selected":false,"dragging":false},{"id":"bDgwRcxgHo","type":"code-node","position":{"x":397.0305805332712,"y":169.58523732318685},"data":{},"parentId":"QxNrkChBWQ","extent":"parent","measured":{"width":256,"height":108},"selected":false,"dragging":false},{"id":"fzmjIpcUsy","type":"output-node","position":{"x":721.6295265834033,"y":238.19964868337735},"data":{},"parentId":"QxNrkChBWQ","extent":"parent","measured":{"width":256,"height":79},"selected":false,"dragging":false},{"id":"nutuhaTLel","type":"llm-node","position":{"x":2075.444643036393,"y":334.5237261697987},"data":{},"measured":{"width":256,"height":108},"selected":false,"dragging":false}],"edges":[{"source":"bivXSpiLaI","sourceHandle":"source","target":"JsUwvjkJCW","id":"xy-edge__bivXSpiLaIsource-JsUwvjkJCW"},{"source":"JsUwvjkJCW","sourceHandle":"736a724a5de4","target":"QxNrkChBWQ","targetHandle":"target","id":"xy-edge__JsUwvjkJCW736a724a5de4-QxNrkChBWQtarget"},{"source":"JsUwvjkJCW","sourceHandle":"406bf6637c64","target":"sRWQqqshAE","targetHandle":"target","id":"xy-edge__JsUwvjkJCW406bf6637c64-sRWQqqshAEtarget"},{"source":"MzEitlOusl","sourceHandle":"source","target":"bDgwRcxgHo","targetHandle":"target","id":"xy-edge__MzEitlOuslsource-bDgwRcxgHotarget"},{"source":"bDgwRcxgHo","sourceHandle":"source","target":"fzmjIpcUsy","targetHandle":"target","id":"xy-edge__bDgwRcxgHosource-fzmjIpcUsytarget"},{"source":"QxNrkChBWQ","sourceHandle":"source","target":"nutuhaTLel","targetHandle":"target","id":"xy-edge__QxNrkChBWQsource-nutuhaTLeltarget"}],"data":{"MzEitlOusl":{"node":{"name":"大模型","description":"使用大模型对话"},"outputs":{"text":{"type":"text"}},"model":"qwen3","systemPrompt":"你是个好人","finished":true},"bivXSpiLaI":{"node":{"name":"代码执行","description":"执行自定义的处理代码"},"outputs":{"text":{"type":"text"},"condition":{"type":"boolean"},"count":{"type":"number"},"person":{"type":"object"},"words":{"type":"array-text"},"people":{"type":"array-object"}},"type":"javascript","content":"console.log(\'hello\')","inputs":{},"finished":true},"QxNrkChBWQ":{"node":{"name":"循环","description":"实现循环执行流程"},"finished":true,"outputs":{"output":{"type":"array-object"}}},"JsUwvjkJCW":{"node":{"name":"分支","description":"根据不同的情况前往不同的分支"},"conditions":[{"condition":{"id":"736a724a5de4","conjunction":"and","children":[{"id":"1cbccc438a64","left":{"type":"field","field":"bivXSpiLaI.text"},"op":"equal","right":"2"},{"id":"7bf51315dd05","left":{"type":"field","field":"bivXSpiLaI.condition"},"op":"not_equal","right":true}]}},{"condition":{"id":"406bf6637c64","conjunction":"and","children":[{"id":"ea37e95e6d1b","left":{"type":"field","field":"bivXSpiLaI.text"},"op":"equal","right":"3"}]}}],"finished":true},"sRWQqqshAE":{"node":{"name":"大模型","description":"使用大模型对话"},"outputs":{"text":{"type":"text"}},"model":"deepseek","systemPrompt":"Hello","finished":true},"bDgwRcxgHo":{"node":{"name":"代码执行","description":"执行自定义的处理代码"},"type":"javascript","content":"console.log(\'hello\')","outputs":{"ok":{"type":"boolean"}},"finished":true},"fzmjIpcUsy":{"node":{"name":"输出","description":"定义输出变量"},"output":"loopItem","finished":true},"nutuhaTLel":{"node":{"name":"大模型","description":"使用大模型对话"},"outputs":{"text":{"type":"text"}},"model":"qwen3","systemPrompt":"你是个好人","finished":true}}}'))

  return (
    <div className="h-screen">
      <FlowEditor
        inputSchema={{}}
        graphData={graphData}
        onGraphDataChange={data => console.log(data)}
      />
    </div>
  )
}

export default Test