import { notification } from 'antd';
import { ArgsProps, NotificationInstance } from 'antd/lib/notification';
import { NOTIFICATION_DEBOUNCE } from 'core/constants/debounce';

const defaultOptions: Partial<ArgsProps> = {
  placement: 'bottomRight',
};

type NotificationOptions = ArgsProps & {
  type: keyof NotificationInstance;
};

export const openNotification = (options: NotificationOptions) => {
  setTimeout(() => {
    if (!options.key) options.key = JSON.stringify(options);
    notification[options.type]({ ...defaultOptions, ...options });
  }, NOTIFICATION_DEBOUNCE);
};
