/**
 * @description 全局提示，包括dialog和notify
 */
import { showConfirmDialog, DialogOptions, closeDialog } from "vant";
import WlNotice from "@mobileUI/components/WlNotice/index";
const useMessage = () => {
  const duration = 3000;
  const onNotify = (message: string) => {
    WlNotice({ message, type: "success", duration });
  };
  const onError = (message: string) => {
    WlNotice({ message, type: "error", duration });
  };
  const onWarning = (message: string) => {
    WlNotice({ message, type: "warning", duration });
  };

  const onConfirm = (params: DialogOptions) => {
    return new Promise((resolve, reject) => {
      const filter_params = {
        className: "vant-confirm-z-index",
        overlayClass: "vant-overlay-z-index",
        ...params,
      };
      showConfirmDialog(filter_params).then(resolve, reject);
    });
  };
  const onConfirmCancel = () => {
    closeDialog();
  };
  return {
    onNotify,
    onError,
    onConfirm,
    onWarning,
    onConfirmCancel,
  };
};
export default useMessage;
