/** Flowchart diagram node dimensions for ELK layout spacing. */
export const FLOW_SIZES = {
  process: { w: 160, h: 60 },
  decision: { w: 140, h: 130 },
  terminal: { w: 140, h: 50 },
  io: { w: 160, h: 60 },
  subprocess: { w: 160, h: 60 },
} as const;

const FLOW_TYPE_MAP: Record<string, { w: number; h: number }> = {
  flowProcess: FLOW_SIZES.process,
  flowDecision: FLOW_SIZES.decision,
  flowTerminal: FLOW_SIZES.terminal,
  flowIo: FLOW_SIZES.io,
  flowSubprocess: FLOW_SIZES.subprocess,
};

const FLOW_NODE_TYPE_MAP: Record<string, string> = {
  process: "flowProcess",
  decision: "flowDecision",
  terminal: "flowTerminal",
  io: "flowIo",
  subprocess: "flowSubprocess",
};

/** Get flowchart node dimensions by @xyflow/react node type. Returns null if not a flowchart type. */
export function getFlowNodeSize(
  flowType: string | undefined,
): { w: number; h: number } | null {
  if (!flowType) return null;
  return FLOW_TYPE_MAP[flowType] ?? null;
}

/** Map DiagramNode.type (with or without flow: prefix) to @xyflow/react node type string. */
export function resolveFlowchartNodeType(type: string): string {
  const bare = type.startsWith("flow:") ? type.slice(5) : type;
  return FLOW_NODE_TYPE_MAP[bare] ?? "flowProcess";
}

/** Map DiagramEdge.type to @xyflow/react edge type string for flowchart diagrams. */
export function resolveFlowchartEdgeType(
  _type: string | undefined,
): string {
  return "flowEdge";
}
