export type ThemeContainerKey = 'appShell' | 'roomLayout' | 'dmLayout';

export interface ThemeMeta {
  name: string;
  version: string;
  description?: string;
}

export interface ThemeTokenGroups {
  colors: Record<string, string>;
  spacing: Record<string, string>;
  radii: Record<string, string>;
  effects: Record<string, string>;
}

export interface ThemeGridRect {
  x: number;
  y: number;
  w: number;
  h: number;
}

export interface ThemeLayoutEntry {
  container: ThemeContainerKey;
  grid: ThemeGridRect;
}

export interface ThemeElementStyles {
  width?: string;
  height?: string;
  minWidth?: string;
  minHeight?: string;
  maxWidth?: string;
  maxHeight?: string;
  position?: 'static' | 'relative' | 'absolute' | 'sticky';
  top?: string;
  right?: string;
  bottom?: string;
  left?: string;
  opacity?: number;
  padding?: string;
  margin?: string;
  border?: string;
  borderRadius?: string;
  backgroundColor?: string;
  color?: string;
  backgroundImage?: string;
  backgroundSize?: string;
  backgroundPosition?: string;
  backgroundRepeat?: string;
  gradient?: string;
  boxShadow?: string;
  backdropFilter?: string;
  icon?: string;
  textOverride?: string;
  link?: string;
  animationClass?: string;
}

export type ThemeElementStyleProperty = keyof ThemeElementStyles;

export interface ThemeAnimationDefinition {
  duration?: string;
  easing?: string;
  delay?: string;
  iterationCount?: string;
  fillMode?: 'none' | 'forwards' | 'backwards' | 'both';
  direction?: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
  keyframes?: Record<string, Record<string, string | number>>;
}

export interface ThemeDocument {
  css: string;
  meta: ThemeMeta;
  tokens: ThemeTokenGroups;
  layout: Record<string, ThemeLayoutEntry>;
  elements: Record<string, ThemeElementStyles>;
  animations: Record<string, ThemeAnimationDefinition>;
}

export interface ThemeLayoutContainerDefinition {
  key: ThemeContainerKey;
  label: string;
  description: string;
  columns: number;
  rows: number;
  templateColumns?: string;
  templateRows?: string;
}

export interface ThemeRegistryEntry {
  key: string;
  label: string;
  description: string;
  category: 'shell' | 'room' | 'overlay' | 'state';
  container?: ThemeContainerKey;
  layoutEditable: boolean;
  pickerVisible: boolean;
  supportsTextOverride: boolean;
  supportsLink: boolean;
  supportsIcon: boolean;
}

export interface SavedThemeSummary {
  description: string | null;
  error: string | null;
  fileName: string;
  filePath: string;
  isValid: boolean;
  modifiedAt: number;
  themeName: string;
  version: string | null;
}

export interface ThemeValidationResult {
  valid: boolean;
  errors: string[];
  value: ThemeDocument | null;
}

export interface ThemeGridEditorItem {
  key: string;
  label: string;
  description: string;
  grid: ThemeGridRect;
}

export interface ThemeSchemaField<T extends string = string> {
  key: T;
  description: string;
  type: 'string' | 'number' | 'object';
  example: string | number;
  examples: readonly (string | number)[];
}
