import { isoDayOfWeek } from "@/lib/calendar"
import { dueDateInMonth, isDueOn, type Template } from "@/lib/recurrence"

const NAME = ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
const t = (o: Partial<Template>): Template => ({ id: "t", recurrence: "monthly", active: true, pattern: "mon_fri", ...o })

for (const d of ["2026-02-28","2026-03-02","2026-04-30","2026-05-31","2026-06-01","2026-08-15","2026-08-17","2026-09-15","2026-09-17","2026-05-01","2026-08-03"])
  console.log(d, NAME[isoDayOfWeek(d)]!)

console.log("--- day 31, May/June ---")
for (const p of ["mon_fri","mon_sat"] as const)
  console.log(p, "May", dueDateInMonth(t({ dayOfMonth: 31, pattern: p }), 2026, 5, new Set()), "June", dueDateInMonth(t({ dayOfMonth: 31, pattern: p }), 2026, 6, new Set()))
console.log("isDueOn 2026-06-01 mon_fri", isDueOn(t({ dayOfMonth: 31 }), "2026-06-01"))
console.log("--- day 15 August (Sat) ---")
for (const p of ["mon_fri","mon_sat"] as const)
  console.log(p, dueDateInMonth(t({ dayOfMonth: 15, pattern: p }), 2026, 8, new Set()))
console.log("--- day 31 Feb ---")
for (const p of ["mon_fri","mon_sat"] as const)
  console.log(p, dueDateInMonth(t({ dayOfMonth: 31, pattern: p }), 2026, 2, new Set()))
console.log("--- day 15 Sept, holidays 15+16 ---")
console.log(dueDateInMonth(t({ dayOfMonth: 15 }), 2026, 9, new Set(["2026-09-15","2026-09-16"])))
