import { useQuery } from 'react-query';

import { useAuth } from 'src/contexts/JWTContext';
import { getUserSegmentation } from 'src/services/users';

import { userKeys } from 'src/components/dashboard/users/queries';

export const useCarLibraryId = () => {
  const { user } = useAuth();
  return useQuery(
    userKeys.segmentation(user!.id),
    () => getUserSegmentation(user!.id),
    {
      select: data => {
        const getCarLibraryId = (items: number[]) => {
          return data.data.some(g => g.items?.some(i => items.includes(i.id)));
        };
        switch (true) {
          case getCarLibraryId([346927, 346951]):
            return 764755;
          case getCarLibraryId([346916, 346944]):
            return 764788;
          case getCarLibraryId([346904, 346937]):
            return 1218638;
        }
      },
    },
  );
};
