import { useState, useEffect } from 'react';
import learningService from '../services/learningService';
import { MEDIA_URL } from '../../../../utils/Constant';

const useSections = () => {
    const [sections, setSections] = useState([]);
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(null);
    const thumbPath = `${MEDIA_URL}/section/`;

    useEffect(() => {
        const fetchData = async () => {
          try {
            const dataAPI = await learningService.fetchSections();
            const data = dataAPI.payload;
            
            setSections(data);
          } catch (error) {
            setError(error);
          } finally {
            setLoading(false);
          }
        };

        fetchData();
    }, []);

    return { sections, loading, error, thumbPath};
};

export default useSections;
