import "client-only"

export const glaStorageName = "gla-storage"

type GlaSessionData = {
  lateArrivalGuarantee: string
  hotelId: string
}

export function readGlaFromSessionStorage(): GlaSessionData | null {
  try {
    const glaSessionData = sessionStorage.getItem(glaStorageName)
    if (!glaSessionData) return null
    return JSON.parse(glaSessionData)
  } catch (error) {
    console.error("Error reading from session storage:", error)
    return null
  }
}

export function writeGlaToSessionStorage(
  lateArrivalGuarantee: string,
  hotelId: string
) {
  try {
    sessionStorage.setItem(
      glaStorageName,
      JSON.stringify({ lateArrivalGuarantee, hotelId })
    )
  } catch (error) {
    console.error("Error writing to session storage:", error)
  }
}

export function clearGlaSessionStorage() {
  sessionStorage.removeItem(glaStorageName)
}
