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

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

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

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

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