import { Course } from "@/types/types";
import { DEFAULT_LANGUAGE, type AppLanguage } from "@/lib/i18n/registry";
import { translateCommon } from "@/lib/i18n/translate";

export function formatCoursePriceLabel(
  course: Course,
  lang: AppLanguage = DEFAULT_LANGUAGE
): string {
  if (course.is_free) {
    return translateCommon(lang, "academy.course.free");
  }

  const price = Number(course.price) || 0;
  const offer = Number(course.offer) || 0;
  const locale = lang === "fa" ? "fa-IR" : "en-US";

  if (offer > 0) {
    const finalPrice = Math.round((price * (100 - offer)) / 100);
    return translateCommon(lang, "courseSeo.priceToman", {
      price: finalPrice.toLocaleString(locale),
    });
  }

  return translateCommon(lang, "courseSeo.priceToman", {
    price: price.toLocaleString(locale),
  });
}
