import { mountCalendar, type CalendarItem } from "../calendar/mount-calendar";
import type { RenderSpec, ViewRow } from "./types";

// shape-calendar — Custom Views calendar shape. Since t-paliad-224 this
// is a thin adapter on top of the canonical mountCalendar() in
// frontend/src/client/calendar/mount-calendar.ts. /events Kalender tab
// uses the same module so both surfaces render identical DOM.
// See docs/design-calendar-view-align-2026-05-20.md.

export function renderCalendarShape(host: HTMLElement, rows: ViewRow[], render: RenderSpec): void {
  const items: CalendarItem[] = rows.map(toCalendarItem);
  mountCalendar(host, items, {
    defaultView: render.calendar?.default_view ?? "month",
    urlState: true,
  });
}

function toCalendarItem(row: ViewRow): CalendarItem {
  return {
    kind: row.kind,
    id: row.id,
    title: row.title,
    event_date: row.event_date,
    project_id: row.project_id,
    project_title: row.project_title,
    project_reference: row.project_reference,
  };
}
