import { getDemoToken } from '@/api/user.api';
import localStorage from '@/service/localStorage.service';
import store from '../store';

/**
 * 安硕
 */
export async function shouDemo(next = () => {}) {
  const demoPhone = localStorage.get('demoPhone') || '';
  const vccChannel = localStorage.get('vccChannel') || '';
  if (!demoPhone) return;
  try {
    const [{ token }] = await getDemoToken({ phoneNo: String(demoPhone), vccChannel });
    store.commit('CHANGE_TOKEN', token);
    next();
  } catch (error) {
    console.log('DEBUG: shouDemo getToken =>', error);
    next();
  }
}
