export interface TextState {
  showing: boolean;
  title: string;
}

export interface SettingsState {
  /** Portrait background image URL (height > width). Empty string = no background. */
  background_url: string;
}

export interface ImagePopupState {
  showing: boolean;
  image_url: string;
  caption: string;
}

/** Grid layout: 1-based col/row, 4-column × 4-row grid */
export interface CardLayout {
  grid_col: number; // 1–4
  grid_row: number; // 1–4
  col_span: number; // 1–4
  row_span: number; // 1–4
}

// ─── custom_json ───────────────────────────────────────────────────────────────

export interface DisplayOptions {
  font_size: number;
  text_color: string;
}

export interface DataCardConfig {
  url: string;
  refresh_interval: number;
  display_options: DisplayOptions;
  take?: string;
  additional_headers?: Record<string, string>;
}

export interface CustomJsonCard {
  id: string;
  type: "custom_json";
  name: string;
  config: DataCardConfig;
  layout?: CardLayout;
}

// ─── static_text ──────────────────────────────────────────────────────────────

export interface StaticTextConfig {
  text: string;
  font_size: number;
  text_color: string;
}

export interface StaticTextCard {
  id: string;
  type: "static_text";
  name: string;
  config: StaticTextConfig;
  layout?: CardLayout;
}

// ─── clock ────────────────────────────────────────────────────────────────────

export interface ClockConfig {
  /** "time" = live clock, "timer" = countdown to target_iso */
  mode: "time" | "timer";
  /** IANA timezone string, e.g. "Europe/Berlin" */
  timezone?: string;
  /** ISO-8601 target datetime for mode="timer", e.g. "2026-12-31T23:59:59" */
  target_iso?: string;
  font_size: number;
  text_color: string;
  show_seconds?: boolean;
}

export interface ClockCard {
  id: string;
  type: "clock";
  name: string;
  config: ClockConfig;
  layout?: CardLayout;
}

// ─── image_rotator ────────────────────────────────────────────────────────────

export interface ImageRotatorConfig {
  /** List of public image URLs to cycle through */
  images: string[];
  /** Seconds between transitions */
  interval: number;
  fit: "cover" | "contain";
}

export interface ImageRotatorCard {
  id: string;
  type: "image_rotator";
  name: string;
  config: ImageRotatorConfig;
  layout?: CardLayout;
}

// ─── Union ────────────────────────────────────────────────────────────────────

export type DataCard = CustomJsonCard | StaticTextCard | ClockCard | ImageRotatorCard;
