import type Konva from "konva";

import type { ImageLayer } from "@/lib/image-editor-types";

export function nodeToImageLayer(node: Konva.Node): Partial<ImageLayer> {
  const scaleX = node.scaleX();
  const scaleY = node.scaleY();

  return {
    x: node.x(),
    y: node.y(),
    width: Math.max(8, node.width() * scaleX),
    height: Math.max(8, node.height() * scaleY),
    rotation: node.rotation(),
  };
}

export function resetNodeScale(node: Konva.Node): void {
  node.scaleX(1);
  node.scaleY(1);
}
