"use client";

import { useCallback, useMemo } from "react";
import { useTranslations } from "next-intl";

import { PeriodKeyVariant, PeriodType } from "@/types/period";

export const usePeriod = () => {
  const t = useTranslations();

  const getPeriodText = useCallback(
    (
      periodType: PeriodType,
      count: number,
      periodKeyVariant: PeriodKeyVariant = "period"
    ) => {
      return t(`${periodKeyVariant}.${periodType.toLowerCase()}`, { count });
    },
    [t]
  );

  return useMemo(() => ({ getPeriodText }), [getPeriodText]);
};
