import { api } from './api'
import type { PublicSiteStatusResponse } from '../types/awards'

let siteStatusPromise: Promise<PublicSiteStatusResponse | null> | null = null

export function clearSiteStatusCache() {
  siteStatusPromise = null
}

export function loadSiteStatus(force = false) {
  if (force || !siteStatusPromise) {
    siteStatusPromise = api.getSiteStatus().catch(() => null)
  }

  return siteStatusPromise
}
