import Bridge from "@/utils/jsBridge2"
import { Toast } from 'vant';
import { enableLive } from '@/service/StaffService/index'

export const sendLive = () => {
  const USER_MSG = window.localStorage.getItem('USER_MSG')
  if (!USER_MSG) {
    Toast('请先登录')
    return
  }
  let allow = false
  let time_section = ''
  // new Bridge().bridge_live({
  //   phone: JSON.parse(window.localStorage.getItem('USER_MSG') as string)?.userInfo.phone,
  //   avatar: window.location.host + require('../../../assets/icons/avatar.png'),
  //   allow: true,
  //   time_section: '30000'
  // })
  enableLive().then(res => {
    if (res.code === 200) {
      allow = res.data.allow
      time_section = res.data.time_section
    }
    new Bridge().bridge_live({
      phone: JSON.parse(window.localStorage.getItem('USER_MSG') as string)?.userInfo.phone,
      avatar: window.location.host + require('../assets/icons/avatar.png'),
      allow,
      time_section
    })
    console.log({
      phone: JSON.parse(window.localStorage.getItem('USER_MSG') as string)?.userInfo.phone,
      avatar: window.location.host + require('../assets/icons/avatar.png'),
      allow,
      time_section
    }, 'show live');
    
  }).catch(() => {
    new Bridge().bridge_live({
      phone: JSON.parse(window.localStorage.getItem('USER_MSG') as string)?.userInfo.phone,
      avatar: window.location.host + require('../assets/icons/avatar.png'),
      allow,
      time_section
    })
    console.log({
      phone: JSON.parse(window.localStorage.getItem('USER_MSG') as string)?.userInfo.phone,
      avatar: window.location.host + require('../assets/icons/avatar.png'),
      allow,
      time_section
    },'show live');
    
  })
}