import { useMemo as M } from "react";
import { isValidDate as I } from "./index-date-helpers.js";
import { formatTextWithAffixes as r } from "./index-format-text-with-affixes.js";
const g = (s) => M(() => {
  if (!s)
    return {
      text: "recently"
    };
  if (!I(s))
    return {
      text: "Invalid date",
      error: `Invalid date provided: ${s}`
    };
  const x = /* @__PURE__ */ new Date(), l = new Date(s), u = Math.floor((l.getTime() - x.getTime()) / 1e3), c = u > 0, m = Math.abs(u), e = c ? "in " : "", n = c ? "" : " ago";
  if (m < 60) {
    const {
      text: t
    } = r("a few seconds", e, n);
    return {
      text: t
    };
  }
  const f = Math.floor(m / 60);
  if (f === 1) {
    const {
      text: t
    } = r("a minute", e, n);
    return {
      text: t
    };
  }
  if (f < 60) {
    const {
      text: t
    } = r("%number% minutes", e, n);
    return {
      text: t,
      replacements: {
        number: f
      }
    };
  }
  const a = Math.floor(f / 60);
  if (a === 1) {
    const {
      text: t
    } = r("an hour", e, n);
    return {
      text: t
    };
  }
  if (a < 24) {
    const {
      text: t
    } = r("%number% hours", e, n);
    return {
      text: t,
      replacements: {
        number: a
      }
    };
  }
  const o = Math.floor(a / 24);
  if (o === 1) {
    const {
      text: t
    } = r("a day", e, n);
    return {
      text: t
    };
  }
  if (o < 7) {
    const {
      text: t
    } = r("%number% days", e, n);
    return {
      text: t,
      replacements: {
        number: o
      }
    };
  }
  if (o < 30) {
    const t = Math.floor(o / 7);
    if (t === 1) {
      const {
        text: D
      } = r("a week", e, n);
      return {
        text: D
      };
    }
    const {
      text: p
    } = r("%number% weeks", e, n);
    return {
      text: p,
      replacements: {
        number: t
      }
    };
  }
  const i = Math.floor(o / 30);
  if (i === 1) {
    const {
      text: t
    } = r("a month", e, n);
    return {
      text: t
    };
  }
  if (i < 12) {
    const {
      text: t
    } = r("%number% months", e, n);
    return {
      text: t,
      replacements: {
        number: i
      }
    };
  }
  const b = Math.floor(i / 12);
  if (b === 1) {
    const {
      text: t
    } = r("a year", e, n);
    return {
      text: t
    };
  }
  const {
    text: h
  } = r("%number% years", e, n);
  return {
    text: h,
    replacements: {
      number: b
    }
  };
}, [s]);
export {
  g as useRelativeTimeFormat
};
