import { memo } from 'react' import { isNull } from 'lodash' import { getCountdownTimeStatus } from '@/utils/getCountdownTimeStatus' /** * Constructs animated progress bar visualizing time progress of an event. * If end date is not provided, progress bar animates indefinitely. * * @param id - A unique ID to distinguish instances. * @param startDate - The start date of the tracked event. * @param endDate - The end date of the tracked event. */ export const LinearAnimatedProgressBar = memo( ({ id, startDate, endDate, }: { id: string startDate: Date endDate: Date | null }) => { const height = 3 const maskId = `mask-${id}` const progressId = `progress-${id}` const greenColor = 'rgb(74 222 128)' const purpleColor = 'hsl(265deg 100% 75%)' let duration: string | number const isIndefinite = isNull(endDate) if (isIndefinite) { duration = 'infinite' return ( ) } else { const { totalTimeInSeconds, totalTimeElapsedInSeconds, totalTimeRemainingInSeconds, isComplete, } = getCountdownTimeStatus(startDate, endDate) const percentElapsed = Math.floor( (totalTimeElapsedInSeconds / totalTimeInSeconds) * 100 ) duration = isComplete ? 0.5 : totalTimeRemainingInSeconds return ( {isComplete && ( )} {isComplete && ( )} ) } } )