import type { ReactNode, ComponentProps } from 'react';

import type { Button } from '../button';

export type DialogFuncProps = {
  afterClose?: () => void;
  /**
   * Text that should be displayed in the cancel button
   */
  cancelText?: ReactNode;
  className?: string;
  closable?: boolean;
  content?: ReactNode;
  description?: ReactNode;
  /**
   * Flag that controls if the cancel button should be included in the dialog or not
   */
  displayCancel?: boolean;
  /**
   * Flag that controls if the ok button should be included in the dialog or not
   */
  displayOk?: boolean;
  /**
   * @deprecated - Use displayCancel instead
   *
   * Flag that controls if the cancel button should be included in the dialog or not
   */
  okCancel?: boolean;
  /**
   * Text that should be displayed in the ok button
   */
  okText?: ReactNode;
  okButtonIntent?: ComponentProps<typeof Button>['intent'];
  /**
   * The callback that will be called once the user click the cancel button
   * @param args
   * @returns void
   */
  onCancel?: (...args: unknown[]) => void;
  onEscapeKeyDown?: (event: Event) => void;
  onInteractOutside?: (event: Event) => void;
  /**
   * The callback that will be called once the user click the ok button
   * @param args
   * @returns void
   */
  onOk?: (...args: unknown[]) => void;
  onPointerDownOutside?: (event: Event) => void;
  open?: boolean;
  prefixCls?: string;
  title?: ReactNode;
  type?: 'info' | 'error' | 'warning';
};

export type ConfigUpdate = DialogFuncProps | ((prevConfig: DialogFuncProps) => DialogFuncProps);

export type DialogFunc = (props: DialogFuncProps) => {
  destroy: () => void;
  update: (configUpdate: ConfigUpdate) => void;
};

export type ModalStaticFunctions = Record<NonNullable<DialogFuncProps['type']>, DialogFunc>;

export interface ConfirmDialogProps extends DialogFuncProps {
  close: (...args: unknown[]) => void;
  autoFocusButton?: null | 'ok' | 'cancel';
  rootPrefixCls: string;
  iconPrefixCls?: string;
}
