import { api } from "../utils/axiosClient";

const GlobalRepository = {
  getDashboardProgressionData: ({ days = '', FromDate = '', projectId = '' }) => {
    let params;
    if (projectId == null) {
      params = new URLSearchParams({
        days: days.toString(),
        FromDate,
      });
    } else {
      params = new URLSearchParams({
        days: days.toString(),
        FromDate,
        projectId,
      });
    }

    return api.get(`/api/Dashboard/Progression?${params.toString()}`);
  },
  getProjectCompletionStatus:()=>api.get(`/api/Dashboard/project-completion-status`),


  getDashboardAttendanceData: (date, projectId) => {

    return api.get(`/api/Dashboard/project-attendance/${projectId}?date=${date}`);
  },
  getDashboardProjectsCardData: () => {
    return api.get(`/api/Dashboard/projects`);
  },

  getDashboardTeamsCardData: (projectId) => {
    const url = projectId
      ? `/api/Dashboard/teams?projectId=${projectId}`
      : `/api/Dashboard/teams`;
    return api.get(url);
  },

  getDashboardTasksCardData: (projectId) => {
    const url = projectId
      ? `/api/Dashboard/tasks?projectId=${projectId}`
      : `/api/Dashboard/tasks`;
    return api.get(url);
  },

  getExpenseData: (projectId, startDate, endDate) => {
    let url = `api/Dashboard/expense/type`
    const queryParams = [];
    if (projectId) {
      queryParams.push(`projectId=${projectId}`);
    }
    if (startDate) {
      queryParams.push(`startDate=${startDate}`);
    }
    if (endDate) {
      queryParams.push(`endDate=${endDate}`);
    }

    if (queryParams.length > 0) {
      url += `?${queryParams.join("&")}`;
    }
    return api.get(url);
  },

  getExpenseStatus: (projectId) => api.get(`/api/Dashboard/expense/pendings${projectId ? `?projectId=${projectId}` : ""}`),

  getExpenseDataByProject: (projectId, categoryId, months) => {
    let url = `api/Dashboard/expense/monthly`
    const queryParams = [];
    if (projectId) {
      queryParams.push(`projectId=${projectId}`);
    }
    if (categoryId) {
      queryParams.push(`categoryId=${categoryId}`);
    }
    if (months) {
      queryParams.push(`months=${months}`);
    }
    if (queryParams.length > 0) {
      url += `?${queryParams.join("&")}`;
    }
    return api.get(url);
  },

  getAttendanceOverview: (projectId, days) => api.get(`/api/dashboard/attendance-overview/${projectId}?days=${days}`)



};


export default GlobalRepository;
