import axios from "axios";
import { envConfig } from "./config";
import { cookies } from "next/headers";

if (!envConfig.apiUrl) {
  console.error("API URL is not defined in envConfig");
}

export async function getCost() {
  const cookieStore = cookies();
  const token = (await cookieStore).get("token")?.value;

  try {
    const response = await axios.get(`${envConfig.apiUrl}/costo`, {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    });
    return response.data;
  } catch (error: any) {
    const msg =
      error.response?.data?.error ||
      error.message ||
      "Error desconocido al cobrar impresión";
    return { error: msg };
  }
}
//IO
