// Type definitions for vendor libraries

declare module "../vendor/topbar" {
  interface Topbar {
    config(options: { barColors: { [key: number]: string }; shadowColor: string }): void;
    show(delay?: number): void;
    hide(): void;
  }
  const topbar: Topbar;
  export default topbar;
}

declare module "../vendor/chart" {
  export interface ChartDataPoint {
    x: number;
    y: number | null;
  }

  export interface ChartDataset {
    label: string;
    data: ChartDataPoint[];
    borderColor?: string;
    backgroundColor?: string;
    borderWidth?: number;
    tension?: number;
    pointRadius?: number;
    pointHoverRadius?: number;
  }

  export interface ChartData {
    datasets: ChartDataset[];
  }

  export interface ChartTickContext {
    tick: { value: number };
  }

  export interface ChartAxisConfig {
    type?: string;
    min?: number;
    max?: number;
    beginAtZero?: boolean;
    ticks?: {
      callback?: (value: number, index?: number) => string;
      maxTicksLimit?: number;
    };
    grid?: {
      display?: boolean;
      color?: string | ((context: ChartTickContext) => string);
      lineWidth?: number | ((context: ChartTickContext) => number);
    };
  }

  export interface ChartTooltipContext {
    parsed: { x: number; y: number };
    dataset: ChartDataset;
  }

  export interface ChartOptions {
    responsive?: boolean;
    maintainAspectRatio?: boolean;
    barPercentage?: number;
    categoryPercentage?: number;
    interaction?: {
      mode?: string;
      intersect?: boolean;
    };
    plugins?: {
      legend?: {
        position?: string;
        labels?: {
          usePointStyle?: boolean;
          padding?: number;
        };
      };
      tooltip?: {
        callbacks?: {
          title?: (context: ChartTooltipContext[]) => string;
          label?: (context: ChartTooltipContext) => string;
        };
      };
    };
    scales?: {
      x?: ChartAxisConfig;
      y?: ChartAxisConfig;
    };
  }

  export interface ChartConfig {
    type: string;
    data: ChartData;
    options: ChartOptions;
  }

  export default class Chart {
    constructor(context: CanvasRenderingContext2D, config: ChartConfig);
    destroy(): void;
  }
}

declare module "phoenix" {
  export class Socket {
    constructor(endpoint: string, options?: any);
    connect(): void;
    enableDebug(): void;
    enableLatencySim(ms: number): void;
    disableLatencySim(): void;
  }
}

declare module "phoenix_live_view" {
  import { Socket } from "phoenix";

  export interface LiveSocket {
    connect(): void;
    enableDebug(): void;
    enableLatencySim(ms: number): void;
    disableLatencySim(): void;
  }

  export class LiveSocket {
    constructor(
      endpoint: string,
      Socket: typeof Socket,
      options: {
        longPollFallbackMs?: number;
        params?: { _csrf_token: string };
        hooks?: Record<string, any>;
      }
    );
  }
}

declare module "phoenix-colocated/towerops" {
  export const hooks: Record<string, any>;
}
