import axios from 'axios';
import axiosInstance from '../../../../utils/axiosInstance';
import { API_URL } from '../../../../utils/Constant';

const fetchDataStudent = async (search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/stdLearning/activities?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching progress:', error);
        throw error;
    }
};

const fetchDataClass = async (search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/class/admin?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching progress:', error);
        throw error;
    }
};

const getStudentById = async (id) => {
    try {
        const response = await axiosInstance.get(`/progress/${id}`);
        return response.data;
    } catch (error) {
        console.error(`Error fetching progress with student ID ${id}:`, error);
        throw error;
    }
};

const getTopicByClass = async (id, search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/monitoring/class/${id}?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching progress:', error);
        throw error;
    }
};

const fetchDataStudentProgress = async (id, search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/monitoring/progress/${id}?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching progress:', error);
        throw error;
    }
};

const fetchDataClassProgress = async (classId, search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/stdLearning/activities/class/${classId}?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching progress:', error);
        throw error;
    }
};

export default{
    fetchDataStudent,
    fetchDataClass,
    getStudentById,
    getTopicByClass,
    fetchDataStudentProgress,
    fetchDataClassProgress
};
