// src/hooks/useCrmProjects.ts
import { useEffect, useState } from "react";
import { crmapi } from "../utils/api";
import { CrmProject } from "@/types/crm";

export function useCrmProjects() {
  const [data, setData] = useState<CrmProject[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<unknown>(null);

  useEffect(() => {
    setLoading(true);
    crmapi.getProjects()
      .then(res => setData(res.data?.data ?? []))
      .catch(setError)
      .finally(() => setLoading(false));
  }, []);

  return { data, loading, error };
} 
