import { listenerMessage, postMessage, removeListenerMessage } from '/src/helpers/native-message'
import runtime, { setCurrentTime } from '/src/pages/detail/runtime'
import detailState from '/src/pages/detail/state'
export const initFollow = () => {
  console.log(runtime, detailState)
  let index = 0
  setInterval(() => {
    const item = detailState.times[index]
    console.log(item)
    index++
    setCurrentTime(item.time)
  }, 3000)
}

export const toggleFollow = () => {
  postMessage(
    {
      api: 'cloudToggleFollow',
      content: {
        // 状态
        state: 'start',
      },
    },
    (res) => {
      console.log(res)
    }
  )
}

export const onChangeFollowTime = (res: any) => {
    console.log(res)
}

export const toggleListener = (type: boolean) => {
  if (type) {
    // 触发
    listenerMessage('cloudFollowTime', onChangeFollowTime)
  } else {
    removeListenerMessage('cloudFollowTime', onChangeFollowTime)
  }
}
