const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const pusherStatusToast = e => {
  var msg = "";
  switch (e.detail.code) {
    case -1301:
      msg = "打开摄像头失败";
      break;
    case -1302:
      msg = "打开麦克风失败";
      break;
    case -1303:
      msg = "视频编码失败";
      break;
    case -1304:
      msg = "音频编码失败";
      break;
    case -1305:
      msg = "不支持的视频分辨率";
      break;
    case -1306:
      msg = "不支持的音频采样率";
      break;
    case -1312:
      msg = "录屏动态切横竖屏失败";
      break;
    case 1104:
      msg = "视频编码失败";
      break;
  }

  switch (e.detail.errCode) {
    case 10001:
      msg = "请开启摄像头权限";
      break;
    case 10002:
      msg = "请开启麦克风权限";
      break;
  }

  if (msg && msg.length > 0) {
    wx.showToast({
      title: msg,
      icon: 'none'
    });
  }

}

const shareData = () => {
  return {
    title: '视频会议从未如此简单',
    path: '/pages/index/index',
    imageUrl: '/resource/share.png'
  }
}

module.exports = {
  formatTime: formatTime,
  pusherStatusToast: pusherStatusToast,
  shareData: shareData
}
