import { isValidEnv } from 'config/env'

export const SELECTED_API_KEY = 'selected_api'

export const readSelectedApi = () => {
  const rawValue = localStorage.getItem(SELECTED_API_KEY)
  if (!rawValue) return null

  const selectedApi = JSON.parse(rawValue)
  if (selectedApi && isValidEnv(selectedApi)) {
    return selectedApi
  }
  return null
}
