import { useState, useEffect } from "react";
import axios from "axios";
import { GET_CITY_LISTS } from "@/core/utils/routes";

const useCities = () => {
    const [cities, setCities] = useState([]);
    const [loadingCities, setLoadingCities] = useState(true);
    const [errorCities, setErrorCities] = useState(null);

    useEffect(() => {
        const fetchCities = async () => {
            try {
                const response = await axios.get(`${GET_CITY_LISTS}`);
                setCities(response.data.data);
                setLoadingCities(false);
            } catch (e) {
                console.error("Error fetching cities:", e);
                setErrorCities(e);
                setLoadingCities(false);
            }
        };

        fetchCities();
    }, []);

    return { cities, loadingCities, errorCities };
};

export default useCities;
