let BASE_URL: string = ''
let TOKEN: string = ''

const getCookie = (name: string): string | null => {
  const reg: RegExp = new RegExp(`(^| )${name}=([^;]*)(;|$)`)
  const arr: RegExpMatchArray | null = document.cookie.match(reg)
  if (arr) return unescape(arr[2])
  return null
}

switch (process.env.NODE_ENV) {
  case 'production':
    BASE_URL = 'https://www.maicedata.com/collector/data/' // 生产环境
    TOKEN = LZString.decompressFromEncodedURIComponent(
      getCookie('__DM_TOKEN__') || window.localStorage.getItem('dm_token_'),
    )
    break
  default:
    // vite.config 代理 https://survey.maicedata.com/api/data/
    BASE_URL = '/api'
    TOKEN = '91e315a9-b2a8-4950-97fa-9dbf84a230d6'
}

export default {
  TOKEN,
  BASE_URL,
  ORGANIZATION: '733d0ac0-f67e-4bde-8872-3ca00983f18c',
  MEMBER: '6c18d1b6-406e-4961-965c-c4b9cfc14cc4',
  ACTIVITY: 'e6659af9-d53c-4b3f-9719-465d02687933',
  AREA: '65ef4ee6-4ad2-4754-b50c-1176c9188231',
  COMMITTEE: '6f610aca-39c2-4401-8b75-12f94193d956',
  COMMUNITY: '931687e6-b53a-4f2d-8ab9-83b4a7d5ea8f',
  STREET: 'af3ce0b6-f32d-4914-a336-bb7f6398ff85',
  BUILDING: 'e08e40c6-a15c-447d-8f9e-786216d93443',
  ROOM: '24b5403c-9b6e-4882-b049-51ef197e3aa7',
  ATTACHMENT: '988fc63e-fa55-4729-851d-24c4355213f2',
  TAG: '54344e11-c0d3-40d5-8f99-771066249328',
  GET_AUTH: '988fc63e-fa55-4729-851d-24c4355213f2/storage/grant',
  GET_USER_ID: 'https://www.maicedata.com/auth/user/bytoken',
  USER: '3625616b-7f2c-449a-8306-101aac7b8b97',
  ORG: 'b47ddc9a-0aa7-45a8-b1b6-6064f888d537',
}
