import { useAuth } from 'hooks/useAuth';
import { useClient } from 'hooks/useClient';
import { useQuery } from '@tanstack/react-query';

export const usePlans = () => {
  const client = useClient();
  const { isAuthenticated } = useAuth();

  const { data: plans = [] } = useQuery<string[]>({
    queryKey: ['PLANS'],
    enabled: isAuthenticated,
    queryFn: () => client.get<string[]>('/plans'),
  });

  const getPlan = (name: string) => client.getText(`/plans/${name}`);

  return { plans, getPlan };
};
