export interface UserMetaField {
  id: string
  type: string
  label?: string
  key?: string
  latKey?: string
  lngKey?: string
  startKey?: string
  endKey?: string
  allDayKey?: string
  presets?: string[]
  options?: string[]
  min?: number
  max?: number
  step?: number
  unit?: string
  default?: boolean
}

export interface PageMeta extends Record<string, unknown> {
  // Universal display
  color?: string
  icon?: string
  subtitle?: string
  note?: string

  // Datetime
  datetimeStart?: string
  datetimeEnd?: string
  allDay?: boolean
  dateStart?: string
  dateEnd?: string
  timeStart?: string
  timeEnd?: string
  dateTaken?: string

  // Task/status
  checked?: boolean
  priority?: number
  status?: string
  taskProgress?: number
  rating?: number
  tags?: string[]
  members?: { id: string; label: string }[]

  // Contact/value
  url?: string
  email?: string
  phone?: string
  number?: number
  unit?: string

  // Cover image
  coverUploadId?: string
  coverDocId?: string
  coverMimeType?: string

  // Geo/Map
  geoType?: 'marker' | 'line' | 'measure'
  geoLat?: number
  geoLng?: number
  geoDescription?: string

  // Dashboard
  deskX?: number
  deskY?: number
  deskZ?: number
  deskMode?: string

  // Mindmap
  mmX?: number
  mmY?: number

  // Graph
  graphX?: number
  graphY?: number
  graphPinned?: boolean

  // Spatial (3D) — spatial uses the universal `color` key (no spColor)
  spShape?: string
  spOpacity?: number
  spX?: number
  spY?: number
  spZ?: number
  spRX?: number
  spRY?: number
  spRZ?: number
  spSX?: number
  spSY?: number
  spSZ?: number
  spModelUploadId?: string
  spModelDocId?: string

  // Slides
  slidesTransition?: string
  slidesTheme?: string

  // Media metadata (extracted on import)
  mediaDuration?: number
  mediaWidth?: number
  mediaHeight?: number
  mediaCamera?: string
  mediaLens?: string
  mediaIso?: number
  mediaFocalLength?: number
  mediaAperture?: number
  mediaShutterSpeed?: string
  mediaArtist?: string
  mediaAlbum?: string
  mediaGenre?: string
  mediaYear?: number

  // Sheets cell formatting
  bold?: boolean
  italic?: boolean
  textColor?: string
  bgColor?: string
  align?: string
  formula?: string

  // Coder plugin (per-file)
  fileType?: string
  entry?: boolean

  // Renderer config (set on the page doc itself, not children)
  kanbanColumnWidth?: string
  galleryColumns?: number
  galleryAspect?: string
  galleryCardStyle?: string
  galleryShowLabels?: boolean
  gallerySortBy?: string
  calendarView?: string
  calendarWeekStart?: string
  calendarShowWeekNumbers?: boolean
  tableMode?: string
  tableSortKey?: string
  tableSortDir?: string
  tableColumns?: any[]
  tableColumnWidths?: Record<string, number>
  tableColumnOrder?: string[]
  timelineZoom?: string
  timelinePixelsPerDay?: number
  timelineCenterDate?: string
  checklistFilter?: string
  checklistSort?: string
  mapShowLabels?: boolean
  spatialGridVisible?: boolean
  graphSpacing?: string
  graphShowLabels?: boolean
  graphEdgeThickness?: string
  mmSpacing?: string
  showRefEdges?: boolean
  chartType?: string
  chartMetric?: string
  chartColorScheme?: string
  chartLimit?: number
  chartShowLegend?: boolean
  chartShowValues?: boolean
  mediaRepeat?: string
  mediaShuffle?: boolean
  sheetsDefaultColWidth?: number
  sheetsDefaultRowHeight?: number
  sheetsShowGridlines?: boolean
  sheetsColumnWidths?: Record<string, number>
  sheetsRowHeights?: Record<string, number>
  sheetsFreezeRows?: number
  sheetsFreezeCols?: number

  // Internal
  _metaFields?: UserMetaField[]
  _metaInitialized?: boolean
}

export interface TreeEntry {
  id: string
  label: string
  parentId: string | null
  order: number
  type?: string
  meta?: PageMeta
  createdAt?: number
  updatedAt?: number
}
