import axios from "axios";

const axiosInstance = axios.create({
  baseURL: `${process.env.NEXT_PUBLIC_API_URL}api`, 
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer 8e32297f4b630b69c5446e36e93144e0b3e12827a84252c6c4e6b08d869f817db9b0f7e5c03b6b0553210ac0efe4f7b68bb9f2c3e784e2485794af05087a81f792bf723af2bab3400c5716b478c95c9b8ac0f2a9f3bf836074d8d48cbfeb2f21d03bab93c6f00d846ae7b116953bff27fb09e4cd79febaf2f1bdd421ed7b9417` 
  },
});

export const getBlogPosts = async () => {
  const url = "blog-posts?populate=Image";
  try {
    const response = await Methods.getData(url);
    return response.data; 
  } catch (error: any) {
    throw error?.response?.data || error;
  }
}

const Methods = {
   getData: async(url:string)=> {
    try {
      const response = await axiosInstance.get(url);
      return response.data;
    } catch (error: any) {
      throw error?.response?.data || error;
    }
   },
}