// Minimal type declarations for vendored Preact — no npm required.

// Global JSX namespace — required for "jsx": "react" + jsxFactory: "h"
declare namespace JSX {
  type Element = import('preact').VNode;
  interface ElementClass { render(): import('preact').ComponentChild; }
  interface ElementAttributesProperty { props: {}; }
  interface ElementChildrenAttribute { children: {}; }
  type IntrinsicElements = {
    [K in keyof HTMLElementTagNameMap]: any;
  } & {
    [K in keyof SVGElementTagNameMap]: any;
  } & { [key: string]: any };
}

declare module 'preact' {
  export type Key = string | number;
  export type Ref<T> = { current: T | null };
  export type VNode<P = {}> = { type: any; props: P; key: Key | null };
  export type ComponentType<P = {}> = (props: P) => VNode | null;
  export type ComponentChild = VNode | string | number | boolean | null | undefined;
  export type ComponentChildren = ComponentChild | ComponentChild[];

  export interface Attributes {
    key?: Key;
    ref?: Ref<any>;
    children?: ComponentChildren;
  }

  export function h(type: any, props: any, ...children: any[]): VNode;
  export const Fragment: unique symbol;
  export function render(vnode: ComponentChild, parent: Element | ShadowRoot): void;
  export function cloneElement(vnode: VNode, props?: any, ...children: any[]): VNode;

  namespace JSX {
    type Element = VNode;
    interface ElementClass { render(): ComponentChild; }
    interface ElementAttributesProperty { props: {}; }
    interface ElementChildrenAttribute { children: {}; }
    // Allow any HTML/SVG attributes on intrinsic elements
    type IntrinsicElements = {
      [K in keyof HTMLElementTagNameMap]: any;
    } & {
      [K in keyof SVGElementTagNameMap]: any;
    } & { [key: string]: any };
  }
}

declare module 'preact/hooks' {
  import type { Ref, VNode } from 'preact';

  export type StateUpdater<S> = S | ((prevState: S) => S);
  export function useState<S>(initialState: S | (() => S)): [S, (update: StateUpdater<S>) => void];
  export function useReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S): [S, (action: A) => void];
  export function useEffect(effect: () => void | (() => void), inputs?: readonly any[]): void;
  export function useLayoutEffect(effect: () => void | (() => void), inputs?: readonly any[]): void;
  export function useRef<T>(initialValue: T): { current: T };
  export function useRef<T>(initialValue: T | null): Ref<T>;
  export function useMemo<T>(factory: () => T, inputs: readonly any[]): T;
  export function useCallback<T extends (...args: any[]) => any>(callback: T, inputs: readonly any[]): T;
  export function useContext<T>(context: import('preact').Context<T>): T;
}

declare module 'uplot' {
  namespace uPlot {
    type AlignedData = (number | null | undefined)[][];
    interface Series { label?: string; stroke?: string; width?: number; [k: string]: any; }
    interface Scale { min?: number; max?: number; time?: boolean; [k: string]: any; }
    interface Axis { stroke?: string; grid?: any; ticks?: any; [k: string]: any; }
    interface Options {
      width: number;
      height: number;
      series: Series[];
      legend?: { show?: boolean };
      axes?: Axis[];
      scales?: { [key: string]: Scale };
      [k: string]: any;
    }
  }
  class uPlot {
    constructor(opts: uPlot.Options, data: uPlot.AlignedData, target: HTMLElement);
    setData(data: uPlot.AlignedData): void;
    setSize(size: { width: number; height: number }): void;
    destroy(): void;
  }
  export default uPlot;
}

declare module 'echarts' {
  interface EChartsType {
    setOption(option: any, opts?: any): void;
    resize(): void;
    dispose(): void;
  }
  export function init(el: HTMLElement, theme?: string | null): EChartsType;
  export type { EChartsType };
}
