import api from './client';

export const apiGetDivision = async ({ user, search, group, kategori, active, page }: { user: string, search: string, group?: string, kategori?: string, active?: string, page?: number }) => {
   const response = await api.get(`mobile/division?user=${user}&active=${active}&group=${group}&search=${search}&cat=${kategori}&page=${page}`);
   return response.data;
};

export const apiGetDivisionReport = async ({ user, cat, date, dateEnd, division, group }: { user: string, cat: 'table-progress' | 'lainnya', date: string, dateEnd: string, division: string, group?: string }) => {
   const response = await api.get(`mobile/division/report?user=${user}&cat=${cat}&date=${date}&date-end=${dateEnd}&division=${division}&group=${group}`);
   return response.data;
};

export const apiGetDivisionOneFeature = async ({ user, cat, id }: { user: string, cat: 'jumlah' | 'today-task' | 'new-file' | 'new-discussion' | 'check-member' | 'check-admin', id: string }) => {
   const response = await api.get(`mobile/division/${id}/detail?user=${user}&cat=${cat}`);
   return response.data;
};

export const apiGetDivisionOneDetail = async ({ user, id }: { user: string, id: string }) => {
   const response = await api.get(`mobile/division/${id}?user=${user}`);
   return response.data;
};

export const apiCreateDivision = async (data: { data: { idGroup: string, name: string, desc: string }, member: [], admin: string[], user: string }) => {
   const response = await api.post(`/mobile/division`, data)
   return response.data;
};

export const apiCheckDivisionName = async (data: { data: { idGroup: string, name: string, desc: string }, user: string }) => {
   const response = await api.put(`/mobile/division`, data)
   return response.data;
};

export const apiEditDivision = async (data: { user: string, name: string, desc: string }, id: string) => {
   const response = await api.put(`mobile/division/${id}`, data)
   return response.data
};

export const apiUpdateStatusDivision = async ({ data, id }: { data: { user: string, isActive: boolean }, id: string }) => {
   const response = await api.post(`/mobile/division/${id}/status`, data)
   return response.data;
};

export const apiGetDivisionMember = async ({ user, id, search }: { user: string, id: string, search: string }) => {
   const response = await api.get(`mobile/division/${id}/member?user=${user}&search=${search}`);
   return response.data;
};

export const apiGetListDivisionByIdDivision = async ({ user, search, division }: { user: string, search: string, division: string }) => {
   const response = await api.get(`mobile/division/more?user=${user}&search=${search}&division=${division}`);
   return response.data;
};

export const apiUpdateStatusAdminDivision = async (data: { user: string, id: string, isAdmin: boolean }, id: string) => {
   const response = await api.put(`mobile/division/${id}/detail`, data)
   return response.data
};

export const apiDeleteMemberDivision = async (data: { user: string, id: string }, id: string) => {
   const response = await api.delete(`/mobile/division/${id}/detail`, { data })
   return response.data;
};

export const apiAddMemberDivision = async ({ data, id }: { data: { user: string, member: any[] }, id: string }) => {
   const response = await api.post(`/mobile/division/${id}/detail`, data)
   return response.data;
};
