import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { ProjectSchema } from "@/lib/client";
import { getProjectsOptions } from "@/lib/client/@tanstack/react-query.gen";

const useProjectsList = () => {
    const [projects, setProjects] = useState<ProjectSchema[]>([]);

    const { data, refetch, isLoading } = useQuery({
        ...getProjectsOptions(),
    });

    useEffect(() => {
        if (data?.projects) {
            setProjects(data.projects);
        }
    }, [data?.projects]);

    return { projects, setProjects, refetch, isLoading };
};

export default useProjectsList;
