import axios from "axios"
import mockData from "../input-data/data3.js";

let AJAX_ORIGIN = ''
switch (process.env.NODE_ENV) {
  case 'development':
    AJAX_ORIGIN = 'https://uat-laser.4dkankan.com/'
    break;
  case 'production':
    AJAX_ORIGIN = 'https://uat-laser.4dkankan.com/'
    // AJAX_ORIGIN = 'https://laser.4dkankan.com/backend/'

    break;
  default:
    AJAX_ORIGIN = ''
    break;
}

export function getWholeData(sceneNameOrUrl) {
  // if (process.env.NODE_ENV === 'development') {
  //   return Promise.resolve(mockData.data)
  // }

  let url = sceneNameOrUrl.startsWith('http') ?
    sceneNameOrUrl :
    `${AJAX_ORIGIN}laser/route/${sceneNameOrUrl}/getRouteInfo`
    // http://192.168.0.11:8080/laser/route/t-Y22JxCS7sP/getRouteInfo
  return axios
    .get(url)
    .then((res) => {
      if (Array.isArray(res.data.data) && res.data.data.length > 0) {
        return res.data.data
      } else {
        throw('getWholeData结果异常！')
      }
    })
}