import { atom } from 'jotai';
import { atomFamily } from 'jotai/utils';

/** Stores the active thread root event ID for a given room. `undefined` means no thread is open. */
const createActiveThreadAtom = () => atom<string | undefined>(undefined);

export type TActiveThreadAtom = ReturnType<typeof createActiveThreadAtom>;

export const activeThreadIdAtomFamily = atomFamily<string, TActiveThreadAtom>(
  createActiveThreadAtom
);
