import { Pen } from "@meta2d/core";

export function monitorRoom(pen: Pen, ctx?: CanvasRenderingContext2D): Path2D {
  const path = !ctx ? new Path2D() : ctx;
  let wr = pen.calculative.borderRadius || 0,
    hr = wr;
  const { x, y, width, height, ex, ey } = pen.calculative.worldRect;
  if (wr < 1) {
    wr = width * wr;
    hr = height * hr;
  }
  let r = wr < hr ? wr : hr;
  if (width < 2 * r) {
    r = width / 2;
  }
  if (height < 2 * r) {
    r = height / 2;
  }
  path.moveTo(x + r, y);
  path.arcTo(ex, y, ex, ey, r);
  path.arcTo(ex, ey, x, ey, r);
  path.arcTo(x, ey, x, y, r);
  path.arcTo(x, y, ex, y, r);
  path.closePath();
  if (path instanceof Path2D) {
    return path;
  }
}

export const monitorRoomData = {
  name: "monitorRoom",
  width: 214,
  height: 140,
  lineWidth: 0,
  borderRadius: 12,
  background: "rgba(255, 255, 255, 1)",
};
