import type { DrawableShape } from './layoutDrawTypes';

const DUPLICATE_OFFSET_PX = 24;

export function duplicateShapeWithLabel(
  shape: DrawableShape,
  nextId: string,
  label = shape.label,
  groupId = shape.groupId ?? null,
): DrawableShape {
  if (shape.type === 'line') {
    return {
      ...shape,
      id: nextId,
      ...(groupId ? { groupId } : {}),
      label,
      x1: shape.x1 + DUPLICATE_OFFSET_PX,
      y1: shape.y1 + DUPLICATE_OFFSET_PX,
      x2: shape.x2 + DUPLICATE_OFFSET_PX,
      y2: shape.y2 + DUPLICATE_OFFSET_PX,
    };
  }

  return {
    ...shape,
    id: nextId,
    ...(groupId ? { groupId } : {}),
    label,
    x: shape.x + DUPLICATE_OFFSET_PX,
    y: shape.y + DUPLICATE_OFFSET_PX,
  };
}
