'use client';

/**
 * @djangocfg/ui-tools — Chat
 *
 * Decomposed, transport-agnostic chat. See @dev/@refactoring7-chat/ for design.
 */

// Types
export type {
  ChatRole,
  ChatMessage,
  ChatPersona,
  ChatToolCall,
  ChatAttachment,
  ChatSource,
  ChatDisplayMode,
  ChatUserContext,
  ChatAssistantContext,
  ChatPrefs,
  ChatConfig,
  ChatLabels,
  ChatTransport,
  ChatStreamEvent,
  CreateSessionOptions,
  SessionInfo,
  HistoryPage,
  StreamOptions,
  SendOptions,
} from './types';
export { DEFAULT_LABELS } from './types';

// Config
export {
  STORAGE_KEYS,
  CSS_VARS,
  DEFAULT_Z_INDEX,
  LIMITS,
  DEFAULT_SIDEBAR,
  HOTKEYS,
  CHAT_EVENT_NAME,
  type ChatEventDetail,
} from './config';

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

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

// Launcher (FAB + Dock + Header + Greeting composition)
export {
  ChatFAB,
  ChatDock,
  ChatHeader,
  ChatHeaderActionButton,
  ChatHeaderModeToggle,
  ChatHeaderAudioToggle,
  ChatHeaderResetButton,
  ChatHeaderLanguageButton,
  ChatLauncher,
  ChatGreeting,
  ChatUnreadPreview,
  useChatPresence,
  type ChatFABProps,
  type ChatFABPosition,
  type ChatFABVariant,
  type ChatFABSize,
  type ChatDockProps,
  type ChatDockMode,
  type ChatDockSide,
  type ChatHeaderProps,
  type ChatHeaderActionButtonProps,
  type ChatHeaderModeToggleProps,
  type ChatHeaderAudioToggleProps,
  type ChatHeaderResetButtonProps,
  type ChatHeaderLanguageButtonProps,
  type ChatLauncherProps,
  type ChatLauncherHotkey,
  type ChatLauncherGreeting,
  type ChatGreetingProps,
  type ChatUnreadPreviewProps,
  type ChatPresencePhase,
} from './launcher';

// Hooks
export {
  useChat,
  useChatComposer,
  useChatScroll,
  useChatHistory,
  useChatLayout,
  useChatAudio,
  useAutoFocusOnStreamEnd,
  useRegisterComposer,
  useChatReset,
  useVisitorFingerprint,
  useChatDockPrefs,
  DEFAULT_DOCK_PREFS,
  useFocusOnEmptyClick,
  useChatUnread,
  type UseChatUnreadOptions,
  type UseChatUnreadReturn,
  type UseChatConfig,
  type UseChatReturn,
  type UseChatComposerOptions,
  type UseChatComposerReturn,
  type UseChatScrollOptions,
  type UseChatScrollReturn,
  type UseChatHistoryOptions,
  type UseChatLayoutConfig,
  type UseChatLayoutReturn,
  type UseAutoFocusOnStreamEndOptions,
  type Focusable,
  type UseChatResetOptions,
  type UseChatResetReturn,
  type UseVisitorFingerprintOptions,
  type ChatDockPrefs,
  type UseChatDockPrefsOptions,
  type UseChatDockPrefsReturn,
  type UseFocusOnEmptyClickOptions,
} from './hooks';

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

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

// Lightbox helpers
export { useChatLightbox, type UseChatLightboxReturn, type ChatLightboxState } from './hooks';

// 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';
export { collectImageAttachments } from './utils/collectImageAttachments';

// Draft sanitation — trim, collapse runs, strip zero-width chars.
// Wire into your composer's submit handler / Send-button gate so
// empty-after-cleanup drafts don't fire bogus messages.
export { sanitizeDraft, isSubmittableDraft } from './utils/sanitizeDraft';

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

// Context
export {
  ChatProvider,
  useChatContext,
  useChatContextOptional,
  type ChatContextValue,
  type ChatProviderProps,
} from './context';

// Components
export {
  ChatRoot,
  MessageList,
  MessageBubble,
  MessageActions,
  Composer,
  Sources,
  ToolCalls,
  Attachments,
  AttachmentsGrid,
  AttachmentsList,
  EmptyState,
  ErrorBanner,
  JumpToLatest,
  StreamingIndicator,
  AudioToggle,
  type ChatRootProps,
  type MessageListProps,
  type MessageListHandle,
  type MessageBubbleProps,
  type MessageActionsProps,
  type ComposerProps,
  type SourcesProps,
  type ToolCallsProps,
  type ToolPayloadKind,
  type AttachmentsProps,
  type AttachmentsGridProps,
  type AttachmentsListProps,
  type AttachmentRenderer,
  type AttachmentRendererArgs,
  type AttachmentRendererMap,
  type EmptyStateProps,
  type ErrorBannerProps,
  type JumpToLatestProps,
  type StreamingIndicatorProps,
  type AudioToggleProps,
} from './components';

// Lazy preset
export { LazyChat } from './lazy';

// Markdown renderer (used internally by MessageBubble; re-exported so
// hosts can render chat-style markdown outside a bubble — e.g. previews,
// receipts, support emails).
export {
  MarkdownMessage,
  extractTextFromChildren,
  type MarkdownMessageProps,
  type LinkRule,
} from '../MarkdownMessage';
