import { getApiBaseUrl } from "@/components/main/BaseUrl";
import { Project } from "@/types/types";

export async function fetchProject(
  id: string,
  token = ""
): Promise<Project | null> {
  try {
    const response = await fetch(`${getApiBaseUrl()}/projects/get/web/${id}`, {
      cache: "no-store",
      headers: {
        Authorization: token ? `Bearer ${token}` : "",
      },
    });

    if (!response.ok) return null;

    const data = await response.json();
    return data?.project ?? null;
  } catch {
    return null;
  }
}
