{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "event-calendar",
  "title": "Event Calendar",
  "description": "A full calendar screen with month and week views: color-coded event chips you can drag to another day, a time-grid week with a now line, quick event creation, event details with move and delete, calendar filters with counts, a selected-day agenda and arrow-key day navigation. On phones days show dots and the agenda sits under the grid.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/event-calendar/event-calendar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype CalId = \"work\" | \"team\" | \"personal\";\nexport interface CalendarEvent {\n  id: string;\n  title: string;\n  date: string; // YYYY-MM-DD\n  start: string; // HH:MM\n  end: string;\n  calendar: CalId;\n  location?: string;\n}\n\nexport interface EventCalendarProps {\n  events?: CalendarEvent[];\n  today?: string;\n  defaultView?: \"month\" | \"week\";\n  onEventsChange?: (events: CalendarEvent[]) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", panel: \"#0E0E0E\", card: \"#141414\", border: \"rgba(255,255,255,0.08)\", grid: \"rgba(255,255,255,0.06)\", hover: \"rgba(255,255,255,0.03)\", out: \"rgba(245,244,241,0.22)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", sel: \"rgba(255,255,255,0.06)\", red: \"#F87171\", ring: \"rgba(245,244,241,0.6)\", scrim: \"rgba(0,0,0,0.55)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", panel: \"#F4F4F1\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", grid: \"rgba(10,10,10,0.07)\", hover: \"rgba(10,10,10,0.025)\", out: \"rgba(10,10,10,0.25)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", sel: \"rgba(10,10,10,0.05)\", red: \"#DC2626\", ring: \"rgba(10,10,10,0.5)\", scrim: \"rgba(10,10,10,0.25)\" },\n};\nconst CALS: { id: CalId; name: string; color: string }[] = [\n  { id: \"work\", name: \"Work\", color: \"#60A5FA\" },\n  { id: \"team\", name: \"Team\", color: \"#A78BFA\" },\n  { id: \"personal\", name: \"Personal\", color: \"#34D399\" },\n];\nconst color = (c: CalId) => CALS.find((x) => x.id === c)!.color;\n\nconst EVENTS: CalendarEvent[] = [\n  { id: \"e1\", title: \"Weekly planning\", date: \"2026-11-02\", start: \"09:30\", end: \"10:15\", calendar: \"team\" },\n  { id: \"e2\", title: \"Design review\", date: \"2026-11-03\", start: \"14:00\", end: \"15:00\", calendar: \"work\", location: \"Room 4B\" },\n  { id: \"e3\", title: \"Dentist\", date: \"2026-11-04\", start: \"08:30\", end: \"09:15\", calendar: \"personal\" },\n  { id: \"e4\", title: \"1:1 with Lena\", date: \"2026-11-05\", start: \"11:00\", end: \"11:30\", calendar: \"work\" },\n  { id: \"e5\", title: \"Release v4.2\", date: \"2026-11-06\", start: \"16:00\", end: \"17:00\", calendar: \"team\" },\n  { id: \"e6\", title: \"Weekly planning\", date: \"2026-11-09\", start: \"09:30\", end: \"10:15\", calendar: \"team\" },\n  { id: \"e7\", title: \"Customer call\", date: \"2026-11-10\", start: \"13:00\", end: \"13:45\", calendar: \"work\", location: \"Video call\" },\n  { id: \"e8\", title: \"Gym\", date: \"2026-11-10\", start: \"18:00\", end: \"19:00\", calendar: \"personal\" },\n  { id: \"e9\", title: \"Roadmap workshop\", date: \"2026-11-11\", start: \"10:00\", end: \"12:30\", calendar: \"team\", location: \"Main room\" },\n  { id: \"e10\", title: \"Standup\", date: \"2026-11-12\", start: \"09:00\", end: \"09:15\", calendar: \"team\" },\n  { id: \"e11\", title: \"Investor update\", date: \"2026-11-12\", start: \"11:00\", end: \"12:00\", calendar: \"work\" },\n  { id: \"e12\", title: \"Lunch with Tomás\", date: \"2026-11-12\", start: \"12:30\", end: \"13:30\", calendar: \"personal\", location: \"Café Lumen\" },\n  { id: \"e13\", title: \"Interview: Frontend\", date: \"2026-11-12\", start: \"15:00\", end: \"16:00\", calendar: \"work\" },\n  { id: \"e14\", title: \"Sprint demo\", date: \"2026-11-13\", start: \"15:00\", end: \"16:00\", calendar: \"team\" },\n  { id: \"e15\", title: \"Weekly planning\", date: \"2026-11-16\", start: \"09:30\", end: \"10:15\", calendar: \"team\" },\n  { id: \"e16\", title: \"Offsite prep\", date: \"2026-11-18\", start: \"10:00\", end: \"11:00\", calendar: \"work\" },\n  { id: \"e17\", title: \"Birthday dinner\", date: \"2026-11-19\", start: \"19:00\", end: \"21:00\", calendar: \"personal\" },\n  { id: \"e18\", title: \"Board meeting\", date: \"2026-11-20\", start: \"09:00\", end: \"11:00\", calendar: \"work\" },\n  { id: \"e19\", title: \"Weekly planning\", date: \"2026-11-23\", start: \"09:30\", end: \"10:15\", calendar: \"team\" },\n  { id: \"e20\", title: \"Quarterly review\", date: \"2026-11-25\", start: \"13:00\", end: \"15:00\", calendar: \"team\" },\n  { id: \"e21\", title: \"Flight to Lisbon\", date: \"2026-11-27\", start: \"07:00\", end: \"10:00\", calendar: \"personal\" },\n];\n\nconst MONTHS = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"];\nconst DOW = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\nconst DOW_LONG = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"];\nconst HOURS = Array.from({ length: 14 }, (_, i) => 8 + i); // 8:00 – 21:00\nconst TIMES = Array.from({ length: 29 }, (_, i) => `${String(7 + Math.floor(i / 2)).padStart(2, \"0\")}:${i % 2 ? \"30\" : \"00\"}`);\nconst HOUR_H = 40;\n\nconst toD = (s: string) => {\n  const [y, m, d] = s.split(\"-\").map(Number);\n  return new Date(Date.UTC(y, m - 1, d));\n};\nconst fmt = (d: Date) => d.toISOString().slice(0, 10);\nconst addDays = (s: string, n: number) => fmt(new Date(toD(s).getTime() + n * 864e5));\nconst dow = (s: string) => (toD(s).getUTCDay() + 6) % 7;\nconst monthOf = (s: string) => s.slice(0, 7);\nconst addMonths = (s: string, n: number) => {\n  const d = toD(s);\n  return fmt(new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + n, 1)));\n};\nconst mins = (t: string) => Number(t.slice(0, 2)) * 60 + Number(t.slice(3));\nconst label12 = (t: string) => {\n  const h = Number(t.slice(0, 2));\n  return `${h % 12 || 12}${t.slice(3) === \"00\" ? \"\" : \":\" + t.slice(3)}${h < 12 ? \"am\" : \"pm\"}`;\n};\nconst longDate = (s: string) => `${DOW_LONG[dow(s)]}, ${MONTHS[toD(s).getUTCMonth()].slice(0, 3)} ${toD(s).getUTCDate()}`;\n\nexport function EventCalendar({ events: initial = EVENTS, today = \"2026-11-12\", defaultView = \"month\", onEventsChange, theme = \"dark\", className }: EventCalendarProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [events, setEvents] = React.useState(initial);\n  const [view, setView] = React.useState(defaultView);\n  const [cursor, setCursor] = React.useState(today); // any date inside the visible month / week\n  const [selected, setSelected] = React.useState(today);\n  const [hidden, setHidden] = React.useState<Record<CalId, boolean>>({ work: false, team: false, personal: false });\n  const [openId, setOpenId] = React.useState<string | null>(null);\n  const [creating, setCreating] = React.useState<null | { title: string; start: string; end: string; calendar: CalId }>(null);\n  const [drag, setDrag] = React.useState<null | { id: string; x: number; y: number; over: string | null; moved: boolean }>(null);\n  const gridRef = React.useRef<HTMLDivElement>(null);\n  const focusOnce = React.useCallback((el: HTMLElement | null) => el?.focus({ preventScroll: true }), []);\n\n  const commit = (next: CalendarEvent[]) => {\n    setEvents(next);\n    onEventsChange?.(next);\n  };\n  const visible = events.filter((e) => !hidden[e.calendar]);\n  const byDate = (d: string) => visible.filter((e) => e.date === d).sort((a, b) => mins(a.start) - mins(b.start));\n  const open = events.find((e) => e.id === openId) ?? null;\n\n  React.useEffect(() => {\n    if (!openId && !creating) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpenId(null);\n        setCreating(null);\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [openId, creating]);\n\n  // Month grid\n  const first = `${monthOf(cursor)}-01`;\n  const gridStart = addDays(first, -dow(first));\n  const daysInMonth = new Date(Date.UTC(toD(first).getUTCFullYear(), toD(first).getUTCMonth() + 1, 0)).getUTCDate();\n  const rows = Math.ceil((dow(first) + daysInMonth) / 7);\n  const cells = Array.from({ length: rows * 7 }, (_, i) => addDays(gridStart, i));\n  // Week\n  const weekStart = addDays(cursor, -dow(cursor));\n  const week = Array.from({ length: 7 }, (_, i) => addDays(weekStart, i));\n\n  const title =\n    view === \"month\"\n      ? `${MONTHS[toD(first).getUTCMonth()]} ${toD(first).getUTCFullYear()}`\n      : `${MONTHS[toD(week[0]).getUTCMonth()].slice(0, 3)} ${toD(week[0]).getUTCDate()} – ${monthOf(week[0]) === monthOf(week[6]) ? \"\" : MONTHS[toD(week[6]).getUTCMonth()].slice(0, 3) + \" \"}${toD(week[6]).getUTCDate()}, ${toD(week[6]).getUTCFullYear()}`;\n\n  const shift = (n: number) => {\n    const next = view === \"month\" ? addMonths(cursor, n) : addDays(cursor, 7 * n);\n    setCursor(next);\n    setSelected(view === \"month\" ? next : addDays(selected, 7 * n));\n  };\n  const pick = (d: string) => {\n    setSelected(d);\n    if (monthOf(d) !== monthOf(cursor) && view === \"month\") setCursor(d);\n  };\n  const focusDay = (d: string) => requestAnimationFrame(() => gridRef.current?.querySelector<HTMLElement>(`[data-day=\"${d}\"]`)?.focus());\n  const onGridKey = (e: React.KeyboardEvent) => {\n    const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key];\n    if (!step || !(e.target as HTMLElement).dataset.day) return;\n    e.preventDefault();\n    const d = addDays(selected, step);\n    pick(d);\n    focusDay(d);\n  };\n\n  // Drag a chip to another day (pointer events, so it works with touch too)\n  const startDrag = (e: React.PointerEvent, id: string) => {\n    if (e.button !== 0) return;\n    (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n    setDrag({ id, x: e.clientX, y: e.clientY, over: null, moved: false });\n  };\n  const moveDrag = (e: React.PointerEvent) => {\n    if (!drag) return;\n    const moved = drag.moved || Math.hypot(e.clientX - drag.x, e.clientY - drag.y) > 5;\n    const cell = (document.elementFromPoint(e.clientX, e.clientY) as HTMLElement | null)?.closest<HTMLElement>(\"[data-cell]\");\n    setDrag({ ...drag, moved, over: moved ? (cell?.dataset.cell ?? null) : null });\n  };\n  const endDrag = () => {\n    if (!drag) return;\n    if (!drag.moved) setOpenId(drag.id);\n    else if (drag.over) {\n      commit(events.map((ev) => (ev.id === drag.id ? { ...ev, date: drag.over! } : ev)));\n      setSelected(drag.over);\n    }\n    setDrag(null);\n  };\n\n  const saveNew = () => {\n    if (!creating || !creating.title.trim()) return;\n    const id = `n${events.length + 1}-${creating.start.replace(\":\", \"\")}`;\n    commit([...events, { id, title: creating.title.trim(), date: selected, start: creating.start, end: mins(creating.end) > mins(creating.start) ? creating.end : TIMES[Math.min(TIMES.indexOf(creating.start) + 2, TIMES.length - 1)], calendar: creating.calendar }]);\n    setCreating(null);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const btn = cn(\"flex h-8 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-3 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-40\", focus);\n  const chev = (dir: 1 | -1) => (\n    <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={dir < 0 ? \"m15 6-6 6 6 6\" : \"m9 6 6 6-6 6\"} />\n    </svg>\n  );\n\n  const chip = (e: CalendarEvent) => {\n    const c = color(e.calendar);\n    const lifted = drag?.id === e.id && drag.moved;\n    return (\n      <motion.button\n        key={e.id}\n        layout={!reduce}\n        layoutId={reduce ? undefined : `${uid}-${e.id}`}\n        type=\"button\"\n        onPointerDown={(ev) => startDrag(ev, e.id)}\n        onPointerMove={moveDrag}\n        onPointerUp={endDrag}\n        onPointerCancel={() => setDrag(null)}\n        onKeyDown={(ev) => {\n          if (ev.key === \"Enter\" || ev.key === \" \") {\n            ev.preventDefault();\n            setOpenId(e.id);\n          }\n        }}\n        initial={reduce ? false : { opacity: 0, scale: 0.9 }}\n        animate={{ opacity: lifted ? 0.45 : 1, scale: lifted ? 0.96 : 1 }}\n        className={cn(\"flex w-full min-w-0 cursor-grab touch-none items-center gap-1.5 rounded-md border-0 px-1.5 py-[3px] text-left text-[11.5px] leading-tight select-none active:cursor-grabbing\", focus)}\n        style={{ background: `${c}24`, color: p.text, ...ring }}\n        aria-label={`${e.title}, ${label12(e.start)} to ${label12(e.end)}. Drag to move, Enter for details.`}\n      >\n        <span className=\"h-1.5 w-1.5 shrink-0 rounded-full\" style={{ background: c }} />\n        <span className=\"hidden shrink-0 tabular-nums @[900px]:inline\" style={{ color: p.muted }}>\n          {label12(e.start)}\n        </span>\n        <span className=\"truncate\">{e.title}</span>\n      </motion.button>\n    );\n  };\n\n  const monthView = (\n    <div ref={gridRef} role=\"grid\" aria-label={title} onKeyDown={onGridKey} className=\"flex min-h-0 flex-1 flex-col\">\n      <div role=\"row\" className=\"grid grid-cols-7 border-b\" style={{ borderColor: p.border }}>\n        {DOW.map((d) => (\n          <div key={d} role=\"columnheader\" className=\"px-2 py-2 text-[11.5px] font-medium tracking-[0.04em] uppercase\" style={{ color: p.faint }}>\n            <span className=\"@[640px]:hidden\">{d[0]}</span>\n            <span className=\"hidden @[640px]:inline\">{d}</span>\n          </div>\n        ))}\n      </div>\n      <div className=\"grid flex-1 grid-cols-7\" style={{ gridTemplateRows: `repeat(${rows}, minmax(0, 1fr))` }}>\n        {cells.map((d, i) => {\n          const list = byDate(d);\n          const inMonth = monthOf(d) === monthOf(cursor);\n          const isSel = d === selected;\n          const isToday = d === today;\n          const over = drag?.over === d;\n          return (\n            <div\n              key={d}\n              role=\"gridcell\"\n              data-cell={d}\n              aria-selected={isSel}\n              onClick={(ev) => {\n                if (ev.target === ev.currentTarget) pick(d);\n              }}\n              className={cn(\"relative flex min-h-[56px] min-w-0 flex-col gap-1 p-1 transition-colors @[640px]:min-h-[92px] @[640px]:p-1.5\", i % 7 !== 6 && \"border-r\", i < (rows - 1) * 7 && \"border-b\")}\n              style={{ borderColor: p.grid, background: over ? `${color(events.find((x) => x.id === drag!.id)!.calendar)}1f` : isSel ? p.sel : \"transparent\", boxShadow: over ? `inset 0 0 0 1.5px ${color(events.find((x) => x.id === drag!.id)!.calendar)}` : \"inset 0 0 0 0 transparent\" }}\n            >\n              <button\n                type=\"button\"\n                data-day={d}\n                tabIndex={isSel ? 0 : -1}\n                onClick={() => pick(d)}\n                aria-label={`${longDate(d)}${isToday ? \", today\" : \"\"}, ${list.length ? `${list.length} event${list.length > 1 ? \"s\" : \"\"}` : \"no events\"}`}\n                className={cn(\"grid h-6 w-6 shrink-0 cursor-pointer place-items-center self-center rounded-full border-0 text-[12px] tabular-nums @[640px]:self-start\", focus)}\n                style={{ background: isToday ? p.on : \"transparent\", color: isToday ? p.onText : inMonth ? p.text : p.out, fontWeight: isToday || isSel ? 600 : 400, ...ring }}\n              >\n                {toD(d).getUTCDate()}\n              </button>\n              {/* phones: dots */}\n              <div className=\"flex flex-wrap justify-center gap-0.5 @[640px]:hidden\" aria-hidden=\"true\">\n                {list.slice(0, 4).map((e) => (\n                  <span key={e.id} className=\"h-1.5 w-1.5 rounded-full\" style={{ background: color(e.calendar), opacity: inMonth ? 1 : 0.4 }} />\n                ))}\n              </div>\n              <div className=\"hidden min-w-0 flex-col gap-[3px] @[640px]:flex\" style={{ opacity: inMonth ? 1 : 0.45 }}>\n                {list.slice(0, list.length > 3 ? 2 : 3).map(chip)}\n                {list.length > 3 && (\n                  <button type=\"button\" onClick={() => pick(d)} className={cn(\"cursor-pointer rounded-md border-0 bg-transparent px-1.5 text-left text-[11.5px]\", focus)} style={{ color: p.muted, ...ring }}>\n                    +{list.length - 2} more\n                  </button>\n                )}\n              </div>\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n\n  const weekView = (\n    <div className=\"flex min-h-0 flex-1 flex-col overflow-x-auto\">\n      <div className=\"grid min-w-[640px] grid-cols-[52px_repeat(7,minmax(0,1fr))] border-b\" style={{ borderColor: p.border }}>\n        <span />\n        {week.map((d) => (\n          <button key={d} type=\"button\" onClick={() => setSelected(d)} className={cn(\"flex cursor-pointer flex-col items-center gap-0.5 border-0 bg-transparent py-2\", focus)} style={{ color: p.text, ...ring }} aria-label={longDate(d)} aria-pressed={d === selected}>\n            <span className=\"text-[11px] font-medium tracking-[0.04em] uppercase\" style={{ color: p.faint }}>\n              {DOW[dow(d)]}\n            </span>\n            <span className=\"grid h-7 w-7 place-items-center rounded-full text-[14px] tabular-nums\" style={{ background: d === today ? p.on : d === selected ? p.sel : \"transparent\", color: d === today ? p.onText : p.text, fontWeight: 600 }}>\n              {toD(d).getUTCDate()}\n            </span>\n          </button>\n        ))}\n      </div>\n      <div className=\"relative grid min-w-[640px] grid-cols-[52px_repeat(7,minmax(0,1fr))]\" style={{ height: HOURS.length * HOUR_H }}>\n        <div className=\"relative\">\n          {HOURS.map((h, i) => (\n            <span key={h} className=\"absolute right-2 -translate-y-1/2 text-[10.5px] tabular-nums\" style={{ top: i * HOUR_H, color: p.faint }}>\n              {i ? label12(`${String(h).padStart(2, \"0\")}:00`) : \"\"}\n            </span>\n          ))}\n        </div>\n        {week.map((d) => (\n          <div key={d} className=\"relative border-l\" style={{ borderColor: p.grid, background: d === selected ? p.hover : \"transparent\" }}>\n            {HOURS.map((h, i) => (\n              <span key={h} className=\"absolute inset-x-0 border-t\" style={{ top: i * HOUR_H, borderColor: p.grid }} aria-hidden=\"true\" />\n            ))}\n            {d === today && (\n              <span className=\"absolute inset-x-0 z-10 flex items-center\" style={{ top: ((mins(\"10:40\") - 480) / 60) * HOUR_H }} aria-hidden=\"true\">\n                <span className=\"-ml-1 h-2 w-2 rounded-full\" style={{ background: p.red }} />\n                <span className=\"h-[2px] flex-1\" style={{ background: p.red }} />\n              </span>\n            )}\n            {byDate(d).map((e) => {\n              const top = Math.max(0, ((mins(e.start) - 480) / 60) * HOUR_H);\n              const h = Math.max(20, ((Math.min(mins(e.end), 22 * 60) - Math.max(mins(e.start), 480)) / 60) * HOUR_H - 2);\n              const c = color(e.calendar);\n              return (\n                <motion.button key={e.id} type=\"button\" onClick={() => setOpenId(e.id)} initial={reduce ? false : { opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} className={cn(\"absolute inset-x-1 cursor-pointer overflow-hidden rounded-md border-0 px-1.5 py-1 text-left\", focus)} style={{ top: top + 1, height: h, background: `${c}2e`, borderLeft: `2px solid ${c}`, color: p.text, ...ring }}>\n                  <span className=\"block truncate text-[11.5px] font-medium leading-tight\">{e.title}</span>\n                  {h > 34 && (\n                    <span className=\"block truncate text-[10.5px] tabular-nums\" style={{ color: p.muted }}>\n                      {label12(e.start)} – {label12(e.end)}\n                    </span>\n                  )}\n                </motion.button>\n              );\n            })}\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n\n  const agenda = (\n    <div aria-live=\"polite\">\n      <p className=\"m-0 text-[13px] font-semibold\">{selected === today ? `Today · ${longDate(selected)}` : longDate(selected)}</p>\n      <ul className=\"m-0 mt-3 flex list-none flex-col gap-1.5 p-0\">\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {byDate(selected).map((e) => (\n            <motion.li key={e.id} layout={!reduce} initial={reduce ? false : { opacity: 0, x: -6 }} animate={{ opacity: 1, x: 0 }} exit={reduce ? undefined : { opacity: 0 }}>\n              <button type=\"button\" onClick={() => setOpenId(e.id)} className={cn(\"flex w-full cursor-pointer gap-2.5 rounded-lg border-0 bg-transparent px-2 py-1.5 text-left\", focus)} style={{ color: p.text, ...ring }}>\n                <span className=\"mt-0.5 w-[3px] shrink-0 self-stretch rounded-full\" style={{ background: color(e.calendar) }} />\n                <span className=\"min-w-0\">\n                  <span className=\"block truncate text-[13px] font-medium\">{e.title}</span>\n                  <span className=\"block text-[12px] tabular-nums\" style={{ color: p.muted }}>\n                    {label12(e.start)} – {label12(e.end)}\n                    {e.location ? ` · ${e.location}` : \"\"}\n                  </span>\n                </span>\n              </button>\n            </motion.li>\n          ))}\n        </AnimatePresence>\n        {!byDate(selected).length && (\n          <li className=\"px-2 py-1.5 text-[12.5px]\" style={{ color: p.faint }}>\n            Nothing planned.\n          </li>\n        )}\n      </ul>\n    </div>\n  );\n\n  const calToggles = (\n    <div className=\"flex flex-wrap gap-x-4 gap-y-2 @[900px]:flex-col @[900px]:gap-2.5\">\n      {CALS.map((c) => (\n        <label key={c.id} className=\"flex cursor-pointer items-center gap-2 text-[13px] has-[:focus-visible]:underline\">\n          <input type=\"checkbox\" checked={!hidden[c.id]} onChange={() => setHidden((h) => ({ ...h, [c.id]: !h[c.id] }))} className=\"sr-only\" />\n          <span className=\"grid h-4 w-4 place-items-center rounded-[5px] border transition-colors\" style={{ borderColor: c.color, background: hidden[c.id] ? \"transparent\" : c.color }} aria-hidden=\"true\">\n            {!hidden[c.id] && (\n              <svg width=\"10\" height=\"10\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#0A0A0A\" strokeWidth=\"3.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n              </svg>\n            )}\n          </span>\n          <span style={{ color: hidden[c.id] ? p.faint : p.text }}>{c.name}</span>\n          <span className=\"tabular-nums text-[11.5px]\" style={{ color: p.faint }}>\n            {events.filter((e) => e.calendar === c.id && monthOf(e.date) === monthOf(cursor)).length}\n          </span>\n        </label>\n      ))}\n    </div>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"grid min-h-[680px] grid-cols-[minmax(0,1fr)] @[900px]:grid-cols-[240px_minmax(0,1fr)]\">\n        {/* Sidebar (wide) */}\n        <aside className=\"hidden flex-col gap-7 border-r p-5 @[900px]:flex\" style={{ borderColor: p.border, background: p.panel }}>\n          <button type=\"button\" onClick={() => setCreating({ title: \"\", start: \"10:00\", end: \"11:00\", calendar: \"work\" })} className={cn(btn, \"h-9 w-full border-0\")} style={{ background: p.on, color: p.onText, ...ring }}>\n            <span aria-hidden=\"true\">+</span> New event\n          </button>\n          <div>\n            <p className=\"m-0 mb-3 text-[11.5px] font-medium tracking-[0.04em] uppercase\" style={{ color: p.faint }}>\n              Calendars\n            </p>\n            {calToggles}\n          </div>\n          {agenda}\n        </aside>\n\n        <div className=\"relative flex min-w-0 flex-col\">\n          {/* Toolbar */}\n          <div className=\"flex flex-wrap items-center gap-2 border-b px-3 py-3 @[640px]:px-5\" style={{ borderColor: p.border }}>\n            <h2 className=\"m-0 mr-auto min-w-0 truncate text-[17px] font-semibold tracking-[-0.01em] @[640px]:text-[19px]\" aria-live=\"polite\">\n              {title}\n            </h2>\n            <div className=\"flex items-center gap-1\">\n              <button type=\"button\" onClick={() => shift(-1)} aria-label={view === \"month\" ? \"Previous month\" : \"Previous week\"} className={cn(btn, \"w-8 border bg-transparent px-0\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                {chev(-1)}\n              </button>\n              <button\n                type=\"button\"\n                onClick={() => {\n                  setCursor(today);\n                  setSelected(today);\n                }}\n                className={cn(btn, \"border bg-transparent\")}\n                style={{ borderColor: p.border, color: p.text, ...ring }}\n              >\n                Today\n              </button>\n              <button type=\"button\" onClick={() => shift(1)} aria-label={view === \"month\" ? \"Next month\" : \"Next week\"} className={cn(btn, \"w-8 border bg-transparent px-0\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                {chev(1)}\n              </button>\n            </div>\n            <div role=\"radiogroup\" aria-label=\"View\" className=\"flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n              {([\"month\", \"week\"] as const).map((v) => (\n                <button key={v} type=\"button\" role=\"radio\" aria-checked={view === v} onClick={() => { setView(v); setCursor(selected); }} className={cn(\"relative h-7 cursor-pointer rounded-md border-0 bg-transparent px-3 text-[12.5px] font-medium capitalize\", focus)} style={{ color: view === v ? p.onText : p.muted, ...ring }}>\n                  {view === v && <motion.span layoutId={`${uid}-view`} className=\"absolute inset-0 rounded-md\" style={{ background: p.on }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} />}\n                  <span className=\"relative\">{v}</span>\n                </button>\n              ))}\n            </div>\n            <button type=\"button\" onClick={() => setCreating({ title: \"\", start: \"10:00\", end: \"11:00\", calendar: \"work\" })} aria-label=\"New event\" className={cn(btn, \"w-8 border-0 px-0 @[900px]:hidden\")} style={{ background: p.on, color: p.onText, ...ring }}>\n              +\n            </button>\n          </div>\n          <div className=\"border-b px-3 py-2.5 @[640px]:px-5 @[900px]:hidden\" style={{ borderColor: p.border }}>\n            {calToggles}\n          </div>\n\n          {view === \"month\" ? monthView : weekView}\n\n          {/* Agenda under the grid on narrow containers */}\n          <div className=\"border-t px-4 py-4 @[900px]:hidden\" style={{ borderColor: p.border }}>\n            {agenda}\n          </div>\n\n          {/* Event details / quick create */}\n          <AnimatePresence>\n            {(open || creating) && (\n              <motion.div\n                key=\"scrim\"\n                initial={reduce ? false : { opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={reduce ? undefined : { opacity: 0 }}\n                className=\"absolute inset-0 z-20 grid place-items-center p-4\"\n                style={{ background: p.scrim }}\n                onClick={(e) => {\n                  if (e.target === e.currentTarget) {\n                    setOpenId(null);\n                    setCreating(null);\n                  }\n                }}\n              >\n                <motion.div role=\"dialog\" aria-modal=\"true\" aria-labelledby={`${uid}-dlg`} initial={reduce ? false : { opacity: 0, y: 10, scale: 0.97 }} animate={{ opacity: 1, y: 0, scale: 1 }} exit={reduce ? undefined : { opacity: 0, y: 6, scale: 0.98 }} transition={{ type: \"spring\", stiffness: 480, damping: 36 }} className=\"w-full max-w-sm rounded-2xl border p-5 shadow-2xl\" style={{ background: p.card, borderColor: p.border }}>\n                  {open ? (\n                    <>\n                      <div className=\"flex items-start gap-3\">\n                        <span className=\"mt-1.5 h-2.5 w-2.5 shrink-0 rounded-full\" style={{ background: color(open.calendar) }} />\n                        <div className=\"min-w-0 flex-1\">\n                          <h3 id={`${uid}-dlg`} className=\"m-0 text-[16px] font-semibold\">\n                            {open.title}\n                          </h3>\n                          <p className=\"m-0 mt-1 text-[13px] tabular-nums\" style={{ color: p.muted }}>\n                            {longDate(open.date)} · {label12(open.start)} – {label12(open.end)}\n                          </p>\n                          <p className=\"m-0 mt-0.5 text-[13px]\" style={{ color: p.faint }}>\n                            {CALS.find((c) => c.id === open.calendar)!.name}\n                            {open.location ? ` · ${open.location}` : \"\"}\n                          </p>\n                        </div>\n                        <button type=\"button\" ref={focusOnce} onClick={() => setOpenId(null)} aria-label=\"Close\" className={cn(\"grid h-7 w-7 shrink-0 cursor-pointer place-items-center rounded-md border-0 bg-transparent text-[16px]\", focus)} style={{ color: p.muted, ...ring }}>\n                          ×\n                        </button>\n                      </div>\n                      <div className=\"mt-5 flex items-center gap-2\">\n                        <span className=\"mr-auto text-[12px]\" style={{ color: p.faint }}>\n                          Move\n                        </span>\n                        {[-1, 1].map((n) => (\n                          <button key={n} type=\"button\" onClick={() => { const d = addDays(open.date, n); commit(events.map((e) => (e.id === open.id ? { ...e, date: d } : e))); setSelected(d); if (monthOf(d) !== monthOf(cursor)) setCursor(d); }} className={cn(btn, \"border bg-transparent\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                            {n < 0 ? \"← Day\" : \"Day →\"}\n                          </button>\n                        ))}\n                        <button type=\"button\" onClick={() => { commit(events.filter((e) => e.id !== open.id)); setOpenId(null); }} className={cn(btn, \"border bg-transparent\")} style={{ borderColor: `${p.red}55`, color: p.red, ...ring }}>\n                          Delete\n                        </button>\n                      </div>\n                    </>\n                  ) : creating ? (\n                    <form\n                      onSubmit={(e) => {\n                        e.preventDefault();\n                        saveNew();\n                      }}\n                    >\n                      <h3 id={`${uid}-dlg`} className=\"m-0 text-[15px] font-semibold\">\n                        New event · <span style={{ color: p.muted, fontWeight: 400 }}>{longDate(selected)}</span>\n                      </h3>\n                      <label htmlFor={`${uid}-t`} className=\"sr-only\">\n                        Title\n                      </label>\n                      <input id={`${uid}-t`} ref={focusOnce} value={creating.title} onChange={(e) => setCreating({ ...creating, title: e.target.value })} placeholder=\"Add a title\" autoComplete=\"off\" className={cn(\"mt-4 h-10 w-full rounded-lg border px-3 text-[14px]\", focus)} style={{ borderColor: p.border, background: p.bg, color: p.text, ...ring }} />\n                      <div className=\"mt-3 grid grid-cols-2 gap-2\">\n                        {([\"start\", \"end\"] as const).map((k) => (\n                          <label key={k} className=\"text-[12px]\" style={{ color: p.faint }}>\n                            {k === \"start\" ? \"Starts\" : \"Ends\"}\n                            <select value={creating[k]} onChange={(e) => setCreating({ ...creating, [k]: e.target.value })} className={cn(\"mt-1 h-9 w-full cursor-pointer rounded-lg border px-2 text-[13px]\", focus)} style={{ borderColor: p.border, background: p.bg, color: p.text, ...ring }}>\n                              {TIMES.map((t) => (\n                                <option key={t} value={t}>\n                                  {label12(t)}\n                                </option>\n                              ))}\n                            </select>\n                          </label>\n                        ))}\n                      </div>\n                      <div role=\"radiogroup\" aria-label=\"Calendar\" className=\"mt-3 flex gap-1.5\">\n                        {CALS.map((c) => (\n                          <label key={c.id} className=\"flex cursor-pointer items-center gap-1.5 rounded-full border px-2.5 py-1 text-[12px] has-[:focus-visible]:ring-2\" style={{ borderColor: creating.calendar === c.id ? c.color : p.border, background: creating.calendar === c.id ? `${c.color}22` : \"transparent\", color: p.text, ...ring }}>\n                            <input type=\"radio\" name={`${uid}-cal`} checked={creating.calendar === c.id} onChange={() => setCreating({ ...creating, calendar: c.id })} className=\"sr-only\" />\n                            <span className=\"h-2 w-2 rounded-full\" style={{ background: c.color }} />\n                            {c.name}\n                          </label>\n                        ))}\n                      </div>\n                      <div className=\"mt-5 flex justify-end gap-2\">\n                        <button type=\"button\" onClick={() => setCreating(null)} className={cn(btn, \"border bg-transparent\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                          Cancel\n                        </button>\n                        <button type=\"submit\" disabled={!creating.title.trim()} className={cn(btn, \"border-0\")} style={{ background: p.on, color: p.onText, ...ring }}>\n                          Save\n                        </button>\n                      </div>\n                    </form>\n                  ) : null}\n                </motion.div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default EventCalendar;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}