// Types of the WordPress script packages the editor scripts use. The build maps every `@wordpress/<name>` import to
// the global `wp.<name>` that WordPress itself loads, so the packages are never installed or bundled; these
// declarations cover only what this plugin calls.
declare module "@wordpress/element" {
  import type { ReactNode } from "react";

  export { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
  export function createRoot(container: Element): { render(node: ReactNode): void; unmount(): void };
}

declare module "@wordpress/components" {
  import type { ComponentType, ReactNode } from "react";

  export const Button: ComponentType<{
    variant?: "primary" | "secondary" | "tertiary" | "link";
    onClick?: () => void;
    disabled?: boolean;
    isBusy?: boolean;
    href?: string;
    target?: string;
    rel?: string;
    className?: string;
    accessibleWhenDisabled?: boolean;
    children?: ReactNode;
  }>;
  export const ToggleControl: ComponentType<{
    label: string;
    help?: string;
    checked: boolean;
    disabled?: boolean;
    onChange: (checked: boolean) => void;
    __nextHasNoMarginBottom?: boolean;
  }>;
  export const Spinner: ComponentType<Record<string, never>>;
  export const Notice: ComponentType<{ status?: "warning" | "success" | "error" | "info"; isDismissible?: boolean; children?: ReactNode }>;
  export const PanelBody: ComponentType<{ title?: string; initialOpen?: boolean; children?: ReactNode }>;
  export const ExternalLink: ComponentType<{ href: string; children?: ReactNode }>;
}

declare module "@wordpress/data" {
  export interface EditorSelectors {
    getCurrentPostId(): number;
    getEditedPostPreviewLink(): string | null;
    getPermalink(): string | null;
    isEditedPostDirty(): boolean;
    isEditedPostSaveable(): boolean;
    isSavingPost(): boolean;
    isAutosavingPost(): boolean;
    didPostSaveRequestSucceed(): boolean;
  }
  export interface EditorActions {
    autosave(options?: { isPreview?: boolean }): Promise<void>;
  }
  export function select(store: "core/editor"): EditorSelectors;
  export function dispatch(store: "core/editor"): EditorActions;
  export function subscribe(listener: () => void): () => void;
  export function useSelect<T>(mapSelect: (select: (store: "core/editor") => EditorSelectors) => T, deps?: readonly unknown[]): T;
}

declare module "@wordpress/api-fetch" {
  export interface APIFetchOptions {
    path: string;
    method?: "GET" | "POST" | "PUT" | "DELETE";
    data?: unknown;
    signal?: AbortSignal;
  }
  export default function apiFetch<T>(options: APIFetchOptions): Promise<T>;
}

declare module "@wordpress/i18n" {
  export function __(text: string, domain: string): string;
  export function _n(single: string, plural: string, count: number, domain: string): string;
  export function sprintf(format: string, ...args: (string | number)[]): string;
}

declare module "@wordpress/plugins" {
  import type { ComponentType, ReactElement } from "react";

  export function registerPlugin(name: string, settings: { render: ComponentType; icon?: string | ReactElement }): void;
}

declare module "@wordpress/editor" {
  import type { ComponentType, ReactNode } from "react";

  export const PluginSidebar: ComponentType<{ name: string; title: string; icon?: string | ReactNode; children?: ReactNode }>;
  export const PluginSidebarMoreMenuItem: ComponentType<{ target: string; icon?: string | ReactNode; children?: ReactNode }>;
}

declare module "@wordpress/dom-ready" {
  export default function domReady(callback: () => void): void;
}
