"use client"

import { getRemainingTime, getTimeUntilStart } from "@/lib/helpers/date.helper"
import { Badge } from "@/components/ui/badge"
import { cn } from "@/lib/utils"

interface CourseRemainingTimeProps {
    startDate?: string | null
    endDate?: string | null
    className?: string
}

export default function CourseRemainingTime({ startDate, endDate, className }: CourseRemainingTimeProps) {
    const defaultStyles = "text-[10px] text-white bg-black/40 px-2 py-1 rounded-md border-none"

    const now = Date.now()
    
    if (startDate && new Date(startDate).getTime() > now) {
        return (
            <span className={cn(defaultStyles, className)}>
                {getTimeUntilStart(startDate)}
            </span>
        )
    }

    if (endDate) {
        return (
            <span className={cn(defaultStyles, className)}>
                {getRemainingTime(endDate)}
            </span>
        )
    }

    return (
        <Badge className={cn(defaultStyles, className)}>
            بدون محدودیت
        </Badge>
    )
}
