import React from 'react' import { startOfWeek, endOfWeek, eachDayOfInterval, format, isSameDay, isToday, } from 'date-fns' import { ptBR } from 'date-fns/locale' import { parseLocalDate, sortAppointmentsByTime } from '../../utils/agendaDate.js' export function AgendaWeeklyView({ baseDate, appointments, onAppointmentClick }) { const start = startOfWeek(baseDate, { weekStartsOn: 0 }) const end = endOfWeek(baseDate, { weekStartsOn: 0 }) const days = eachDayOfInterval({ start, end }) const weeklyAppointments = sortAppointmentsByTime( appointments.filter((appointment) => { if (!appointment.date) return false const appointmentDate = parseLocalDate(appointment.date) return appointmentDate && appointmentDate >= start && appointmentDate <= end }), ) return (
{days.map((day) => { const isWeekend = day.getDay() === 0 return (
{format(day, 'EEE', { locale: ptBR })} {format(day, 'dd')}
) })}
{days.map((day) => { const dayAppointments = weeklyAppointments.filter((appointment) => { if (!appointment.date) return false const appointmentDate = parseLocalDate(appointment.date) return appointmentDate && isSameDay(appointmentDate, day) }) return (
{dayAppointments.length === 0 ? (
Livre
) : ( dayAppointments.map((appointment) => ( )) )}
) })}
) } function getStatusColors(status) { switch (status) { case 'Confirmada': return 'border-[#14532d] bg-[#052e1a] text-[#10b981]' case 'Em triagem': return 'border-[#78350f] bg-[#2d1e05] text-[#f59e0b]' case 'Concluida': case 'ConcluĂ­da': return 'border-[#1e3a8a] bg-[#172554] text-[#60a5fa]' case 'Aguardando': return 'border-[#404040] bg-[#303030] text-[#e5e5e5]' case 'Cancelada': return 'border-[#7f1d1d] bg-[#450a0a] text-[#f87171] opacity-75' case 'Bloqueado': return 'border-[#404040] bg-[#1f1f1f] text-[#737373]' default: return 'border-[#404040] bg-[#303030] text-[#e5e5e5]' } }