"use server";

const apiUrl = process.env.NEXT_SERVER_API_URL;

export async function getTableData() {
  try {
    const res = await fetch(
      `${apiUrl}/vorlageFlaechendruck/getAllFlaechendruckVorlagen`
    );
    if (!res.ok) {
      console.error("Response status:", res.status);
    }

    const data: {
      id: number;
      product_type: string;
      height: number;
      width: number;
      printer: string;
      coordinates: {
        x: number;
        y: number;
        rotation: number;
      }[];
    }[] = await res.json();
    return data;
  } catch (error) {
    console.error("Error fetching vorlagen:", error);
    throw new Error("An error occurred while fetching vorlagen.");
  }
}
export async function deleteVorlageFlaechendruck(id: number) {
  const res = await fetch(`${apiUrl}/vorlageFlaechendruck/delete/${id}`, {
    method: "DELETE",
  });

  if (!res.ok) {
    throw new Error("Failed to delete item");
  }

  return;
}
