// validate_space.js

/**
 * Checks if the painting has enough space to be placed.
 * Skips the center block (part 9).
 */
export function isAreaClear(dim, base, direction, width = 4, height = 3) {
  for (let row = 0; row < height; row++) {
    for (let col = 0; col < width; col++) {
      const partNumber = row * width + col + 1;
      if (partNumber === 9) continue; // Skip the central part

      let x = base.x;
      let y = base.y + (height - 1 - row);
      let z = base.z;

      switch (direction) {
        case "south": x -= col; break;
        case "north": x += col; break;
        case "east":  z += col; break;
        case "west":  z -= col; break;
      }

      try {
        const testBlock = dim.getBlock({ x, y, z });
        if (!testBlock || testBlock.typeId !== "minecraft:air") {
          return false;
        }
      } catch {
        return false;
      }
    }
  }

  return true;
}
