import { atom } from 'jotai';
import { messagesAtom, userHasRepliedAtom } from 'src/atoms/chat';

export const lastAssistantMessageAtom = atom(get => {
  const messages = get(messagesAtom);
  const userHasReplied = get(userHasRepliedAtom);
  if (messages.length > 0 && !userHasReplied) {
    return messages[messages.length - 1];
  }
  return null;
});
