'use server';

import { IProjectCardProps } from '@/components/pages/project/project';
import api from '@/lib/axios';
import { IResponse } from '@/models/response';
import { cookies } from 'next/headers';

export async function getProjectCategories() {
  const cookiesStore = await cookies();
  return api
    .get('/project_categories', {
      headers: {
        Cookie: cookiesStore.toString(),
      },
    })
    .then(({ data }) => {
      return Promise.resolve(data.data);
    })
    .catch((error) => Promise.reject(error));
}



export async function getProjects(
  categoryId: string,
  page = 1,
): Promise<IResponse<IProjectCardProps[]>> {
  const cookiesStore = await cookies();
  return api
    .get(`/project_categories/${categoryId}/projects`, {
      headers: {
        Cookie: cookiesStore.toString(),
      },
      params: { page },
    })
    .then(({ data }) => {
      return Promise.resolve(data);
    })
    .catch((error) => Promise.reject(error));
}
