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

import api from '../services/api';

export const useSearchUnit = (
  token: string,
  number: string,
  byNumberStart: boolean,
  name: string,
  place: string,
  areaId: string,
  bankNumber: string,
  ic: string,
  disabled = false,
) => {
  return useQuery(
    ['search-unit', [token, number, byNumberStart, name, place, areaId, bankNumber, ic]],
    () =>
      api.organizationUnit.unitAllGet(
        token,
        number,
        byNumberStart,
        name,
        place,
        areaId,
        bankNumber,
        ic,
      ),
    {
      enabled: !!token && !disabled,
    },
  );
};
