'use client';

/**
 * Chat — shared "light surface".
 *
 * The single source of truth for everything safe to load synchronously:
 * types, runtime constants, pure `core` + transports, hooks (no UI),
 * notifier, payload-dispatch, logger, utils, styles, context.
 *
 * Both root entry points re-export this module verbatim:
 * - `index.ts`  (`@djangocfg/ui-tools`)        — `public` + heavy sync components
 * - `lazy.tsx`  (`@djangocfg/ui-tools/chat`)   — `public` + Lazy* wrappers
 *
 * Heavy UI components must NOT be added here — they belong in `index.ts`
 * (sync) and `lazy.tsx` (lazy) only.
 *
 * `./chat` is the only sanctioned Chat subpath — do not add new subpaths
 * (avoids the dual-bundle / two-React-context trap).
 */

// Types
export type {
  ChatRole,
  ChatMessage,
  ChatPersona,
  ChatToolCall,
  ChatAttachment,
  ChatSource,
  ChatDisplayMode,
  ChatUserContext,
  ChatAssistantContext,
  ChatPrefs,
  ChatConfig,
  ChatLabels,
  ChatTransport,
  ChatStreamEvent,
  CreateSessionOptions,
  SessionInfo,
  HistoryPage,
  StreamOptions,
  SendOptions,
  MessageBlock,
  MessageBlockKind,
  BlockAppearance,
  TextBlock,
  MarkdownBlock,
  AudioBlock,
  VideoBlock,
  ImageBlock,
  GalleryBlock,
  MapBlock,
  JsonBlock,
  MermaidBlock,
  CodeBlock,
  LottieBlock,
  CustomBlock,
} from './types';
export { DEFAULT_LABELS } from './types';

// Constants — plain runtime constants, no UI imports
export {
  STORAGE_KEYS,
  CSS_VARS,
  Z_INDEX,
  DEFAULT_Z_INDEX,
  LIMITS,
  DEFAULT_SIDEBAR,
  HOTKEYS,
  CHAT_EVENT_NAME,
  type ChatEventDetail,
} from './constants';

// Core (pure) — reducer / id / token buffer / persona / initials
export {
  reducer,
  initialState,
  createId,
  createTokenBuffer,
  resolvePersona,
  deriveInitials,
  type ChatState,
  type ChatAction,
  type TokenBuffer,
} from './core';

// Transport — pure functions, no UI
export {
  createHttpTransport,
  createMockTransport,
  parseSSE,
  TransportError,
  createPydanticAIChatTransport,
  createToolIdQueue,
  mapPydanticAIEvent,
  createPydanticAISSEMap,
  type HttpTransportConfig,
  type MockTransportOptions,
  type ParseSSEOptions,
  type PydanticAIChatTransportOpts,
  type PydanticAIEvent,
  type ToolIdQueue,
} from './core/transport';

// Hooks — React state glue, no JSX / UI components
export {
  useChat,
  useChatComposer,
  useChatHistory,
  useChatLayout,
  useChatAudio,
  useAutoFocusOnStreamEnd,
  useRegisterComposer,
  useChatReset,
  useVisitorFingerprint,
  useChatDockPrefs,
  DEFAULT_DOCK_PREFS,
  useFocusOnEmptyClick,
  useChatUnread,
  useChatUnreadNotifier,
  useChatLightbox,
  type UseChatUnreadOptions,
  type UseChatUnreadReturn,
  type UseChatUnreadNotifierOptions,
  type UseChatConfig,
  type UseChatReturn,
  type UseChatComposerOptions,
  type UseChatComposerReturn,
  type UseChatHistoryOptions,
  type UseChatLayoutConfig,
  type UseChatLayoutReturn,
  type UseAutoFocusOnStreamEndOptions,
  type Focusable,
  type UseChatResetOptions,
  type UseChatResetReturn,
  type UseVisitorFingerprintOptions,
  type ChatDockPrefs,
  type UseChatDockPrefsOptions,
  type UseChatDockPrefsReturn,
  type UseFocusOnEmptyClickOptions,
  type UseChatLightboxReturn,
  type ChatLightboxState,
  type ChatLightboxScope,
} from './hooks';

// Audio
export {
  useChatAudioPrefs,
  DEFAULT_CHAT_SOUNDS,
  type ChatAudioEvent,
  type ChatAudioSounds,
  type ChatAudioConfig,
  type UseChatAudioReturn,
} from './core/audio';

// Settings — the single, centralized home for chat-owned persisted
// settings. Every chat feature reads/writes its slice through this hook.
export {
  useChatSettings,
  CHAT_SETTINGS_STORAGE_KEY,
  DEFAULT_CHAT_SETTINGS,
  type ChatSettings,
  type ChatDockSettings,
  type ChatAudioSettings,
  type ChatSpeechSettings,
  type ChatPageContextSettings,
  type UseChatSettingsOptions,
  type UseChatSettingsReturn,
} from './settings';

// Notifier — title rotation + favicon badge + page-visibility + cross-tab
export {
  createBrowserNotifier,
  createNoopNotifier,
  createTitleRotator,
  createFaviconBadge,
  createCrossTabNotifier,
  isPageHidden,
  onVisibilityChange,
  type ChatNotifier,
  type BrowserNotifierOptions,
  type TitleRotatorOptions,
  type TitleMode,
  type FaviconBadgeOptions,
  type CrossTabNotifierOptions,
} from './notifier';

// Tool-call payload dispatcher — pure
export {
  dispatchToolPayload,
  isPlainObject,
  isLatLng,
  isGeoJSONFeatureCollection,
  isStringValue,
  type ToolPayloadMatcher,
  type ToolPayloadFallback,
} from './core/payload-dispatch';

// Dev logger (consola-based, namespace "chat:*")
export { getChatLogger, type ChatLogger, type ChatLogScope } from './core/logger';

// Utils — pure helpers
export { sanitizeDraft, isSubmittableDraft, collectImageAttachments } from './utils';

// Styles — role-aware className tokens + hooks
export {
  BUBBLE_SURFACE,
  ANCHOR,
  TOGGLE,
  DESTRUCTIVE_SURFACE,
  TOOL_CALL,
  useChatBubbleStyles,
  useChatRoleStyles,
  useChatDestructiveStyles,
  type ChatBubbleSurface,
  type ChatBubbleStyles,
  type ChatRoleStyles,
  type ChatDestructiveStyles,
} from './styles';

// Context — provider + hooks for callers wiring custom chat shells
export {
  ChatProvider,
  useChatContext,
  useChatContextOptional,
  type ChatContextValue,
  type ChatProviderProps,
  type ComposerHandle,
} from './context';
