"use client"

import { useEffect, useState } from "react"
import {
  DEFAULT_WEEK_STARTS_ON,
  resolveWeekStartsOn,
  type WeekStartsOn,
} from "@/lib/agenda/agenda-date"
import type { AgendaWeekStart } from "@/lib/agenda/agenda-settings-types"

/** weekStart « auto » : lundi au SSR / hydratation, puis locale navigateur après mount. */
export function useResolvedWeekStartsOn(weekStart: AgendaWeekStart): WeekStartsOn {
  const [startsOn, setStartsOn] = useState<WeekStartsOn>(() =>
    weekStart === "auto" ? DEFAULT_WEEK_STARTS_ON : weekStart,
  )

  useEffect(() => {
    setStartsOn(resolveWeekStartsOn(weekStart))
  }, [weekStart])

  return startsOn
}
