import { differenceInCalendarDays } from "date-fns" import React, { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react" import { useDuration } from "../../hooks/useDuration" import { classNames } from "../../utils/classNames" import { AnimatedNumber } from "../AnimatedNumber" import { CenterAligned } from "../CenterAligned" import { Flex } from "../Flex" import { Text } from "../Text" export type CountdownProps = { end: Date className?: string showDaysOnly?: boolean size?: "sm" | "lg" } & ComponentPropsWithoutRef<"div"> function CountdownCell({ value, unit, size, }: { value: number unit: "years" | "months" | "days" | "hours" | "mins" | "secs" size: "sm" | "lg" }) { return ( {unit} ) } export const Countdown = forwardRef, CountdownProps>( function Countdown({ className, end, showDaysOnly, size = "lg" }, ref) { const now = Date.now() const duration = useDuration(end) const { years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, } = duration const actualDays = showDaysOnly && (years > 0 || months > 0) ? differenceInCalendarDays(end, now) : days return ( {!showDaysOnly && years && ( )} {!showDaysOnly && months && ( )} ) }, )