"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useTimeDifference = void 0;
var _dayjs = _interopRequireDefault(require("dayjs"));
var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));
var _react = require("react");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
_dayjs.default.extend(_relativeTime.default);
const useTimeDifference = timestamp => {
  const timeDifference = (0, _react.useMemo)(() => {
    const timestampDate = (0, _dayjs.default)(timestamp);
    const currentDate = (0, _dayjs.default)();
    const differenceSec = currentDate.diff(timestampDate, 'second');
    const differenceMinutes = currentDate.diff(timestampDate, 'minute');
    const differenceHour = currentDate.diff(timestampDate, 'hour');
    const differenceDay = currentDate.diff(timestampDate, 'day');
    const differenceMonth = currentDate.diff(timestampDate, 'month');
    if (differenceSec < 60) return 'Just now';
    if (differenceMinutes < 60) return `${differenceMinutes}m`;
    if (differenceHour < 24) return `${differenceHour}h`;
    if (differenceDay === 1) return '1d';
    if (differenceDay < 7) return `${differenceDay}d`;
    if (differenceMonth < 12) {
      const formattedMonthDate = timestampDate.format('D MMMM');
      return formattedMonthDate;
    }
    const formattedYearMonthDate = timestampDate.format('D MMMM YYYY');
    return formattedYearMonthDate;
  }, [timestamp]);
  return timeDifference;
};
exports.useTimeDifference = useTimeDifference;
//# sourceMappingURL=useTimeDifference.js.map