import { useQuery } from '@tanstack/react-query';
import { orderService } from '../api/order.service';

export function useSellers() {
  const query = useQuery({
    queryKey: ['sellers'],
    queryFn: () => orderService.findSellers(),
    staleTime: 1000 * 60 * 30, // 30 minutes
    retry: 1,
    retryOnMount: false,
    refetchOnWindowFocus: false,
  });

  const options =
    query.data?.map((seller, index) => {
      return {
        value: seller.id.toString(),
        label: seller.name,
        id: `seller-${seller.id}-${index}`,
        seller: seller,
      };
    }) ?? [];

  return {
    ...query,
    options,
  };
}
