import { isNotH5 } from '../utils/env';

// #ifndef H5
import { Toast as ToastMp } from './toast-mp';
// #endif

// #ifdef H5
import { Toast as ToastWeb } from './toast-web';
// #endif

import type { IToast } from './types';


/**
 * 轻提示
 * @example
 * ```
 * // 显示内容
 * Toast.show('powered by guowangyang');
 *
 * // 第二个参数为 duration，可选，默认 2000
 * Toast.show('powered by guowangyang', 1000);
 *
 * // 也可以传入对象
 * Toast.show({
 *   // 或者传递 text
 *   message: 'powered by guowangyang',
 *   zIndex: 100, // 默认 10000
 *   duration: 1000, // 默认 2000
 *   forbidClick: true,
 * })
 *
 * // 成功
 * Toast.showSuccess('success');
 * Toast.success('success');
 *
 * // 失败
 * Toast.showFail('fail');
 * Toast.fail('fail');
 *
 * // 清除 Toast
 * Toast.clear();
 *
 * // 加载中
 * Toast.loading('loading...');
 * Toast.showLoading('loading...');
 *
 * // 清除加载中
 * Toast.dismissLoading();
 *
 * // 小程序下默认使用小程序原生组件
 * // 可设置 customUI 为 true，则使用 Press UI
 * // 注意，如果使用 Press UI，需要注意提前预埋
 * // 参考：https://novlan1.github.io/docs/press-ui/components/press/press-toast.html
 * Toast.useCustomUI(true);
 *
 * // 也可以使用其他组件库
 * Toast.setComponent( () => [import('xxx')]);
 * ```
 */
let Toast: IToast;


// #ifdef H5
Toast = ToastWeb;
// #endif

// #ifndef H5
if (isNotH5()) {
  Toast = ToastMp;
}
// #endif

export {
  Toast,
};
