"use client"; import { User, Clock, CalendarDays, MapPin } from "lucide-react"; import { shortAddress } from "./constants"; import type { ScheduleDayMerged, ScheduleClassWithLocation } from "./constants"; interface ScheduleGroup { trainer: string; type: string; level?: string; hasSlots: boolean; recruiting: boolean; location?: string; locationAddress?: string; slots: { day: string; dayShort: string; time: string }[]; } function buildGroups(days: ScheduleDayMerged[]): ScheduleGroup[] { const map = new Map(); for (const day of days) { for (const cls of day.classes as ScheduleClassWithLocation[]) { // Include location in key so same trainer+type at different locations = separate groups const locPart = cls.locationName ?? ""; const key = `${cls.trainer}||${cls.type}||${locPart}`; const existing = map.get(key); if (existing) { existing.slots.push({ day: day.day, dayShort: day.dayShort, time: cls.time }); if (cls.hasSlots) existing.hasSlots = true; if (cls.recruiting) existing.recruiting = true; if (cls.level && !existing.level) existing.level = cls.level; } else { map.set(key, { trainer: cls.trainer, type: cls.type, level: cls.level, hasSlots: !!cls.hasSlots, recruiting: !!cls.recruiting, location: cls.locationName, locationAddress: cls.locationAddress, slots: [{ day: day.day, dayShort: day.dayShort, time: cls.time }], }); } } } return Array.from(map.values()); } interface GroupViewProps { typeDots: Record; filteredDays: ScheduleDayMerged[]; filterType: string | null; setFilterType: (type: string | null) => void; filterTrainer: string | null; setFilterTrainer: (trainer: string | null) => void; showLocation?: boolean; onBook?: (groupInfo: string) => void; } export function GroupView({ typeDots, filteredDays, filterType, setFilterType, filterTrainer, setFilterTrainer, showLocation, onBook, }: GroupViewProps) { const groups = buildGroups(filteredDays); if (groups.length === 0) { return (
Нет занятий по выбранным фильтрам
); } return (
{groups.map((group) => { const dotColor = typeDots[group.type] ?? "bg-white/30"; return (
{/* Header */}
{/* Type + badges */}
{group.level && ( {group.level} )} {group.hasSlots && ( есть места )} {group.recruiting && ( набор )}
{/* Trainer */} {/* Location badge — only in "all" mode */} {showLocation && group.location && (
{group.location} {group.locationAddress && ( · {shortAddress(group.locationAddress)} )}
)}
{/* Schedule slots */}
Расписание
{group.slots.map((slot, i) => (
{slot.dayShort}
{slot.time}
))}
{onBook && ( )}
); })}
); }