function getAccessMode(accessMode) {
  if (typeof accessMode !== 'string') return accessMode;
  const oldMode = {
    none: { none: true },
    cert: { cert: true },
    login: { login: true },
    identity: { identity: true },
    realName: { realName: true },
    customer: { customer: true },
  };
  return oldMode[accessMode] || {};
}

function showButton(item, userInfo) {
  const { accessMode = '' } = item || {};
  const {
    phone,
    isLogin,
  } = userInfo || {};
  const {
    login,
    phoneNumber,
  } = getAccessMode(accessMode);
  /* 获取基础信息 */
  if (login && !isLogin) {
    return true;
  }
  /* 如果是获取手机号码 */
  if (phoneNumber && !phone) {
    return true;
  }
}

function getScope(item, userInfo) {
  const { accessMode = '' } = item || {};
  const {
    phone,
    isLogin,
  } = userInfo || {};
  const {
    login,
    phoneNumber,
  } = getAccessMode(accessMode);
  if (login && !isLogin) return 'userInfo';
  if (phoneNumber && !phone) return 'phoneNumber';
}

export default {
  getScope,
  showButton,
};
