import {
  assertSceneMediaSrc
} from "./chunk-M2EBUDZ7.js";

// src/design-canvas-react/insert-builders.ts
var MAX_INSERT_DIMENSION = 600;
function mintElementId() {
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
    return crypto.randomUUID();
  }
  return `el-${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
function fittedSize(naturalW, naturalH, pageWidth, pageHeight) {
  const cap = Math.min(MAX_INSERT_DIMENSION, pageWidth * 0.8, pageHeight * 0.8);
  const longest = Math.max(naturalW, naturalH);
  const scale = naturalW > 0 && naturalH > 0 ? Math.min(1, cap / longest) : 1;
  const width = Math.max(1, Math.round((naturalW || cap) * scale));
  const height = Math.max(1, Math.round((naturalH || cap) * scale));
  return { width, height };
}
function centeredPosition(width, height, pageWidth, pageHeight) {
  return {
    x: Math.round((pageWidth - width) / 2),
    y: Math.round((pageHeight - height) / 2)
  };
}
function baseAttrs(name, x, y) {
  return { id: mintElementId(), name, x, y, rotation: 0, opacity: 1, locked: false, visible: true };
}
function addElementOp(pageId, element) {
  return { type: "add_element", pageId, element };
}
function buildInsertImageOp(src, naturalSize, page) {
  assertSceneMediaSrc(src, "image src");
  const { width, height } = fittedSize(naturalSize.width, naturalSize.height, page.width, page.height);
  const { x, y } = centeredPosition(width, height, page.width, page.height);
  const element = {
    ...baseAttrs("Image", x, y),
    kind: "image",
    width,
    height,
    src,
    fit: "contain"
  };
  return addElementOp(page.pageId, element);
}
var DEFAULT_INSERT_TEMPLATES = [
  {
    id: "heading",
    label: "Heading",
    build(page) {
      const width = Math.min(480, Math.round(page.width * 0.7));
      const { x, y } = centeredPosition(width, 60, page.width, page.height);
      const element = {
        ...baseAttrs("Heading", x, y),
        kind: "text",
        text: "Add a headline",
        width,
        fontFamily: "Inter",
        fontSize: 48,
        fontStyle: "bold",
        fill: "#111827",
        align: "left",
        lineHeight: 1.1,
        letterSpacing: 0
      };
      return [addElementOp(page.pageId, element)];
    }
  },
  {
    id: "body",
    label: "Body text",
    build(page) {
      const width = Math.min(420, Math.round(page.width * 0.6));
      const { x, y } = centeredPosition(width, 80, page.width, page.height);
      const element = {
        ...baseAttrs("Body", x, y),
        kind: "text",
        text: "Add a paragraph of supporting copy.",
        width,
        fontFamily: "Inter",
        fontSize: 20,
        fontStyle: "normal",
        fill: "#374151",
        align: "left",
        lineHeight: 1.4,
        letterSpacing: 0
      };
      return [addElementOp(page.pageId, element)];
    }
  },
  {
    id: "rect",
    label: "Rectangle",
    build(page) {
      const width = Math.min(320, Math.round(page.width * 0.4));
      const height = Math.min(200, Math.round(page.height * 0.3));
      const { x, y } = centeredPosition(width, height, page.width, page.height);
      const element = {
        ...baseAttrs("Rectangle", x, y),
        kind: "rect",
        width,
        height,
        fill: "#6366f1",
        cornerRadius: 12
      };
      return [addElementOp(page.pageId, element)];
    }
  },
  {
    id: "ellipse",
    label: "Ellipse",
    build(page) {
      const size = Math.min(220, Math.round(Math.min(page.width, page.height) * 0.3));
      const { x, y } = centeredPosition(size, size, page.width, page.height);
      const element = {
        ...baseAttrs("Ellipse", x, y),
        kind: "ellipse",
        width: size,
        height: size,
        fill: "#10b981"
      };
      return [addElementOp(page.pageId, element)];
    }
  }
];

export {
  MAX_INSERT_DIMENSION,
  mintElementId,
  fittedSize,
  centeredPosition,
  buildInsertImageOp,
  DEFAULT_INSERT_TEMPLATES
};
//# sourceMappingURL=chunk-SQV7NUEM.js.map