import React from 'react' import PropTypes from 'prop-types' import { organizeData } from './helpers' import { ScheduleMobile } from './ScheduleMobile' import { Divider } from '../../atoms/Divider' import styles from './styles.module.css' const days = { 1: 'Lunes', 2: 'Martes', 3: 'Miércoles', 4: 'Jueves', 5: 'Viernes', 6: 'Sábado', 0: 'Domingo' } const hours = Array.from({ length: 25 }, (_, i) => { return i }) interface ScheduleLinearWeeklyProps { isMobile?: boolean handleClick?: (number: number) => void handleHourPmAM?: (string: string) => void schedules?: any[] style?: React.CSSProperties } export const ScheduleLinearWeekly: React.FC = ({ isMobile = false, handleClick = (number) => { return number }, handleHourPmAM = (string) => { return string }, schedules = [], style = {} }) => { const data = organizeData(schedules) if (isMobile) { return ( ) } return ( <>
{hours?.map((hour) => { return
{`${hour}h`}
})}
{Object.entries(data).map(([day, hoursData], indexDays) => { let isFirstEventShown = false let lastEventIndex = 0 const totalHours = Object.keys(hoursData as Record).length let Hours = 0 for (const hour in hoursData as Record) { Hours += (hoursData as Record)[hour].length } return (
{hours?.map((hour, index) => { const events = (hoursData as Record)[hour] if ((Boolean(events)) && (events as any[]).length > 0) { const event = events[0] const isFirstEvent = !isFirstEventShown // Verifica si es el primer evento isFirstEventShown = true // Actualiza isFirstEventShown después de mostrar el primer evento lastEventIndex = index // Actualiza el índice del último evento mostrado let borderRadiusStyle = {} // Estilo para el borde de la celda if (totalHours === 1) { // Si solo hay un evento, aplicar bordes redondeados borderRadiusStyle = { borderRadius: '5px' } } else if (index === 0) { // Si es el primer evento borderRadiusStyle = { borderTopLeftRadius: '5px', borderTopRightRadius: '5px' } } else if (index === totalHours - 1) { // Si es el último evento borderRadiusStyle = { borderBottomLeftRadius: '5px', borderBottomRightRadius: '5px' } } else if (index === lastEventIndex - 1) { // Si es el evento antes del último borderRadiusStyle = { borderBottomLeftRadius: '0', borderBottomRightRadius: '0' } } return ( ) } return (
) })}
) })}
) } ScheduleLinearWeekly.propTypes = { handleClick: PropTypes.func, handleHourPmAM: PropTypes.func, isMobile: PropTypes.bool, schedules: PropTypes.array, style: PropTypes.object }