export async function uploadToOpeninary(file: File, folder: string) {
  const formData = new FormData();
  formData.append("files", file);
  formData.append("folder", folder);

  const res = await fetch(`${process.env.OPENINARY_API_URL}/api/upload`, {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.OPENINARY_API_KEY}` },
    body: formData,
  });

  if (!res.ok) {
    const errorText = await res.text();
    console.error("Openinary upload error:", errorText);
    throw new Error("Upload başarısız: " + errorText);
  }
  const data = await res.json();
  return data.files[0]; // { path, url, size, ... }
}
