import Taro from '@tarojs/taro';

import { sleep } from '@/utils/common';

const Toast = {
  info: async (title: string, duration: number = 1500, wait: boolean = false) => {
    Taro.showToast({ title, icon: 'none', duration });
    wait && (await sleep(duration / 1000));
  },
  success: async (title: string, duration: number = 1500, wait: boolean = false) => {
    Taro.showToast({ title, icon: 'success', duration });
    wait && (await sleep(duration / 1000));
  },
  error: async (title: string, duration: number = 1500, wait: boolean = false) => {
    Taro.showToast({ title, icon: 'error', duration });
    wait && (await sleep(duration / 1000));
  },
  loading: async (title: string, duration: number = 1500, wait: boolean = false) => {
    Taro.showToast({ title, icon: 'loading', duration });
    wait && (await sleep(duration / 1000));
  },
};

export default Toast;
