export type TermiAdminRuntimeConfig = {
  apiBaseUrl?: string
  frontendBaseUrl?: string
}

declare global {
  interface Window {
    __TERMI_ADMIN_RUNTIME_CONFIG__?: TermiAdminRuntimeConfig
  }
}

export function normalizeAdminBaseUrl(value?: string | null) {
  return value?.trim().replace(/\/$/, '') ?? ''
}

export function getRuntimeAdminBaseUrl(key: keyof TermiAdminRuntimeConfig) {
  if (typeof window === 'undefined') {
    return ''
  }

  return normalizeAdminBaseUrl(window.__TERMI_ADMIN_RUNTIME_CONFIG__?.[key])
}
