import { useTranslation } from "react-i18next"; import { cn, getDaysBetweenDatesWithAutoRenewal, type PublicNoteData, } from "@/lib/utils"; import RemainPercentBar from "./RemainPercentBar"; export default function BillingInfo({ parsedData, }: { parsedData: PublicNoteData; }) { const { t } = useTranslation(); if (!parsedData || !parsedData.billingDataMod) { return null; } let isNeverExpire = false; let daysLeftObject = { days: 0, cycleLabel: "", remainingPercentage: 0, }; const hasBillingDates = Boolean(parsedData.billingDataMod.startDate) || Boolean(parsedData.billingDataMod.endDate); if (parsedData?.billingDataMod?.endDate) { if (parsedData.billingDataMod.endDate.startsWith("0000-00-00")) { isNeverExpire = true; } else { try { daysLeftObject = getDaysBetweenDatesWithAutoRenewal( parsedData.billingDataMod, ); } catch (error) { console.error(error); return (
{t("billingInfo.price")}: {parsedData.billingDataMod.amount}/ {parsedData.billingDataMod.cycle}
) : parsedData.billingDataMod.amount === "0" ? ({t("billingInfo.free")}
) : parsedData.billingDataMod.amount === "-1" ? ({t("billingInfo.usage-baseed")}
) : null} {hasBillingDates && ({t("billingInfo.price")}: {parsedData.billingDataMod.amount}/ {parsedData.billingDataMod.cycle}
) : parsedData.billingDataMod.amount === "0" ? ({t("billingInfo.free")}
) : parsedData.billingDataMod.amount === "-1" ? ({t("billingInfo.usage-baseed")}
) : null}{t("billingInfo.expired")}: {daysLeftObject.days * -1}{" "} {t("billingInfo.days")}
> ); }