export const ApiUrl = async (urlPath: String) => {
  const apiURL = `${process.env.API_URL}/${process.env.API_VERSION}/${urlPath}`;
  return apiURL;
};

export const NavigationProjectsCategories = async () => {
  const url = await ApiUrl("projects/categories");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const FooterContact = async () => {
  const url = await ApiUrl("contact/footer");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const HomepageBanner = async () => {
  const url = await ApiUrl("homepage/banner");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const HomepageAbout = async () => {
  const url = await ApiUrl("homepage/about");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const HomepageServices = async () => {
  const url = await ApiUrl("homepage/services");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const HomepageProjects = async () => {
  const url = await ApiUrl("homepage/projects");
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const ServiceBySlug = async (slug: string) => {
  const url = await ApiUrl(`service/${slug}`);
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const OtherServices = async (slug: string) => {
  const url = await ApiUrl(`services/${slug}`);
  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const CategoryBySlug = async (slug: string) => {
  const url = await ApiUrl(`projects/category/${slug}`);

  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const ProjectsByCategorySlug = async (categorySlug: string) => {
  const url = await ApiUrl(`projects/${categorySlug}`);

  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const ProjectBySlug = async (slug: string) => {
  const url = await ApiUrl(`project/${slug}`);

  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const OtherProjects = async (categorySlug: string, slug: string) => {
  const url = await ApiUrl(`projects/${categorySlug}/${slug}`);

  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};

export const ContactPageContent = async () => {
  const url = await ApiUrl(`contact/content`);

  try {
    const res = await fetch(url, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
      next: {
        revalidate: 60,
      },
    });
    const data: any = await res.json();

    return data;
  } catch (e) {
    console.log(e);
  }
};
