{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kit-scheduling",
  "type": "registry:lib",
  "title": "Kit scheduling",
  "description": "Helpers shared by the scheduling blocks.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/blocks/_shared/scheduling-kit.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/_shared/scheduling-kit.tsx",
      "content": "// Date arithmetic for the scheduling blocks. Pure functions on ISO text (\"2026-11-16\", \"2026-11\"): no clock, no time zone,\n// so a block renders the same everywhere and the same on the server. \"Today\" is a prop, never `new Date()`.\n\nexport interface DayCell { iso: string; day: number; inMonth: boolean }\n\nconst pad = (n: number) => String(n).padStart(2, '0');\nconst utc = (y: number, m: number, d: number) => new Date(Date.UTC(y, m - 1, d));\nconst isoOf = (d: Date) => `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;\n\n/** [year, month] from \"YYYY-MM\"; null when it is not one. */\nexport function parseMonth(text: string): [number, number] | null {\n  const m = /^(\\d{4})-(\\d{2})$/.exec(text.trim());\n  if (!m) return null;\n  const month = Number(m[2]);\n  return month >= 1 && month <= 12 ? [Number(m[1]), month] : null;\n}\n\n/** The month before or after \"YYYY-MM\". */\nexport function shiftMonth(month: string, by: number): string {\n  const [y, m] = parseMonth(month) ?? [1970, 1];\n  const d = utc(y, m + by, 1);\n  return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}`;\n}\n\n/** Whole weeks covering the month, each a row of seven cells starting on Monday or Sunday. */\nexport function monthGrid(month: string, first: 'mon' | 'sun'): DayCell[][] {\n  const [y, m] = parseMonth(month) ?? [1970, 1];\n  const start = utc(y, m, 1);\n  const offset = (start.getUTCDay() - (first === 'mon' ? 1 : 0) + 7) % 7;\n  const total = Math.ceil((offset + new Date(Date.UTC(y, m, 0)).getUTCDate()) / 7) * 7;\n  const cells: DayCell[] = Array.from({ length: total }, (_, i) => {\n    const d = utc(y, m, 1 - offset + i);\n    return { iso: isoOf(d), day: d.getUTCDate(), inMonth: d.getUTCMonth() === m - 1 };\n  });\n  return Array.from({ length: total / 7 }, (_, w) => cells.slice(w * 7, w * 7 + 7));\n}\n\n/** \"November 2026\" for \"2026-11\", in the given language. */\nexport function monthName(month: string, locale: string): string {\n  const [y, m] = parseMonth(month) ?? [1970, 1];\n  try {\n    return new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric', timeZone: 'UTC' }).format(utc(y, m, 1));\n  } catch {\n    return month;\n  }\n}\n\n/** \"Monday 16 November 2026\" for \"2026-11-16\". */\nexport function dayName(iso: string, locale: string): string {\n  const m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(iso);\n  if (!m) return iso;\n  try {\n    return new Intl.DateTimeFormat(locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }).format(utc(Number(m[1]), Number(m[2]), Number(m[3])));\n  } catch {\n    return iso;\n  }\n}\n\n/** Orders events by their date and then their time, both read as numbers (\"2026-11-9\" before \"2026-11-10\"; \"9:00\" before \"10:00\"). */\nexport function byWhen<T extends { date: string; time?: string }>(events: T[]): T[] {\n  const mins = (t?: string) => {\n    const m = /(\\d{1,2})[:.](\\d{2})/.exec(t ?? '');\n    return m ? Number(m[1]) * 60 + Number(m[2]) : -1;\n  };\n  const day = (d: string) => d.split('-').map(Number);\n  const cmp = (a: number[], b: number[]) => (a[0]! - b[0]!) || (a[1]! - b[1]!) || (a[2]! - b[2]!);\n  return [...events].sort((a, b) => cmp(day(a.date), day(b.date)) || mins(a.time) - mins(b.time));\n}\n"
    }
  ]
}
