import { useEffect, useState } from "react"

export function useLocalTimeZone(fallback?: string) {
  const [timeZone, setTimeZone] = useState<string | undefined>(fallback)

  useEffect(() => {
    if (typeof window === "undefined") return
    try {
      const resolved = Intl.DateTimeFormat().resolvedOptions().timeZone
      if (resolved) {
        setTimeZone(resolved)
      }
    } catch {
      /* ignore */
    }
  }, [])

  return timeZone
}
