/**
 * Widget and layout type definitions for HUD system
 */

import type { BaseEntity } from "./index";

/**
 * Widget placement in the grid
 */
export interface WidgetPlacement {
  i: string; // Widget ID
  x: number; // Column position
  y: number; // Row position
  w: number; // Width in grid units
  h: number; // Height in grid units
  minW?: number;
  maxW?: number;
  minH?: number;
  maxH?: number;
  static?: boolean;
  isDraggable?: boolean;
  isResizable?: boolean;
}

/**
 * Widget definition from database
 */
export interface WidgetDefinition extends BaseEntity {
  name: string;
  displayName: string;
  description: string | null;
  component: string;
  defaultWidth: number;
  defaultHeight: number;
  minWidth: number;
  minHeight: number;
  maxWidth: number | null;
  maxHeight: number | null;
  configSchema: Record<string, unknown>;
  isActive: boolean;
}

/**
 * User layout configuration
 */
export interface UserLayout extends BaseEntity {
  workspaceId: string;
  userId: string;
  name: string;
  isDefault: boolean;
  layout: WidgetPlacement[];
  metadata: Record<string, unknown>;
}

/**
 * Layout configuration for editor
 */
export interface LayoutConfig {
  id: string;
  name: string;
  layout: WidgetPlacement[];
}

/**
 * Available widget types (component names)
 */
export type WidgetComponentType =
  | "TasksWidget"
  | "CalendarWidget"
  | "QuickCaptureWidget"
  | "AgentStatusWidget"
  | "ActiveProjectsWidget"
  | "TaskProgressWidget"
  | "StatCardWidget"
  | "ChartWidget"
  | "ListWidget"
  | "CalendarPreviewWidget";

/**
 * Props for individual widgets
 */
export interface WidgetProps {
  id: string;
  config?: Record<string, unknown>;
  onEdit?: () => void;
  onRemove?: () => void;
}

/**
 * Widget configuration types
 */
export interface StatCardConfig {
  title?: string;
  dataSource: "tasks" | "events" | "projects";
  metric: "count" | "completed" | "overdue" | "upcoming";
  filter?: Record<string, unknown>;
  color?: string;
  icon?: string;
}

export interface ChartConfig {
  title?: string;
  chartType: "bar" | "line" | "pie" | "donut";
  dataSource: "tasks" | "events" | "projects";
  groupBy: "status" | "priority" | "project" | "day" | "week" | "month";
  filter?: Record<string, unknown>;
  colors?: string[];
}

export interface ListConfig {
  title?: string;
  dataSource: "tasks" | "events" | "projects";
  sortBy?: string;
  sortOrder?: "asc" | "desc";
  limit?: number;
  filter?: Record<string, unknown>;
  showStatus?: boolean;
  showDueDate?: boolean;
}

export interface CalendarPreviewConfig {
  title?: string;
  view: "day" | "week" | "agenda";
  showTasks?: boolean;
  showEvents?: boolean;
  daysAhead?: number;
}

/**
 * Widget data response types
 */
export interface WidgetStatData {
  value: number;
  change?: number;
  changePercent?: number;
  previousValue?: number;
}

export interface WidgetChartData {
  labels: string[];
  datasets: {
    label: string;
    data: number[];
    backgroundColor?: string[];
  }[];
}

export interface WidgetListItem {
  id: string;
  title: string;
  subtitle?: string;
  status?: string;
  priority?: string;
  dueDate?: string;
  startTime?: string;
  color?: string;
}

export interface WidgetCalendarItem {
  id: string;
  title: string;
  startTime: string;
  endTime?: string;
  allDay?: boolean;
  type: "task" | "event";
  color?: string;
}
