Files
fotospiel-app/resources/js/admin/mobile/lib/packageShop.ts
Codex Agent ab2cf3e023
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Highlight upgrades in package shop
2026-01-12 11:38:16 +01:00

41 lines
969 B
TypeScript

import type { Package } from '../../api';
export function classifyPackageTier(price: number, activePrice: number | null): {
isUpgrade: boolean;
isDowngrade: boolean;
} {
if (activePrice === null) {
return { isUpgrade: false, isDowngrade: false };
}
return {
isUpgrade: price > activePrice,
isDowngrade: price < activePrice,
};
}
export function selectRecommendedPackageId(
packages: Package[],
feature: string | null,
activePrice: number | null
): number | null {
if (!feature) {
return null;
}
const candidates = packages.filter((pkg) => pkg.features?.[feature]);
if (candidates.length === 0) {
return null;
}
const upgradeCandidates =
activePrice === null
? candidates
: candidates.filter((pkg) => pkg.price > activePrice);
const pool = upgradeCandidates.length ? upgradeCandidates : candidates;
const sorted = [...pool].sort((a, b) => a.price - b.price);
return sorted[0]?.id ?? null;
}