import { useLiveQuery } from 'dexie-react-hooks';
import { encountersRepo } from '@/lib/db/repositories';
import type { Encounter } from '@/lib/schemas';

export function useEncounters(campaignId: string): Encounter[] {
  return useLiveQuery(() => encountersRepo.listByCampaign(campaignId), [campaignId], []);
}

export function useEncounter(id: string | null): Encounter | undefined {
  return useLiveQuery(
    () => (id ? encountersRepo.get(id) : Promise.resolve(undefined)),
    [id],
    undefined,
  );
}
