Add cálculo de trial y badge de plan

This commit is contained in:
Carlos Narro
2026-05-30 19:58:18 +02:00
parent df085b6cf1
commit f2fb6d24c6
2 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
export function trialDaysRemaining(trialEndsAt: Date | null, now: Date = new Date()): number {
if (!trialEndsAt) return 0;
const ms = trialEndsAt.getTime() - now.getTime();
if (ms <= 0) return 0;
return Math.ceil(ms / (24 * 60 * 60 * 1000));
}
export function formatPlanBadge(
planNombre: string | null,
status: string,
trialEndsAt: Date | null,
now: Date = new Date()
): string {
const plan = planNombre ? `Plan ${planNombre}` : 'Sin plan';
if (status === 'trial') {
return `${plan} · trial, ${trialDaysRemaining(trialEndsAt, now)} días restantes`;
}
return `${plan} · ${status}`;
}