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

// Per-room toggle: when true, BotExperienceHost renders the standard chat
// (Room + RoomView) instead of BotShell. Owned by an atom so the «Настроить»
// dropdown in the host hero can write it without prop-drilling, and so
// remounting the page for the same room preserves the user's last selection.
//
// AtomFamily keyed by roomId — switching rooms keeps each room's toggle
// isolated. NOT auto-GC'd; for current single-bot deployments the cardinality
// is bounded. Multi-bot scope (Phase 4+) should call
// `botShowChatAtomFamily.remove(roomId)` on leave-room.
export const botShowChatAtomFamily = atomFamily((_roomId: string) => atom(false));

// Per-room sticky failure flag. Set when the widget iframe fails to load or
// errors during runtime. Held alongside `showChat` so the chat-fallback
// view can offer «Retry widget» (vs. plain «Show widget») and so the user
// can recover from a stuck state without losing context. Cleared explicitly
// on retry / clean reload of BotShell.
export const botFailedAtomFamily = atomFamily((_roomId: string) => atom(false));
