import { ENV, isProduction } from 'config/env'

import { readSelectedApi } from 'helpers/selectedApi'

const APIS = {
  preproduction: 'https://api.auth.insports.tv',
  production: 'https://api.auth.insports.tv',
  staging: 'https://api.auth.test.insports.tv',
}

const env = isProduction ? ENV : readSelectedApi() ?? ENV

export const API_ROOT = APIS[env]

export const getApiUrl = (path: string) => (
  `${API_ROOT}${path}${window.location.search}`
)
