import { useMemo } from 'react';
import useNowInterval from "../../../../hooks/time/useNowInterval/index.js";
import classes from './styles.module.scss';
const ItemTimestamp = function ItemTimestamp(props) {
  const {
    timestamp
  } = props;
  const now = useNowInterval(30000);
  const text = useMemo(() => {
    if (!now) return undefined;
    if (now < new Date(timestamp)) return undefined;
    const diffMs = now - new Date(timestamp);

    // Handle minutes-old formats
    const diffMins = Math.round(diffMs / (1000 * 60));
    if (diffMins < 1) return 'just now';
    if (diffMins < 60) return `${diffMins}m ago`;

    // Handle hours-old formats
    const diffHrs = Math.round(diffMins / 60);
    if (diffHrs < 24) return `${diffHrs}hr ago`;
    return undefined;
  }, [now]);
  if (!text) return null;
  return <span className={classes.timestamp}>
      {text}
    </span>;
};
export default ItemTimestamp;