import { useState } from 'react' import type { AttendanceStatus } from '@gruperly/shared' import { Check, ChevronDown, Loader2, Megaphone, Minus, X } from 'lucide-react' import type { LucideIcon } from 'lucide-react' import { Button } from '../../components/ui' import { cn } from '../../lib/utils' import { attendanceStatusClass, attendanceStatusLabel, attendanceSummary, formatSessionShortDate, HISTORY_LIMIT, HISTORY_PREVIEW, visibleSessions, type AttendanceSession, } from './attendance' import { Section } from './Section' import { useAttendeeDetail } from './AttendeeDetailProvider' const STATUS_ICONS: Record = { PRESENT: Check, ABSENT: X, EXCUSED: Megaphone, UNMARKED: Minus, } function iconFor(status: AttendanceSession['status']): LucideIcon { return STATUS_ICONS[status ?? 'UNMARKED'] } export function AttendeeAttendanceSection() { const { history, historyPending, historyFailed } = useAttendeeDetail() const [showAll, setShowAll] = useState(false) if (historyPending) { return (
) } if (historyFailed) { return (

No pudimos cargar la asistencia de este miembro.

) } const sessions = history?.sessions ?? [] if (sessions.length === 0) { return (

Todavía no hay clases registradas.

) } const visible = visibleSessions(sessions, showAll) const hasMore = sessions.length > HISTORY_PREVIEW const isCapped = sessions.length >= HISTORY_LIMIT const summary = attendanceSummary(visible) return (
{showAll && isCapped ? (

El historial guarda las últimas {HISTORY_LIMIT} clases.

) : null} {hasMore ? (
) : null}
) }