"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, isStory) => {
  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 differenceWeek = currentDate.diff(timestampDate, 'week');
    const differenceMonth = currentDate.diff(timestampDate, 'month');
    const differenceYear = currentDate.diff(timestampDate, 'year');
    if (differenceSec < 60) return 'Just now';
    if (differenceMinutes < 60) return `${differenceMinutes}${isStory ? 'm' : differenceMinutes === 1 ? ' min ago' : ' mins ago'}`;
    if (differenceHour < 24) return `${differenceHour}${isStory ? 'h' : differenceHour === 1 ? ' hour ago' : ' hours ago'}`;
    if (differenceHour < 48) return isStory ? `${differenceHour} h` : 'Yesterday';
    if (differenceDay < 7) return `${differenceDay} ${differenceDay === 1 ? 'day ago' : 'days ago'}`;
    if (differenceWeek < 4) return `${differenceWeek} ${differenceWeek === 1 ? 'week ago' : 'weeks ago'}`;
    if (differenceMonth < 12) return `${differenceMonth} ${differenceMonth === 1 ? 'month ago' : 'months ago'}`;
    return `${differenceYear} ${differenceYear === 1 ? 'year ago' : 'years ago'}`;
  }, [isStory, timestamp]);
  return timeDifference;
};
exports.useTimeDifference = useTimeDifference;
//# sourceMappingURL=useTimeDifference.js.map