import { useQuery } from '@tanstack/react-query';
import { api } from '@/shared/lib/apiClient';

/**
 * useKanban — Pipeline Pillar kanban board data
 * Returns leads grouped by stage.
 */
export function useKanban() {
  const query = useQuery({
    queryKey: ['kanban'],
    queryFn:  () => api.get<KanbanStage[]>('/crm/pipeline/kanban'),
    staleTime: 30_000,
    refetchInterval: 60_000,
  });
  return { stages: query.data ?? [], isLoading: query.isLoading };
}

export interface KanbanStage {
  id: string;
  label: string;
  emoji: string;
  leads: KanbanLead[];
}

export interface KanbanLead {
  id: string;
  name: string;
  location?: string;
  qdScore: number;
  qdDelta?: number;
  lastContactRelative: string;
  lastContactChannel: string;
  isVaultActive?: boolean;
}
