/**
 * Toast 适配层 - 替代微信小程序 @vant/weapp/toast
 * 将 Vant Toast 调用适配为 uni.showToast
 */

function Toast(options) {
  if (typeof options === 'string') {
    uni.showToast({
      title: options,
      icon: 'none',
      duration: 2000
    });
  } else if (typeof options === 'object') {
    uni.showToast({
      title: options.message || options.msg || '',
      icon: options.type === 'fail' ? 'error' : (options.type === 'success' ? 'success' : 'none'),
      duration: options.duration || 2000
    });
  }
}

Toast.success = function(options) {
  const title = typeof options === 'string' ? options : (options.message || '');
  uni.showToast({ title, icon: 'success', duration: 2000 });
};

Toast.fail = function(options) {
  const title = typeof options === 'string' ? options : (options.message || '');
  uni.showToast({ title, icon: 'error', duration: 2000 });
};

Toast.loading = function(options) {
  const title = typeof options === 'string' ? options : (options.message || '');
  uni.showLoading({ title });
};

Toast.clear = function() {
  uni.hideLoading();
};

export default Toast;
