"use client";

import useSWR from "swr";
import { fetcher } from "@/lib/fetcher";
import type { FavoriteRecord } from "@/types";

export function useFavorites(userId: string | undefined) {
  const { data, isLoading, mutate } = useSWR<FavoriteRecord[]>(
    userId ? `/api/user/favorite?userId=${userId}` : null,
    fetcher,
  );

  return {
    favorites: data ?? [],
    isLoading,
    mutate,
  };
}
