"use client"

import { create } from "zustand"

export type SessionGuardStatus = "idle" | "offline" | "expired"

interface SessionGuardState {
  status: SessionGuardStatus
  setOffline: () => void
  setExpired: () => void
  clear: () => void
}

export const useSessionGuardStore = create<SessionGuardState>((set, get) => ({
  status: "idle",
  setOffline: () => {
    if (get().status === "expired") return
    set({ status: "offline" })
  },
  setExpired: () => {
    if (get().status === "expired") return
    set({ status: "expired" })
  },
  clear: () => set({ status: "idle" }),
}))

export function isSessionExpired() {
  return useSessionGuardStore.getState().status === "expired"
}
