import { ReactNode } from 'react'

// Widget tipleri
export type WidgetType = 
  | 'metric'
  | 'chart'
  | 'table'
  | 'map'
  | 'activity'
  | 'calendar'
  | 'progress'
  | 'comparison'

// Widget boyutları
export interface WidgetSize {
  w: number // Grid genişliği
  h: number // Grid yüksekliği
  minW?: number
  maxW?: number
  minH?: number
  maxH?: number
}

// Widget pozisyonu
export interface WidgetPosition {
  x: number
  y: number
}

// Tema tipleri
export type DashboardTheme = 'analytics' | 'sales' | 'monitoring' | 'finance' | 'custom'

// Zaman aralığı
export interface TimeRange {
  start: Date
  end: Date
  label: string
  preset?: 'today' | 'yesterday' | 'last7days' | 'last30days' | 'thisMonth' | 'lastMonth' | 'custom'
}

// Metric widget
export interface MetricData {
  id: string
  title: string
  value: string | number
  change?: {
    value: number
    type: 'increase' | 'decrease' | 'neutral'
    period: string
  }
  icon?: ReactNode
  color?: 'primary' | 'success' | 'warning' | 'danger' | 'info'
  sparkline?: number[]
  forecast?: number
  target?: number
  unit?: string
}

// Chart widget
export interface ChartData {
  type: 'line' | 'bar' | 'area' | 'pie' | 'donut' | 'radar'
  data: any
  options?: any
}

// Table widget
export interface TableData {
  columns: Array<{
    id: string
    header: string
    accessor: string
    sortable?: boolean
    filterable?: boolean
  }>
  data: any[]
  pagination?: boolean
  pageSize?: number
}

// Activity widget
export interface ActivityItem {
  id: string
  type: 'info' | 'success' | 'warning' | 'error'
  title: string
  description?: string
  timestamp: Date
  user?: {
    name: string
    avatar?: string
  }
  icon?: ReactNode
}

// Progress widget
export interface ProgressData {
  id: string
  title: string
  current: number
  target: number
  unit?: string
  color?: 'primary' | 'success' | 'warning' | 'danger'
  deadline?: Date
}

// Comparison widget
export interface ComparisonData {
  periods: Array<{
    label: string
    value: number
    data?: any[]
  }>
  metric: string
  unit?: string
  showChart?: boolean
}

// Widget base interface
export interface Widget {
  id: string
  type: WidgetType
  title: string
  description?: string
  size?: WidgetSize
  position?: WidgetPosition
  data?: any
  config?: any
  loading?: boolean
  error?: string
  refreshInterval?: number // ms
  lastUpdated?: Date
  permissions?: {
    canEdit?: boolean
    canDelete?: boolean
    canResize?: boolean
    canMove?: boolean
  }
}

// Dashboard configuration
export interface DashboardConfig {
  id: string
  name: string
  description?: string
  theme: DashboardTheme
  layout: {
    rowHeight: number
    margin: [number, number]
    containerPadding: [number, number]
    breakpoints: {
      lg: number
      md: number
      sm: number
      xs: number
      xxs: number
    }
    cols: {
      lg: number
      md: number
      sm: number
      xs: number
      xxs: number
    }
  }
  widgets: Widget[]
  filters?: {
    timeRange?: TimeRange
    dimensions?: Record<string, any>
  }
  createdAt: Date
  updatedAt: Date
  createdBy?: string
  shared?: boolean
  tags?: string[]
}

// Dashboard template
export interface DashboardTemplate {
  id: string
  name: string
  description: string
  thumbnail?: string
  category: 'analytics' | 'sales' | 'operations' | 'finance' | 'marketing' | 'custom'
  widgets: Omit<Widget, 'id'>[]
  theme: DashboardTheme
  popularity?: number
  isPro?: boolean
}

// WebSocket message
export interface DashboardUpdate {
  type: 'widget-update' | 'notification' | 'alert' | 'refresh'
  widgetId?: string
  data?: any
  timestamp: Date
}

// Export format
export type ExportFormat = 'json' | 'csv' | 'pdf' | 'png'

// Filter types
export interface DashboardFilter {
  id: string
  type: 'select' | 'multiselect' | 'daterange' | 'search' | 'toggle'
  label: string
  field: string
  options?: Array<{ value: any; label: string }>
  defaultValue?: any
}

// Notification
export interface DashboardNotification {
  id: string
  type: 'info' | 'success' | 'warning' | 'error'
  title: string
  message?: string
  timestamp: Date
  read?: boolean
  action?: {
    label: string
    handler: () => void
  }
}