import { callApi } from "../api/index.jsx";
import { constants as c } from "../constants";

const apiNews = () => {
  return callApi(`/customer/${c.STORE_CODE}/home_web/posts_new`, "get");
};

const getPostCategories = () => {
  return callApi(`/customer/${c.STORE_CODE}/post_categories`, "get");
};

const getAllPost = () => {
  return callApi(`/customer/${c.STORE_CODE}/posts`, "get");
};

const getNewsDetail = (post) => {
  return callApi(`/customer/${c.STORE_CODE}/posts/${post.idNews}`, "get");
};

const newsByCategory = (post) => {
  return callApi(
    `/customer/${c.STORE_CODE}/posts?danh-muc=${post.slug}-${post.id}&category_ids=${post.id}&`,
    "get"
  );
};

export const news = {
  apiNews,
  getPostCategories,
  getAllPost,
  getNewsDetail,
  newsByCategory,
};
