// ScheduleLinearWeekly.js
import PropTypes from 'prop-types'
import React from 'react'
import styles from './styles.module.css'
import { organizeData } from './helpers'
import { ScheduleMobile } from './ScheduleMobile'
import { AlertInfo } from '../../molecules'
import { Divider } from '../../atoms/Divider'
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
})
export const ScheduleLinearWeekly = ({
isMobile,
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 // Variable para rastrear si ya se mostró el texto del primer evento
let lastEventIndex = 0 // Variable para rastrear el índice del último evento
const totalHours = Object.keys(hoursData).length // Obtener el número total de horas con eventos
let Hours = 0 // Inicializar el total de horas para el día
for (let hour in hoursData) {
Hours += hoursData[hour].length // Sumar la cantidad de horas para cada evento
}
return (
{
return handleClick(Number(indexDays))
}}
>
{days[day]}
{Hours ? ` ${Hours || 0} h` : null}
{hours?.map((hour, index) => {
const events = hoursData[hour]
if (events && events.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 handleClick(indexDays)
}}
>
{isFirstEvent
? `${event.schHoSta} - ${event.schHoEnd}`
: null}
)
}
return (
)
})}
)
})}
>
)
}
ScheduleLinearWeekly.propTypes = {
handleClick: PropTypes.func,
handleHourPmAM: PropTypes.func,
isMobile: PropTypes.bool,
openStoreEveryDay: PropTypes.bool,
schedules: PropTypes.array,
style: PropTypes.object
}