import type { MessageInstance } from 'antd/es/message/interface';

let messageApi: MessageInstance | undefined;

export function bindMessageApi(api: MessageInstance): void {
  messageApi = api;
}

function requireMessageApi(): MessageInstance {
  if (!messageApi) {
    throw new Error('Ant Design message API has not been initialized');
  }
  return messageApi;
}

export const message: Pick<MessageInstance, 'success' | 'error' | 'warning'> = {
  success: (...args) => requireMessageApi().success(...args),
  error: (...args) => requireMessageApi().error(...args),
  warning: (...args) => requireMessageApi().warning(...args),
};
