// Metro module 6250 (f6251). import { PREMIUM_GUILD_SUBSCRIPTION_PLANS, PremiumTypes, SubscriptionIntervalTypes, SubscriptionPlans } from "../PremiumConstants"; import { AppStorePremiumProductIdsToPremiumBundledItems } from "./ProductIds.android"; import { isBoostOnlySubscription, getItemsWithUpsertedPremiumPlanId } from "../../../utils/PremiumUtils"; function $mk78085($env) { return (a0) => { const numPremiumGuild = a0.numPremiumGuild; const r6 = $env[0]; return numPremiumGuild === r6.numPremiumGuild && a0.premiumTier === r6.premiumTier && a0.interval !== r6.interval && !a0.isDeprecated; }; } let isValidBundleProductId, getSubscriptionItemsForProduct, aggregateQuantitiesByPlanId, planQuantityMapsEqual, getProductIdFromSubscriptionItems; const getPremiumBundledItemsFromProductId = function getPremiumBundledItemsFromProductId(a0) { if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { return AppStorePremiumProductIdsToPremiumBundledItems[a0]; } throw new Error(`Invalid bundled product ID ${a0}`); }; isValidBundleProductId = function isValidBundleProductId(a0) { return a0 != null && a0 in AppStorePremiumProductIdsToPremiumBundledItems; }; getSubscriptionItemsForProduct = function getSubscriptionItemsForProduct(a0) { if (!isValidBundleProductId(a0)) { throw new Error(`Invalid product ${a0}`); } const premiumBundledItemsFromProductId = getPremiumBundledItemsFromProductId(a0); const r28 = []; if (premiumBundledItemsFromProductId.basePlanId !== SubscriptionPlans.NONE_MONTH) { r28.push({ planId: premiumBundledItemsFromProductId.basePlanId, quantity: 1 }); } for (const additionalPlan of premiumBundledItemsFromProductId.additionalPlans) { r28.push({ planId: additionalPlan.planId, quantity: additionalPlan.quantity }); } return r28; }; aggregateQuantitiesByPlanId = function aggregateQuantitiesByPlanId(a0) { const map = new Map(); for (const item of a0) { const { planId, quantity } = item; let r10 = map.get(planId); if (r10 == null) { r10 = 0; } map.set(planId, r10 + quantity); } return map; }; planQuantityMapsEqual = function planQuantityMapsEqual(a0, a1) { if (a0.size !== a1.size) { return false; } for (const item of a0) { const [r8, r28] = item; if (a1.get(r8) === r28) { continue; } return false; } return true; }; getProductIdFromSubscriptionItems = function getProductIdFromSubscriptionItems(a0) { const r4 = aggregateQuantitiesByPlanId(a0); for (const item of Object.keys(AppStorePremiumProductIdsToPremiumBundledItems)) { if (!planQuantityMapsEqual(r4, aggregateQuantitiesByPlanId(getSubscriptionItemsForProduct(item)))) { continue; } return item; } throw new Error("No App Store bundled product matches the subscription items"); }; export function getPremiumBundlesWithPredicate(a0) { return Object.values(AppStorePremiumProductIdsToPremiumBundledItems).filter(a0); } export function getPremiumBundleWithPredicate(a0) { return Object.values(AppStorePremiumProductIdsToPremiumBundledItems).find(a0); } export { getPremiumBundledItemsFromProductId }; export function getToggledIntervalProduct(a0) { if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { let env15613; const r19 = env15613 = {}; const r23 = AppStorePremiumProductIdsToPremiumBundledItems[a0]; env15613[0] = r23; return r23.premiumTier !== PremiumTypes.TIER_1 ? Object.values(AppStorePremiumProductIdsToPremiumBundledItems).find($mk78085(r19))?.productId : null; } throw new Error(`Invalid bundled product ID ${a0}`); } export function getProductIdsForBothIntervals(a0) { let r63; if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { let env15614; const r25 = AppStorePremiumProductIdsToPremiumBundledItems[a0]; const r26 = env15614 = {}; env15614[0] = void 0; if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { const r42 = AppStorePremiumProductIdsToPremiumBundledItems[a0]; env15614[0] = r42; let yearly = r42.premiumTier !== PremiumTypes.TIER_1 ? Object.values(AppStorePremiumProductIdsToPremiumBundledItems).find($mk78085(r26))?.productId : null; if (yearly == null) { r63 = { monthly: a0, yearly: null }; } else { const monthly = r25.interval === SubscriptionIntervalTypes.MONTH ? a0 : yearly; if (r25.interval === SubscriptionIntervalTypes.YEAR) { yearly = a0; } r63 = { monthly, yearly }; } return r63; } throw new Error(`Invalid bundled product ID ${a0}`); } throw new Error(`Invalid bundled product ID ${a0}`); } export function productsHaveSamePerks(a0, a1) { if (a0 != null && a0 in AppStorePremiumProductIdsToPremiumBundledItems && a1 != null && a1 in AppStorePremiumProductIdsToPremiumBundledItems) { if (a0 != null && a1 != null) { if (a0 === a1) { return true; } if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { const r40 = AppStorePremiumProductIdsToPremiumBundledItems[a0]; if (a1 in AppStorePremiumProductIdsToPremiumBundledItems) { const r57 = AppStorePremiumProductIdsToPremiumBundledItems[a1]; return r40.numPremiumGuild === r57.numPremiumGuild && r40.premiumTier === r57.premiumTier; } throw new Error(`Invalid bundled product ID ${a1}`); } throw new Error(`Invalid bundled product ID ${a0}`); } return a0 === a1; } return a0 === a1; } export { isValidBundleProductId }; export function shouldAlwaysExcludeFromPlanSelect(a0) { return a0.isDeprecated || a0.interval === SubscriptionIntervalTypes.YEAR; } export { getSubscriptionItemsForProduct }; export function getModifySubscriptionItemsForProduct(a0, a1) { if (a0 in AppStorePremiumProductIdsToPremiumBundledItems) { const r24 = AppStorePremiumProductIdsToPremiumBundledItems[a0]; if (r24.premiumTier != null && isBoostOnlySubscription(a1)) { let c15615_0; const r40 = getItemsWithUpsertedPremiumPlanId(a1, r24.basePlanId).reverse(); const r44 = r24.additionalPlans.find((additionalPlan) => PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(additionalPlan.planId)); c15615_0 = r44; return r44 != null ? r40.map((item) => { const r7 = PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(item.planId); let r8 = item; if (r7) { r8 = { ...item, planId: c15615_0.planId, quantity: c15615_0.quantity }; } return r8; }) : r40; } return getSubscriptionItemsForProduct(a0); } throw new Error(`Invalid bundled product ID ${a0}`); } export function makeExternalPaymentGatewayPlanIdOrThrow(a0) { if (a0 == null) { throw new Error("Invalid null plan ID"); } if (a0 != null && a0 in AppStorePremiumProductIdsToPremiumBundledItems) { return a0; } const r14 = a0 + ".1"; if (r14 in AppStorePremiumProductIdsToPremiumBundledItems) { return r14; } throw new Error(`Invalid plan ID ${a0}`); } export { getProductIdFromSubscriptionItems }; export function getProductIdFromSubscription(a0, a1) { let r20; if (a0.isACOM) { let r44 = a1 ? a0.renewalMutations?.items : null; if (r44 == null) { r44 = a0.items; } r20 = getProductIdFromSubscriptionItems(r44); } else { let r10 = a1 ? a0.renewalMutations?.paymentGatewayPlanId : null; if (r10 == null) { r10 = a0.paymentGatewayPlanId; } if (r10 == null) { throw new Error("Invalid null plan ID"); } const r14 = r10 != null && r10 in AppStorePremiumProductIdsToPremiumBundledItems; r20 = r10; if (!r14) { const r22 = r10 + ".1"; const r27 = r22 in AppStorePremiumProductIdsToPremiumBundledItems; r20 = r22; if (!r27) { throw new Error(`Invalid plan ID ${r10}`); } } } return r20; }