/**
 * Top-level chat configuration — placeholder, suggestions, identities, prefs.
 */

import type { ChatAssistantContext, ChatUserContext } from './persona';
import type { ChatLabels } from './labels';
import type { ResolveLinkPreview } from '../../../common/link-preview';

export type ChatDisplayMode = 'closed' | 'embedded' | 'floating' | 'sidebar' | 'fullscreen';

export interface ChatPrefs {
  /** Submit hotkey for the composer. */
  submitOn?: 'enter' | 'cmd+enter';
  /** UI density. */
  density?: 'comfortable' | 'compact';
  /** Locale forwarded to transport metadata. */
  locale?: string;
  /** Show timestamps on each bubble. */
  showTimestamps?: boolean;
}

export interface ChatConfig {
  /** Window title / aria-label. */
  title?: string;
  /** Composer placeholder. */
  placeholder?: string;
  /** Empty-state greeting. */
  greeting?: string;
  /** Empty-state description. */
  description?: string;
  /** Suggested prompts shown on empty conversation. */
  suggestions?: Array<{ label: string; prompt: string }>;
  /** Project / chat slug forwarded to the transport. */
  slug?: string;
  /** Identity of the human author. Renders avatar / name on user bubbles
   *  and gets stamped on outgoing messages as `message.sender`. */
  user?: ChatUserContext;
  /** Identity of the assistant. Renders avatar / name on assistant bubbles. */
  assistant?: ChatAssistantContext;
  /** UI preferences. */
  prefs?: ChatPrefs;
  /** Visual labels (i18n is the host's job). */
  labels?: Partial<ChatLabels>;
  /** Link-preview (URL unfurl) wiring — the host owns metadata fetching. */
  linkPreview?: ChatLinkPreviewConfig;
  /**
   * Render bare web URLs inside message bubbles as compact "URL chips"
   * (favicon + domain + middle-ellipsis path, e.g.
   * `github.com/wailsapp/…/README.md`) instead of a plain blue link —
   * matching the composer's URL chip. Only bare `http(s)` autolinks are
   * chipped; a `[labeled](url)` link keeps its author-chosen text as a
   * normal link.
   *
   * Off by default (the host opts in). When on, the chip rule is appended
   * AFTER any host-supplied `linkRules`, so host-specific rules win.
   * @default false
   */
  linkChips?: boolean;
}

export interface ChatLinkPreviewConfig {
  /**
   * Host resolver that turns a URL into preview metadata. Required for any
   * link card to appear (the browser cannot fetch meta tags cross-origin).
   * In Wails/Go this wraps a bound `FetchLinkMetadata` method; on the web,
   * a `/api/unfurl` route.
   */
  resolve?: ResolveLinkPreview;
  /**
   * Auto-render a preview card under a message bubble when its text
   * contains a link (Telegram-style — at most ONE card per message).
   * Off by default; needs `resolve` to be set.
   * @default false
   */
  autoDetect?: boolean;
}
