"use client" import { XIcon } from "lucide-react" import { Button } from "@/components/ui/button" import type { AIWorkflowDefinition, AIWorkflowNodeSpec } from "@/lib/api/admin" import type { SelectedWorkflowBranch } from "./workflow-branch-selection" import { ConditionBranchConfigPanel, NodeConfigPanel } from "./node-config-panel" import { getAvailableVariables, normalizeNodeConfig, type WorkflowNodeData, } from "./workflow-utils" export function WorkflowConfigPanel({ definition, nodeSpecs, selectedNodeId, selectedBranch, onClose, onSelectBranch, onChangeNodeData, onDeleteNode, }: { definition: AIWorkflowDefinition nodeSpecs: AIWorkflowNodeSpec[] selectedNodeId: string selectedBranch: SelectedWorkflowBranch | null onClose: () => void onSelectBranch: (branch: SelectedWorkflowBranch | null) => void onChangeNodeData: (nodeId: string, data: WorkflowNodeData) => void onDeleteNode: (nodeId: string) => void }) { const selectedNode = definition.nodes.find((node) => node.id === selectedNodeId) ?? null const selectedNodeSpec = selectedNode ? nodeSpecs.find((spec) => spec.type === selectedNode.type) : undefined const availableVariables = selectedNode ? getAvailableVariables(definition, selectedNode.id, nodeSpecs) : [] const selectedBranchItem = selectedNode && selectedBranch?.nodeId === selectedNode.id ? normalizeNodeConfig(selectedNode.data?.config).branches?.find((branch) => branch.id === selectedBranch.branchId) ?? null : null const panelTitle = selectedBranchItem ? selectedBranchItem.name || selectedBranchItem.id : selectedNode?.data?.title || selectedNodeSpec?.title || selectedNode?.type || "" const panelMeta = selectedBranchItem ? "条件分支" : selectedNode?.type || "" const panelDescription = selectedBranchItem ? "配置该条件分支的匹配规则和目标节点。" : selectedNodeSpec?.description || "" if (!selectedNode) { return null } const deleteSelectedBranch = (branchId: string) => { const config = normalizeNodeConfig(selectedNode.data?.config) onChangeNodeData(selectedNode.id, { ...(selectedNode.data ?? {}), config: { ...config, branches: (config.branches ?? []).filter((branch) => branch.id !== branchId), }, }) onSelectBranch(null) } return (