import React from "react"; // Import types import { ProgramItem, ProgramWithPosition, ChannelWithPosiiton, DateTime, Position, BaseTimeFormat, } from "../helpers/types"; // Import helpers import { getProgramOptions, isFutureTime } from "../helpers"; // Import styles import { EpgStyled } from "../styles"; // Import components import { Timeline, Channels, Program, Line } from "../components"; interface RenderTimeline { isBaseTimeFormat: BaseTimeFormat; isSidebar: boolean; isRTL: boolean; sidebarWidth: number; hourWidth: number; numberOfHoursInDay: number; offsetStartHoursRange: number; dayWidth: number; } interface LayoutProps { programs: ProgramItem[]; channels: ChannelWithPosiiton[]; startDate: DateTime; endDate: DateTime; scrollY: number; dayWidth: number; hourWidth: number; numberOfHoursInDay: number; offsetStartHoursRange: number; sidebarWidth: number; itemHeight: number; onScroll: ( e: React.UIEvent & { target: Element } ) => void; isRTL?: boolean; isBaseTimeFormat?: BaseTimeFormat; isSidebar?: boolean; isTimeline?: boolean; isLine?: boolean; isProgramVisible: (position: Position) => boolean; isChannelVisible: (position: Pick) => boolean; renderProgram?: (v: { program: ProgramItem; isRTL: boolean; isBaseTimeFormat: BaseTimeFormat; }) => React.ReactNode; renderChannel?: (v: { channel: ChannelWithPosiiton }) => React.ReactNode; renderTimeline?: (v: RenderTimeline) => React.ReactNode; } const { ScrollBox, Content } = EpgStyled; export const Layout = React.forwardRef( (props, scrollBoxRef) => { const { channels, programs, startDate, endDate, scrollY } = props; const { dayWidth, hourWidth, sidebarWidth, itemHeight } = props; const { numberOfHoursInDay, offsetStartHoursRange } = props; const { isSidebar = true, isTimeline = true, isLine = true, isBaseTimeFormat = false, isRTL = false, } = props; const { onScroll, isProgramVisible, isChannelVisible, renderProgram, renderChannel, renderTimeline, } = props; const channelsLength = channels.length; const contentHeight = React.useMemo(() => channelsLength * itemHeight, [ channelsLength, itemHeight, ]); const isFuture = isFutureTime(endDate); const renderPrograms = (program: ProgramWithPosition) => { const { position } = program; const isVisible = isProgramVisible(position); if (isVisible) { const options = getProgramOptions(program); if (renderProgram) return renderProgram({ program: options, isRTL, isBaseTimeFormat, }); return ( ); } return null; }; const renderTopbar = () => { const props = { sidebarWidth, isSidebar, isRTL, dayWidth, numberOfHoursInDay, }; const timeProps = { offsetStartHoursRange, numberOfHoursInDay, isBaseTimeFormat, hourWidth, }; if (renderTimeline) { return renderTimeline({ ...timeProps, ...props }); } return ; }; return ( {isLine && isFuture && ( )} {isTimeline && renderTopbar()} {isSidebar && ( )} {programs.map((program) => renderPrograms(program as ProgramWithPosition) )} ); } );