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

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

  useEffect(() => {
    const fetchData = async () => {
        try {
            const data = await homeService.fetchJourney();
            if (data.payload !== null) {
                setJourney(data.payload);
            }
        } catch (err) {
            setError(err);
        } finally {
            setLoading(false);
        }
    };
    fetchData();
  }, []);

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

export default useDashboards;
