export type ColumnType =
  | "text"
  | "number"
  | "currency"
  | "date"
  | "select"
  | "checkbox"
  | "formula"
  | "reference";

export interface TableColumn {
  id: string; // Unique column ID
  name: string; // Column display name
  type: ColumnType;
  width: number; // Column width for display
  options?: { value: string; color: string }[]; // For 'select' type
}

export interface TableSchema {
  columns: TableColumn[];
  frozenRowCount: number; // 冻结行数
  frozenColCount: number; // 冻结列数
  // 其他视图偏好设置...
}

export type TableRowData = Record<string, string | number | boolean | null | undefined>;

export interface DocumentTableSnapshot {
  rows?: TableRowData[];
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  luckysheet?: any;
}

// 对应 Supabase document_tables 表的元数据
export interface DocumentTable {
  id: string;
  document_id: string;
  grid_key: string;
  title: string;
  schema: TableSchema;
  snapshot?: DocumentTableSnapshot | null;
  created_at: string;
  updated_at: string;
}

// Blocknote 块的数据结构
export interface OnlineTableBlockProps {
  tableId: string;
  title: string; // 允许 Blocknote 渲染时显示表格名称
}

// Global declarations for Luckysheet (minimal definition)
declare global {
  interface Window {
    luckysheet?: {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      create?: (options: any) => void;
      destroy?: (id: string) => void;
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      getluckysheetfile?: () => any;
      enterEditMode?: () => void;
      getluckysheet_select_save?: () => unknown;
      // 实际功能会通过动态加载的脚本注入
      // 最小化声明以通过 TypeScript 检查（必须允许 undefined）
    };
  }
}
