import { NOTIFICATION_TYPES } from '@/appConfig';
import { notification } from 'antd';
import { throttle } from 'lodash-es';

/**
 * 全局通知提醒框
 * @param {String} title
 * @param {String} des
 * @param {String} type
 */
const showNotification = throttle(
  (
    type: 'success' | 'info' | 'warning' | 'error',
    title = NOTIFICATION_TYPES[type],
    des = '...',
    duration = 2,
  ) => {
    notification[type]({
      message: title,
      description: des,
      duration,
    });
  },
  1000,
  { leading: true, trailing: false },
);

/**
 * 生成uuid
 * @returns
 */
const getUuid = () => {
  return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    let r = (Math.random() * 16) | 0,
      v = c === 'x' ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
};

export { getUuid, showNotification };
