declare module "w2ui" {
  type W2EventHandler = (event: unknown) => void;
  type W2EventHost = {
    on(eventName: string, handler: W2EventHandler): W2EventHost;
  };

  export const w2popup: {
    open(options: {
      title?: string;
      width?: number;
      height?: number;
      modal?: boolean;
      body?: string;
      actions?: Record<string, () => void | Promise<void>>;
    }): {
      self: W2EventHost;
    };
    close(): void;
  };

  export class w2layout {
    constructor(options: {
      name: string;
      padding?: number;
      panels: Array<{
        type: "left" | "right" | "top" | "bottom" | "main" | "preview";
        size?: number | string;
        minSize?: number;
        maxSize?: number | false;
        resizable?: boolean;
        overflow?: string;
        html?: string;
      }>;
    });
    render(target: HTMLElement): void;
    destroy(): void;
  }

  export const w2ui: Record<string, { destroy?: () => void } | undefined>;

  export function w2alert(message: string, title?: string): unknown;
  export function w2confirm(
    message: string | { msg: string; title?: string; yes?: string; no?: string },
    title?: string,
    callback?: (action: string) => void
  ): unknown;
}
