import {Typography} from "@mui/material";
import {useEffect, useState} from "react";
import moment from "jalali-moment";
import useLanguage from "@/lib/app/hooks/useLanguage";

const CallTabTime = ({realTimeDate}) => {
    const {languageApp} = useLanguage()
    const [date, setDate] = useState('...')
    const changeTabTime = (tabTime) => {
        moment.relativeTimeThreshold('ss', 1)
        return moment(tabTime).locale(languageApp).fromNow()
    }

    useEffect(() => {
        const timer = setInterval(() => {
            setDate(changeTabTime(realTimeDate))
        }, 1000)

        return () => {
            clearInterval(timer)
        }
    }, [realTimeDate]);

    return (
        <Typography variant = "caption"
                    color = "gray">{date}</Typography>
    )
}
export default CallTabTime