'use client';
import type { CalendarEventView } from '@/services/ScheduleService';
import { eventsOnDay, toISODate } from '@/lib/calendar/grid';
import {
SOURCE_COLORS,
SOURCE_CHIP_BORDER,
WEEKDAY_LABELS,
} from '@/components/calendar/sourceColors';
const MAX_VISIBLE_CHIPS = 3;
/**
* 月表示グリッド。日曜始まりの7列グリッドで各日にイベントチップを表示する。
* 長いタイトルは truncate し、3件を超える分は「+N件」でまとめる。
*/
export function MonthView({
events,
weeks,
anchorMonth,
todayKey,
onSelectDate,
}: {
events: CalendarEventView[];
weeks: Date[][];
anchorMonth: number;
todayKey: string;
onSelectDate: (dateKey: string) => void;
}) {
return (
{WEEKDAY_LABELS.map((w) => (
{w}
))}
{weeks.map((week, wi) => (
{week.map((day) => {
const key = toISODate(day);
const dayEvents = eventsOnDay(events, key);
const inMonth = day.getMonth() === anchorMonth;
const isToday = key === todayKey;
const visible = dayEvents.slice(0, MAX_VISIBLE_CHIPS);
const hidden = dayEvents.length - visible.length;
return (
{visible.map((e) => (
))}
{hidden > 0 && (
)}
);
})}
))}
);
}