// This constants.ts is a mere file to add and extract api request.
// It's purpose is only to organise data and for a healthy code base.

import { getStrapiMedia } from "../utils/media";
import axios from "axios";


export const API_URL = process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:1337';

export const settings = {
    data:{
        logo: getStrapiMedia(`${process.env.NEXT_PUBLIC_BASE_URL}/uploads/logo_45191742ce.png?updated_at=2023-03-20T14:51:36.229Z`)
    }
}

// // Menu Structure 
// export const menu = {
//     data:[
//       {link: "/projects", title: "Projetos"},
//       {link: "/services", title: "Serviços"},
//       {link: "/partners", title: "Parceiros"},
//       {link: "/aboutus", title: "Sobre Nós"}
//   ]
// }

//API for menu
export async function loadMenu () {
    const token = process.env.STRAPI_TOKEN; // Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    let res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/mainmenu/`, { headers });
    const menu = await res.data

    return menu
}

//API for the About us page 
export async function loadAbout () {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/aboutus?populate=*`, { headers });
    const content = await res.data

    return content
}

// API for the Services page 
export async function loadServices () {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/service/`, { headers });
    const content = await res.data

    return content
}

// API for the Partners page 
export async function loadPartners () {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/partner?populate[parceiro][populate]=*`, { headers });
    const content = await res.data

    return content
}   

// API for the Projects page 
export async function loadProjectPage () {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/project-page`, { headers });
    const content = await res.data

    return content
}  

// API for the Projects (The actual project)
export async function loadProjects () {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
  
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/projects`, { headers });
    const content = await res.data

    return content
}  

// API for the Projects (The actual project)
export async function loadProjectById(id) {
    const token = process.env.STRAPI_TOKEN; // Will Replace with your actual token
    const headers = { Authorization: `Bearer ${token}` };
    const res = await axios.get(`${process.env.NEXT_PUBLIC_BASE_URL}/api/projects/${id}`, { headers });
    const content = await res.data

    return content
}  





// Not finished- API for posts 
// Waiting for team to organise posts and what is needed.
// Will only call this once the struture for post has been inserted to Strapi
export async function loadPosts() {
    // Call an external API endpoint to get posts
    const res = await fetch('https://.../posts/')
    const data = await res.json()
  
    return data
  }