"use client";
import { ReactNode, useCallback } from "react";
import { NodeResizer, OnResize, useReactFlow } from "@xyflow/react";
import { useWorkflowStore } from "@/store/workflowStore";
interface BaseNodeProps {
id: string;
children: ReactNode;
selected?: boolean;
isExecuting?: boolean;
hasError?: boolean;
className?: string;
contentClassName?: string;
minWidth?: number;
minHeight?: number;
/** When true, node has no background/border — content fills the entire node area */
fullBleed?: boolean;
}
export function BaseNode({
id,
children,
selected = false,
isExecuting = false,
hasError = false,
className = "",
contentClassName,
minWidth = 180,
minHeight = 100,
fullBleed = false,
}: BaseNodeProps) {
const currentNodeIds = useWorkflowStore((state) => state.currentNodeIds);
const nodes = useWorkflowStore((state) => state.nodes);
const setHoveredNodeId = useWorkflowStore((state) => state.setHoveredNodeId);
const isCurrentlyExecuting = currentNodeIds.includes(id);
const { getNodes, setNodes } = useReactFlow();
// Synchronize resize across all selected nodes
const handleResize: OnResize = useCallback(
(event, params) => {
const allNodes = getNodes();
const selectedNodes = allNodes.filter((node) => node.selected && node.id !== id);
if (selectedNodes.length > 0) {
setNodes((nodes) =>
nodes.map((node) => {
if (node.selected && node.id !== id) {
return {
...node,
style: {
...node.style,
width: params.width,
height: params.height,
},
};
}
return node;
})
);
}
},
[id, getNodes, setNodes]
);
return (
<>