/**
 * The WordPress components the app uses (the "wp-components" script, kept
 * external in vite.config.ts), with only the props that @wordpress/components
 * 19.8, the version WordPress 6.0 ships, accepts. Typing them here rather
 * than installing the package keeps newer props out of the code: anything
 * not listed fails the type check.
 *
 * `__nextHasNoMarginBottom` / `__next40pxDefaultSize` are the opt-ins newer
 * versions ask for (WordPress 6.7–7.0 log a deprecation without them). Older
 * ones don't know them: WordPress 6.0's TextControl passes them on to its
 * <input>, which only React's development build (SCRIPT_DEBUG) warns about.
 */
declare module '@wordpress/components' {
    import type {
        ChangeEvent,
        ComponentPropsWithoutRef,
        ComponentType,
        ForwardRefExoticComponent,
        ReactNode,
        RefAttributes,
    } from 'react';

    interface NextDefaults {
        __nextHasNoMarginBottom?: boolean;
        __next40pxDefaultSize?: boolean;
    }

    interface ControlBase {
        label?: ReactNode;
        hideLabelFromVision?: boolean;
        help?: ReactNode;
        className?: string;
    }

    export type ButtonProps = Omit<ComponentPropsWithoutRef<'button'>, 'type'> & {
        variant?: 'primary' | 'secondary' | 'tertiary' | 'link';
        isDestructive?: boolean;
        isSmall?: boolean;
        isBusy?: boolean;
        /** Renders a link instead of a button. */
        href?: string;
        target?: string;
        rel?: string;
        type?: 'button' | 'submit' | 'reset';
    } & NextDefaults;
    export const Button: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;

    type CardPartProps = ComponentPropsWithoutRef<'div'> & {
        size?: 'xSmall' | 'small' | 'medium' | 'large';
        isBorderless?: boolean;
    };
    export const Card: ComponentType<CardPartProps & { isRounded?: boolean }>;
    export const CardHeader: ComponentType<CardPartProps>;
    export const CardBody: ComponentType<CardPartProps>;

    export type TextControlProps = Omit<ComponentPropsWithoutRef<'input'>, 'onChange' | 'value' | 'className'> &
        ControlBase &
        NextDefaults & {
            value: string | number;
            onChange: ( value: string ) => void;
        };
    export const TextControl: ForwardRefExoticComponent<TextControlProps & RefAttributes<HTMLInputElement>>;

    export const TextareaControl: ComponentType<
        Omit<ComponentPropsWithoutRef<'textarea'>, 'onChange' | 'value' | 'className'> &
            ControlBase &
            NextDefaults & {
                value: string;
                onChange: ( value: string ) => void;
            }
    >;

    export const SelectControl: ComponentType<
        ControlBase &
            NextDefaults & {
                id?: string;
                value?: string;
                onChange: ( value: string ) => void;
                /** <option> and <optgroup> elements. */
                children?: ReactNode;
            }
    >;

    export const FormToggle: ComponentType<{
        id?: string;
        checked?: boolean;
        disabled?: boolean;
        className?: string;
        onChange: ( event: ChangeEvent<HTMLInputElement> ) => void;
    }>;

    export const CheckboxControl: ComponentType<
        ControlBase &
            NextDefaults & {
                id?: string;
                checked?: boolean;
                onChange: ( checked: boolean ) => void;
            }
    >;

    export const Modal: ComponentType<{
        title?: string;
        onRequestClose: () => void;
        focusOnMount?: boolean;
        shouldCloseOnEsc?: boolean;
        shouldCloseOnClickOutside?: boolean;
        isDismissible?: boolean;
        aria?: { labelledby?: string; describedby?: string };
        closeButtonLabel?: string;
        className?: string;
        overlayClassName?: string;
        contentLabel?: string;
        role?: string;
        __experimentalHideHeader?: boolean;
        children?: ReactNode;
    }>;

    export const Notice: ComponentType<{
        status?: 'success' | 'info' | 'warning' | 'error';
        isDismissible?: boolean;
        politeness?: 'polite' | 'assertive';
        /** Read out when shown; defaults to the content, '' for silence. */
        spokenMessage?: ReactNode;
        className?: string;
        children?: ReactNode;
    }>;
}
