import { useTunnelStore } from '@/store/modules/tunnel'

const tunnelStore = useTunnelStore()

const getCameras = (direction) => {

  const { cameras } = [tunnelStore.getUpTunnel, tunnelStore.getDownTunnel][direction]
  const arrs = JSON.parse(JSON.stringify(cameras))

  if (direction === 0) {
    arrs.reverse()
  }

  return JSON.parse(JSON.stringify(arrs))

}

// 获取道路摄像头
const getRoadCameras = (direction) => {

  const arrs = getCameras(direction)

  return arrs.map((item, x) => {
    return {
      ...item, 
      realx: x,
      hasNext: x < arrs.length - 1,
      hasPrev: x > 0
    }
  })

}

// 根据桩米号获取摄像头
const getComputedCamera = (direction, milestone) => {

  const arrs = getCameras(direction)

  return arrs.find(({ equipmentStation }) => {
    return direction ? equipmentStation > milestone : // 下行
      equipmentStation < milestone // 上行
  }) || null

}

export {
  getRoadCameras,
  getComputedCamera
}