thread-master/apps/web/src/lib/planRights.ts

55 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PLANS, type PlanId } from "./usageMeter";
export type PlanRightsCopy = {
headline: string;
/** 比價卡上 45 條短權益 */
bullets: string[];
/** 結帳頁:你會得到 */
rights: string[];
/** 結帳頁:額度 */
quota: string[];
notes: string[];
};
type TFn = (key: string, params?: Record<string, string | number>) => string;
/** 購買/比價用文案(用量首頁不堆字)— 由 i18n keys 組成 */
export function getPlanRights(id: PlanId, t: TFn): PlanRightsCopy {
const p = PLANS[id];
const caps = {
copy: p.soft_caps.ai_copy,
research: p.soft_caps.ai_research,
search: p.soft_caps.web_search,
image: p.soft_caps.ai_image,
};
return {
headline: t(`plan.${id}.headline`),
bullets: [
t(`plan.${id}.bullet1`, { n: p.monthly_credits }),
t(`plan.${id}.bullet2`),
t(`plan.${id}.bullet3`),
t(`plan.${id}.bullet4`),
],
rights: [
t(`plan.${id}.right1`),
t(`plan.${id}.right2`),
t(`plan.${id}.right3`),
],
quota: [
t(`plan.${id}.quota1`, { n: p.monthly_credits, price: p.price_label }),
t(`plan.${id}.quota2`, caps),
],
notes: [t(`plan.${id}.note1`), t(`plan.${id}.note2`)],
};
}
export function planCtaLabel(current: PlanId, target: PlanId, t: TFn): string {
if (current === target) return t("plan.cta.current");
const order: PlanId[] = ["free", "starter", "pro"];
const a = order.indexOf(current);
const b = order.indexOf(target);
if (b > a) return t("plan.cta.upgrade");
if (b < a) return t("plan.cta.downgrade");
return t("plan.cta.switch");
}