import i18n from "@/i18n";
export const msg = (title) => {
    uni.showToast({
        title,
        icon: 'none'
    })
}
export const copy = (data) => {
    uni.setClipboardData({
        data,
        success(){
            msg("复制成功")
        },
        fail(){
            msg("复制失败")
        }
    })
}

export const alert = (content, title = '提示') => {
  return new Promise((resolve) => {
    uni.showModal({
      title,
      content,
      confirmText: i18n.t('确定'),
      showCancel: false,
      success:(res) => {
        resolve(res)
      }
    })
  })
}


export const confirm = (content, title = '提示') => {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title,
      content,
      showCancel: true,
      confirmText: i18n.t('确定'),
      cancelText: i18n.t('取消'),
      success:(res) => {
        if(res.confirm){
          resolve(res)
        }else{
          reject(res)
        }
      }
    })
  })
}

export const prompt = (content, title, placeholderText) => {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title,
      // content必须是字符串，否则可能会弹不出来
      content: content.toString(),
      showCancel: true,
      editable: true,
      placeholderText,
      confirmText: i18n.t('确定'),
      cancelText: i18n.t('取消'),
      success:(res) => {
        if(res.confirm){
          resolve(res)
        }else{
          reject(res)
        }
      }
    })
  })
}
