Files
discord-decomp/utils/PremiumUtils.tsx
T
2026-11-01 12:12:55 +02:00

2339 lines
90 KiB
TypeScript

// Metro module 3835 (f3836).
import _slicedToArray from "../_bundle/_slicedToArray";
import { useMemo } from "react";
import * as _SubscriptionPlanRecord from "../records/SubscriptionPlanRecord";
import UserStore from "../stores/UserStore";
import BillingInfoStore from "../stores/billing/BillingInfoStore";
import PaymentSourceStore from "../stores/billing/PaymentSourceStore";
import SubscriptionPlanStore from "../stores/billing/SubscriptionPlanStore";
import SubscriptionStore from "../stores/billing/SubscriptionStore";
import { PriceSetAssignmentPurchaseTypes, SubscriptionStatusTypes, InvoiceStatusTypes, PaymentGateways } from "../Constants";
import { PREMIUM_PLANS, PREMIUM_GUILD_SUBSCRIPTION_PLANS, FRACTIONAL_PREMIUM_SKU_INTERVAL_COUNTS, FractionalPremiumIntervalTypes, SubscriptionPlanInfo, PremiumTypes, SubscriptionIntervalTypes, SubscriptionPlans, PREMIUM_TYPE_DISPLAY_NAME, PremiumSubscriptionSKUs, NUM_FREE_GUILD_BOOSTS_WITH_PREMIUM, PAID_SUBSCRIPTION_MAX_BILLING_RETRY_DAYS, ANNUAL_DISCOUNT_PERCENTAGE_FALLBACK, DISCOUNT_PERCENTAGE_FALLBACK, DISCOUNT_DURATION_FALLBACK, DEFAULT_APPLE_GRACE_PERIOD_DAYS, DEFAULT_GOOGLE_GRACE_PERIOD_DAYS, DEFAULT_MAX_GRACE_PERIOD_DAYS, PAID_SUBSCRIPTION_MAX_GRACE_PERIOD_DAYS, FractionalPremiumStates, PREMIUM_TIER_2_PLANS, MAX_ACCOUNT_HOLD_DAYS, MAX_PAYMENT_PROCESSING_TIME_DAYS, PREMIUM_SKU_TO_MONTHLY_PLAN, DiscountUserUsageLimitIntervalTypes, PremiumUserLimits, PREMIUM_TIER_2_REVERSE_FOLLOWUP_TRIAL_ID, USER_PREMIUM_OFFER_EXPIRES_APPROACHING_4_DAY_THRESHOLD, PREMIUM_TIER_2_TRIAL_FOR_EVERYONE_TRIAL_ID, TRIAL_FOR_EVERYONE_OFFER_EXPIRES_APPROACHING_THRESHOLD, USER_PREMIUM_OFFER_EXPIRES_APPROACHING_7_DAY_THRESHOLD, DISCOUNTS } from "../modules/premium/PremiumConstants";
import { getPremiumGroupProductName } from "../modules/premium/premium_group/PremiumGroupConstants";
import { PaymentGatewayToFriendlyName, PREPAID_PAYMENT_SOURCES, CurrencyCodes } from "../_bundle/Module505";
import Logger from "../modules/debug/Logger";
import { captureBillingException } from "./BillingUtils";
import { getBaseSubscriptionItemForSubscriptionItems } from "../modules/premium/PremiumSubscription";
import * as _PremiumTypeUtils from "./PremiumTypeUtils";
import Module38 from "../_bundle/Module38";
import * as _index_native from "../intl/index.native";
import PremiumGroup_messages from "../modules/premium/premium_group/PremiumGroup.messages";
import Module3771 from "../_bundle/Module3771";
import { dateFormat, unitsAsStrings, diffAsUnits, differenceInCalendarDays, differenceInDays } from "./DateUtils";
import openURL from "../lib/openURL";
import { formatPrice, formatRate } from "./PriceUtils";
import { roundFPCountdownUnits } from "../modules/billing/hooks/useFPDurationLeft";
import Durations from "./Durations";
import { useStateFromStores } from "../_bundle/Module589";
import { CheckoutError } from "../modules/checkout/CheckoutError";
import { formatSize } from "./FileSizeUtils";
import { canUserUse, ANIMATED_EMOJIS, EMOJIS_EVERYWHERE, SOUNDBOARD_EVERYWHERE, CUSTOM_CALL_SOUNDS, UPLOAD_LARGE_FILES, PROFILE_BADGES, INCREASED_VIDEO_UPLOAD_QUALITY, CUSTOM_DISCRIMINATOR, BOOST_DISCOUNT, ANIMATED_AVATAR, INSTALL_PREMIUM_APPLICATIONS, INCREASED_MESSAGE_LENGTH, INCREASED_GUILD_LIMIT, REDEEM_PREMIUM_PERKS, PROFILE_PREMIUM_FEATURES, APP_ICONS, PREMIUM_GUILD_MEMBER_PROFILE, CLIENT_THEMES, STREAM_HIGH_QUALITY, STREAM_MID_QUALITY, QUEST_ORB_MULTIPLIER, FREE_BOOSTS, STICKERS_EVERYWHERE, VIDEO_FILTER_ASSETS, COLLECTIBLES } from "../modules/premium/ProductCatalog";
import { getIsCrepeEnabled } from "../modules/croissant/crepe/CrepeExperiment";
import { hasPerk } from "../modules/premium/perks_state/PerksStateUtils";
import { Perk } from "../_bundle/Module1892";
import * as _PremiumFeatureUtils from "./PremiumFeatureUtils";
function $mk72812() {
return (a0) => [a0.id, a0.price];
}
function $mk72813($env) {
return (a0) => a0.currency === $env[0].toLowerCase();
}
function $mk72814($env) {
return (a0) => a0.currency === $env[0].toLowerCase();
}
function $mk72818($env) {
return (a0) => $env[0].includes(a0.planId);
}
function $mk72825($env) {
return (a0) => {
for (const item of $env[0].items) {
if (a0.planId !== item.planId) {
continue;
}
return {
...item,
...a0
};
}
return a0;
};
}
function $mk72831() {
return (a0) => a0.skuId;
}
let getDefaultPrice, getPrice, getPurchaseTypePrices, experimentalGetPrices, getServerPriceFromClientPrice, getItemPlansTotalServerPrice, getDisplayName, getPlanDescription, getNumPremiumGuildSubscriptions, getBillingGracePeriodDaysAndExpiresDate, getExpectedRenewalDate, getCoercedPremiumGuildSubscriptionStatus, isPremiumGuildSubscriptionCanceled, getFormattedPriceForPlan, getPremiumGuildIntervalPrice, getDefaultCurrency, formatTrialCtaIntervalDuration, getItemsWithUpsertedPlanIdForGroup, getMonthlyPrice, calculateMonthlyPriceEquivalentTotal, calculateDiscountPercentageForYearlyPlan, c2169_51, c2169_52, c2169_53, c2169_54, c2169_55, c2169_65;
let $mk72811 = function() {
return (a0) => PREMIUM_PLANS.has(a0.planId);
}, $mk72824 = function() {
return (a0) => PREMIUM_PLANS.has(a0.planId);
}, $mk72826 = function() {
return (a0) => !PREMIUM_PLANS.has(a0.planId);
}, $mk72830 = function() {
return (a0) => PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(a0.planId);
}, $mk72832 = function() {
return (a0, a1) => {
const r8 = _slicedToArray(FRACTIONAL_PREMIUM_SKU_INTERVAL_COUNTS[a1], 2);
const r9 = r8[0];
return a0 + (FractionalPremiumIntervalTypes.HOUR !== r9 ? FractionalPremiumIntervalTypes.DAY === r9 ? 24 : 1 : 1) * r8[1];
};
};
let env2169 = {};
export function getPremiumPlanItem(a0) {
return a0.items.find($mk72811());
}
getDefaultPrice = function getDefaultPrice(a0, r8 = false, r7 = false, currency = void 0, r6 = true) {
let defaultPaymentSourceId = PaymentSourceStore.defaultPaymentSourceId;
if (defaultPaymentSourceId == null) {
defaultPaymentSourceId = void 0;
}
const premiumTypeSubscription = SubscriptionStore.getPremiumTypeSubscription();
if (premiumTypeSubscription != null && premiumTypeSubscription.paymentSourceId != null) {
defaultPaymentSourceId = premiumTypeSubscription.paymentSourceId;
}
return getPrice(a0, r8, r7, {
paymentSourceId: defaultPaymentSourceId,
currency
}, r6);
};
getPrice = function getPrice(a0, r8 = false, isGift = false, r17 = {}, r7 = true) {
let r69;
const paymentSourceId = r17.paymentSourceId;
let currency = r17.currency;
const contextPlanPrices = r17.contextPlanPrices;
if (contextPlanPrices != null) {
const r6 = contextPlanPrices[a0];
const r1 = currency != null && r6 != null && r6.currency !== currency;
if (r6 != null && !r1) {
return {
amount: r6.amount,
currency: r6.currency,
exponent: r6.exponent,
tax: 0,
taxInclusive: false
};
}
}
if (SubscriptionPlanStore.get(a0) != null) {
let DEFAULT = PriceSetAssignmentPurchaseTypes.DEFAULT;
if (isGift) {
DEFAULT = PriceSetAssignmentPurchaseTypes.GIFT;
} else if (r8) {
DEFAULT = PriceSetAssignmentPurchaseTypes.PREMIUM_TIER_1;
}
let env13648;
const r52 = {
paymentSourceId,
purchaseType: DEFAULT,
currency
};
const r53 = env13648 = {};
const { paymentSourceId: paymentSourceId2, purchaseType, currency: currency2 } = r52;
env13648[0] = currency2;
const r59 = experimentalGetPrices(a0, {
paymentSourceId: paymentSourceId2,
purchaseType
});
if (r59.length === 0) {
c2169_53.warn(`No prices found for planId: ${a0}, paymentSourceId: ${paymentSourceId2}, purchaseType: ${purchaseType}`);
}
if (currency2 != null) {
let r72 = r59.find($mk72813(r53));
if (r72 == null) {
r72 = paymentSourceId2 != null ? experimentalGetPrices(a0, {
purchaseType
}).find($mk72814(r53)) : void 0;
}
r69 = r72;
} else {
r69 = r59[0];
}
if (r69 == null) {
const error2 = new Error("Couldn't find price");
if (r7) {
const tags = {
purchaseType: DEFAULT.toString(),
planId: a0,
currency: null
};
if (currency == null) {
currency = "unknown";
}
tags.currency = currency;
captureBillingException(error2, {
extra: {
paymentSourceId
},
tags
});
}
throw error2;
}
return r69;
}
const error = new Error("Plan not found");
if (r7) {
captureBillingException(error, {
tags: {
planId: a0,
currency: currency == null ? "unknown" : currency
},
extra: {
...r17,
isGift
}
});
}
throw error;
};
getPurchaseTypePrices = function getPurchaseTypePrices(a0, a1) {
const r16 = SubscriptionPlanStore.get(a0);
if (r16 == null) {
const error = new Error("Plan not found");
captureBillingException(error, {
tags: {
planId: a0,
purchaseType: a1.toString()
}
});
throw error;
}
if (r16.prices == null) {
throw new Error(`No prices returned for ${a0}, is your user in the experiment?`);
}
const r19 = r16.prices[a1];
if (r19 == null) {
c2169_53.info(`Purchase types: ${JSON.stringify(Object.keys(r16.prices))}`);
throw new Error(`No prices returned for purchase type ${a1} for plan ${a0}`);
}
return r19;
};
experimentalGetPrices = function experimentalGetPrices(a0, r3 = {
purchaseType: PriceSetAssignmentPurchaseTypes.DEFAULT
}) {
const { paymentSourceId, purchaseType } = r3;
const purchaseTypePrices = getPurchaseTypePrices(a0, purchaseType);
if (paymentSourceId != null) {
const r11 = purchaseTypePrices.paymentSourcePrices[paymentSourceId];
if (r11 == null) {
c2169_53.info(`Payment sources IDs: ${JSON.stringify(Object.keys(purchaseTypePrices.paymentSourcePrices))}`);
c2169_53.info(`prices: ${r11}`);
captureBillingException(new Error("Missing prices for payment source on subscription plan"), {
extra: {
paymentSourceId
},
tags: {
purchaseType: purchaseType.toString(),
planId: a0
}
});
} else if (r11.length !== 0) {
return r11;
}
}
if (purchaseTypePrices.countryPrices.prices == null) {
c2169_53.info(`countryPrices: ${JSON.stringify(purchaseTypePrices.countryPrices)}`);
const error = new Error("Missing prices for country");
captureBillingException(error, {
tags: {
countryCode: purchaseTypePrices.countryPrices.countryCode,
planId: a0
}
});
throw error;
}
return purchaseTypePrices.countryPrices.prices;
};
getServerPriceFromClientPrice = function getServerPriceFromClientPrice(a0) {
return {
amount: a0.amount,
currency: a0.currency,
exponent: a0.exponent
};
};
getItemPlansTotalServerPrice = function getItemPlansTotalServerPrice(a0, a1, a2) {
const r1 = {
currency: a1,
amount: 0,
tax: 0,
taxInclusive: false
};
const baseSubscriptionItemForSubscriptionItems = getBaseSubscriptionItemForSubscriptionItems(a0);
const r12 = baseSubscriptionItemForSubscriptionItems != null ? SubscriptionPlanInfo[baseSubscriptionItemForSubscriptionItems.planId].premiumType : void 0;
const isPremiumAtLeast = _PremiumTypeUtils.isPremiumAtLeast(r12, PremiumTypes.TIER_0);
const isPremiumAtLeast2 = _PremiumTypeUtils.isPremiumAtLeast(r12, PremiumTypes.TIER_2);
for (const item of a0) {
const r56 = PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(item.planId);
let r57 = isPremiumAtLeast2;
if (!r56) {
const r61 = PREMIUM_PLANS.has(item.planId);
r57 = r61 ? !r61 : isPremiumAtLeast;
}
const r63 = r57;
r1.amount = r1.amount + (a2 === void 0 ? getDefaultPrice(item.planId, r63, false, a1) : getPrice(item.planId, r63, false, {
paymentSourceId: a2,
currency: a1
})).amount * item.quantity;
}
return getServerPriceFromClientPrice(r1);
};
export function getInterval(a0) {
const r2 = SubscriptionPlanInfo[a0];
if (r2 != null) {
return {
intervalType: r2.interval,
intervalCount: r2.intervalCount
};
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
}
export function getIntervalString(a0, a1, a2, intervalCount = 1, r5 = false, r6 = PremiumTypes.TIER_2) {
if (!a1 && !a2) {
if (SubscriptionIntervalTypes.MONTH === a0) {
return intervalCount !== 1 ? _index_native.intl.formatToPlainString(_index_native.t["0UlZnH"], {
intervalCount
}) : _index_native.intl.string(_index_native.t.DKzs96);
}
if (SubscriptionIntervalTypes.YEAR === a0) {
return _index_native.intl.string(_index_native.t["/Q4HRN"]);
}
throw new Error("Unexpected interval");
}
if (SubscriptionIntervalTypes.MONTH === a0) {
let r124 = _index_native.intl.formatToPlainString(r6 === PremiumTypes.TIER_0 ? _index_native.t.NPKsLz : _index_native.t.poEovT, {
timeInterval: _index_native.intl.string(_index_native.t.FPybU7)
});
if (!r5) {
r124 = _index_native.intl.string(_index_native.t.Mh9bTt);
}
return r124;
}
if (SubscriptionIntervalTypes.YEAR === a0) {
let r90 = _index_native.intl.formatToPlainString(r6 === PremiumTypes.TIER_0 ? _index_native.t.NPKsLz : _index_native.t.poEovT, {
timeInterval: _index_native.intl.string(_index_native.t.tfqrhj)
});
if (!r5) {
r90 = _index_native.intl.string(_index_native.t.DRgqMo);
}
return r90;
}
throw new Error("Unexpected interval");
}
export function getIntervalStringAsNoun(a0) {
if (SubscriptionIntervalTypes.MONTH === a0) {
return _index_native.intl.string(_index_native.t.FPybU7);
}
if (SubscriptionIntervalTypes.YEAR === a0) {
return _index_native.intl.string(_index_native.t.tfqrhj);
}
throw new Error("Unexpected interval");
}
export function getPremiumType(a0) {
const r11 = SubscriptionPlanInfo[a0];
if (r11 != null) {
return r11.premiumType;
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
}
getDisplayName = function getDisplayName(a0, r5 = false, r2 = false, duration) {
if (SubscriptionPlans.PREMIUM_MONTH_TIER_0 === a0) {
return r5 ? _index_native.intl.format(_index_native.t.TZXHNj, {
duration
}) : r2 ? _index_native.intl.string(_index_native.t["81iAgs"]) : _index_native.intl.string(_index_native.t["0efVPy"]);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_0 === a0) {
return r5 ? _index_native.intl.format(_index_native.t.eqRhC7, {
duration
}) : r2 ? _index_native.intl.string(_index_native.t.UvzqY1) : _index_native.intl.string(_index_native.t.eoVuBn);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_1 === a0) {
return r2 ? _index_native.intl.string(_index_native.t["g/dH5g"]) : _index_native.intl.string(_index_native.t["7O6qSq"]);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_1 === a0) {
return r2 ? _index_native.intl.string(_index_native.t.pdZJaq) : _index_native.intl.string(_index_native.t.Md5xbi);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_2 === a0) {
return r5 ? _index_native.intl.format(_index_native.t.aI6QXz, {
duration
}) : r2 ? _index_native.intl.string(_index_native.t.SmVbHc) : _index_native.intl.string(_index_native.t.FKYNC6);
}
if (SubscriptionPlans.PREMIUM_GROUP_MONTH === a0) {
return r2 ? _index_native.intl.string(_index_native.t.SmVbHc) : _index_native.intl.formatToPlainString(PremiumGroup_messages["8bPDtb"], {
premiumGroupProductName: (0, getPremiumGroupProductName)()
});
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_2 === a0) {
return r5 ? _index_native.intl.format(_index_native.t["1wBcPi"], {
duration
}) : r2 ? _index_native.intl.string(_index_native.t.JIq4O1) : _index_native.intl.string(_index_native.t["cfu/5d"]);
}
if (SubscriptionPlans.PREMIUM_3_MONTH_TIER_2 === a0) {
return _index_native.intl.string(_index_native.t.wCbINr);
}
if (SubscriptionPlans.PREMIUM_6_MONTH_TIER_2 === a0) {
return _index_native.intl.string(_index_native.t["e3/ArU"]);
}
if (SubscriptionPlans.PREMIUM_MONTH_GUILD === a0) {
return r2 ? _index_native.intl.string(_index_native.t["6ZR3By"]) : _index_native.intl.string(_index_native.t["h80cx/"]);
}
if (SubscriptionPlans.PREMIUM_YEAR_GUILD === a0) {
return r2 ? _index_native.intl.string(_index_native.t.YDpAzZ) : _index_native.intl.string(_index_native.t.ZHkls0);
}
if (SubscriptionPlans.PREMIUM_3_MONTH_GUILD === a0) {
return _index_native.intl.string(_index_native.t.EZHHB6);
}
if (SubscriptionPlans.PREMIUM_6_MONTH_GUILD === a0) {
return _index_native.intl.string(_index_native.t.X2KDO2);
}
if (SubscriptionPlans.PREMIUM_MONTH_LEGACY === a0) {
return _index_native.intl.string(_index_native.t.PD6k79);
}
if (SubscriptionPlans.PREMIUM_YEAR_LEGACY === a0) {
return _index_native.intl.string(_index_native.t.LtJgTC);
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
};
export function getTierDisplayNameByPlanId(a0) {
const premiumType = SubscriptionPlanInfo[a0]?.premiumType;
const r5 = premiumType != null ? PREMIUM_TYPE_DISPLAY_NAME[premiumType] : null;
if (r5 != null) {
return _index_native.intl.string(r5);
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
}
getPlanDescription = function getPlanDescription({ subscription, planId: planId2, price, includePremiumGuilds, hasDiscountApplied, activeDiscountInfo, renewalInvoiceWithoutEntitlementsPreview, renewalInvoiceWithEntitlementsPreview, hasFractionalPremiumWithSub, fractionalPremiumInfo }) {
let r70, r227;
const r38 = SubscriptionPlanInfo[planId2];
const id = r38.id;
let defaultPaymentSourceId = PaymentSourceStore.defaultPaymentSourceId;
if (defaultPaymentSourceId == null) {
defaultPaymentSourceId = void 0;
}
const premiumTypeSubscription = SubscriptionStore.getPremiumTypeSubscription();
if (premiumTypeSubscription != null && premiumTypeSubscription.paymentSourceId != null) {
defaultPaymentSourceId = premiumTypeSubscription.paymentSourceId;
}
const price2 = getPrice(id, false, false, {
paymentSourceId: defaultPaymentSourceId,
currency: void 0
}, true);
const interval = r38.interval;
const r24 = formatPrice(price2.amount, price2.currency);
if (SubscriptionIntervalTypes.MONTH === interval) {
r70 = _index_native.intl.string(_index_native.t.FPybU7);
} else {
if (SubscriptionIntervalTypes.YEAR !== interval) {
throw new Error("Unexpected interval");
}
r70 = _index_native.intl.string(_index_native.t.tfqrhj);
}
const regularPrice = `${r24}/${r70}`;
const r3 = renewalInvoiceWithEntitlementsPreview != null && renewalInvoiceWithEntitlementsPreview.subtotal === 0;
const { status, renewalMutations } = subscription;
let r89 = status === SubscriptionStatusTypes.CANCELED || renewalMutations != null && (0, _SubscriptionPlanRecord.isNoneSubscription)(renewalMutations.planId) && !subscription.isPurchasedExternally;
if (!r89) {
let r2 = subscription.paymentSourceId == null && !subscription.isPurchasedExternally;
if (r2) {
const currentUser = UserStore.getCurrentUser();
r2 = !(currentUser == null ? void 0 : currentUser.hasFreePremium());
}
if (r2) {
r2 = !r3;
}
r89 = r2;
}
const r101 = price != null && subscription.paymentGateway == null;
const r105 = subscription.status === SubscriptionStatusTypes.UNPAID && subscription.latestInvoice !== null && subscription.latestInvoice?.status === InvoiceStatusTypes.OPEN;
const r112 = r89 ? SubscriptionStatusTypes.CANCELED : r105 ? SubscriptionStatusTypes.UNPAID : subscription.status;
let r114 = renewalInvoiceWithoutEntitlementsPreview?.taxInclusive;
if (r114 == null) {
r114 = subscription.latestInvoice?.taxInclusive;
}
if (r114 == null) {
r114 = true;
}
let r119 = 0;
if (includePremiumGuilds) {
let env13650;
const additionalPlans = subscription.additionalPlans;
const r120 = env13650 = {};
env13650[0] = void 0;
const planIdsForSkus = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13650[0] = planIdsForSkus;
Module38(planIdsForSkus != null, "Missing guildSubscriptionPlanIds");
const r131 = additionalPlans.find($mk72818(r120));
r119 = r131 != null ? r131.quantity : 0;
}
const num = NUM_FREE_GUILD_BOOSTS_WITH_PREMIUM + r119;
let r143 = r101 ? r114 ? _index_native.intl.format(_index_native.t["cd+hqB"], {
price
}) : _index_native.intl.format(_index_native.t.NUkcpF, {
price
}) : _index_native.intl.string(_index_native.t.zYx3Y6);
let r161 = r101 ? r114 ? _index_native.intl.format(_index_native.t.VsKcFB, {
price
}) : _index_native.intl.format(_index_native.t.hJ5xEX, {
price
}) : _index_native.intl.string(_index_native.t["8rSipI"]);
let r180 = r101 ? r114 ? _index_native.intl.format(_index_native.t["jRy6/J"], {
price,
num
}) : _index_native.intl.format(_index_native.t.tTNE8M, {
price,
num
}) : _index_native.intl.format(_index_native.t["U+z/HJ"], {
num
});
if (SubscriptionPlans.PREMIUM_MONTH_TIER_0 !== planId2 && SubscriptionPlans.PREMIUM_YEAR_TIER_0 !== planId2) {
if (SubscriptionPlans.PREMIUM_MONTH_TIER_1 !== planId2 && SubscriptionPlans.PREMIUM_YEAR_TIER_1 !== planId2) {
if (SubscriptionPlans.PREMIUM_MONTH_TIER_2 !== planId2 && SubscriptionPlans.PREMIUM_YEAR_TIER_2 !== planId2 && SubscriptionPlans.PREMIUM_3_MONTH_TIER_2 !== planId2 && SubscriptionPlans.PREMIUM_6_MONTH_TIER_2 !== planId2 && SubscriptionPlans.PREMIUM_GROUP_MONTH !== planId2) {
throw new Error(`Invalid planId ${planId2}`);
}
if (SubscriptionStatusTypes.CANCELED === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t.xoFgRh, {
price,
num
}) : _index_native.intl.format(_index_native.t.nXdbKo, {
price,
num
}) : _index_native.intl.format(_index_native.t.EcSdRH, {
num
});
}
if (SubscriptionStatusTypes.ACCOUNT_HOLD === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t["5C/0QG"], {
price,
num
}) : _index_native.intl.format(_index_native.t.xfYkhu, {
price,
num
}) : _index_native.intl.format(_index_native.t.ivjxcn, {
num
});
}
if (SubscriptionStatusTypes.UNPAID === r112) {
return _index_native.intl.format(_index_native.t["0HopYf"], {
num
});
}
if (SubscriptionStatusTypes.PAUSE_PENDING === r112) {
const pauseDuration = subscription.pauseEndsAt != null ? Module3771(subscription.pauseEndsAt).diff(subscription.currentPeriodEnd, "days") : null;
return pauseDuration != null ? _index_native.intl.format(_index_native.t.WUfOD5, {
pauseDate: subscription.currentPeriodEnd,
pauseDuration
}) : _index_native.intl.format(_index_native.t.VlWufv, {
pauseDate: subscription.currentPeriodEnd
});
}
if (SubscriptionStatusTypes.PAUSED === r112) {
if (!hasFractionalPremiumWithSub) {
r180 = _index_native.intl.format(_index_native.t["6RTdZA"], {
resumeDate: subscription.pauseEndsAt
});
}
return r180;
}
if (SubscriptionStatusTypes.BILLING_RETRY === r112) {
return _index_native.intl.format(_index_native.t["IlJ/HV"], {
endDate: Module3771(subscription.currentPeriodStart).add(PAID_SUBSCRIPTION_MAX_BILLING_RETRY_DAYS, "days").toDate()
});
}
if (SubscriptionStatusTypes.PAST_DUE === r112) {
return _index_native.intl.format(_index_native.t["d+0vwo"], {
endDate: dateFormat(getBillingGracePeriodDaysAndExpiresDate(subscription).expiresDate, "LL"),
onClick: () => {
openURL("https://support.discord.com/hc/articles/23082866222871");
}
});
}
let r212 = r180;
if (hasDiscountApplied) {
if (planId2 === SubscriptionPlans.PREMIUM_YEAR_TIER_2) {
const z2oQtA = _index_native.t.z2oQtA;
let percent3 = activeDiscountInfo?.percentage;
if (percent3 == null) {
percent3 = ANNUAL_DISCOUNT_PERCENTAGE_FALLBACK;
}
r227 = _index_native.intl.format(z2oQtA, {
percent: percent3,
regularPrice,
renewalDate: getExpectedRenewalDate(subscription, fractionalPremiumInfo)
});
} else if (r114) {
const r228 = _index_native.t["3ZiutU"];
let percent2 = activeDiscountInfo?.percentage;
if (percent2 == null) {
percent2 = DISCOUNT_PERCENTAGE_FALLBACK;
}
let numMonths2 = activeDiscountInfo?.duration;
if (numMonths2 == null) {
numMonths2 = DISCOUNT_DURATION_FALLBACK;
}
r227 = _index_native.intl.formatToPlainString(r228, {
percent: percent2,
regularPrice,
numMonths: numMonths2
});
} else {
const r221 = _index_native.t["G6+XOT"];
let percent = activeDiscountInfo?.percentage;
if (percent == null) {
percent = DISCOUNT_PERCENTAGE_FALLBACK;
}
let numMonths = activeDiscountInfo?.duration;
if (numMonths == null) {
numMonths = DISCOUNT_DURATION_FALLBACK;
}
r227 = _index_native.intl.formatToPlainString(r221, {
percent,
regularPrice,
numMonths
});
}
r212 = r227;
}
return r212;
}
if (SubscriptionStatusTypes.CANCELED === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t.cXy8Bp, {
price
}) : _index_native.intl.format(_index_native.t["C/XsHt"], {
price
}) : _index_native.intl.string(_index_native.t.K6tYFa);
}
if (SubscriptionStatusTypes.ACCOUNT_HOLD === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t.HBkIBi, {
price
}) : _index_native.intl.format(_index_native.t.ZsO1Sx, {
price
}) : _index_native.intl.format(_index_native.t["0+/WH7"], {});
}
if (SubscriptionStatusTypes.UNPAID === r112) {
return _index_native.intl.format(_index_native.t.McIzwj, {});
}
if (SubscriptionStatusTypes.PAUSE_PENDING === r112) {
const pauseDuration2 = subscription.pauseEndsAt != null ? Module3771(subscription.pauseEndsAt).diff(subscription.currentPeriodEnd, "days") : null;
return pauseDuration2 != null ? _index_native.intl.format(_index_native.t.WUfOD5, {
pauseDate: subscription.currentPeriodEnd,
pauseDuration: pauseDuration2
}) : _index_native.intl.format(_index_native.t.VlWufv, {
pauseDate: subscription.currentPeriodEnd
});
}
if (SubscriptionStatusTypes.PAUSED === r112) {
if (!hasFractionalPremiumWithSub) {
r161 = _index_native.intl.format(_index_native.t["6RTdZA"], {
resumeDate: subscription.pauseEndsAt
});
}
return r161;
}
if (SubscriptionStatusTypes.PAST_DUE === r112) {
return _index_native.intl.format(_index_native.t["d+0vwo"], {
endDate: dateFormat(getBillingGracePeriodDaysAndExpiresDate(subscription).expiresDate, "LL"),
onClick: () => {
openURL("https://support.discord.com/hc/articles/23082866222871");
}
});
}
return r161;
}
if (SubscriptionStatusTypes.CANCELED === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t["USi/nc"], {
price
}) : _index_native.intl.format(_index_native.t["FS//l2"], {
price
}) : _index_native.intl.string(_index_native.t.JshLzq);
}
if (SubscriptionStatusTypes.ACCOUNT_HOLD === r112) {
return r101 ? r114 ? _index_native.intl.format(_index_native.t["5mv+2i"], {
price
}) : _index_native.intl.format(_index_native.t.nkAEfZ, {
price
}) : _index_native.intl.format(_index_native.t.SsLIXS, {});
}
if (SubscriptionStatusTypes.UNPAID === r112) {
return _index_native.intl.format(_index_native.t.cmkbFB, {});
}
if (SubscriptionStatusTypes.PAUSE_PENDING === r112) {
const pauseDuration3 = subscription.pauseEndsAt != null ? Module3771(subscription.pauseEndsAt).diff(subscription.currentPeriodEnd, "days") : null;
return pauseDuration3 != null ? _index_native.intl.format(_index_native.t.WUfOD5, {
pauseDate: subscription.currentPeriodEnd,
pauseDuration: pauseDuration3
}) : _index_native.intl.format(_index_native.t.VlWufv, {
pauseDate: subscription.currentPeriodEnd
});
}
if (SubscriptionStatusTypes.PAUSED === r112) {
if (!hasFractionalPremiumWithSub) {
r143 = _index_native.intl.format(_index_native.t["6RTdZA"], {
resumeDate: subscription.pauseEndsAt
});
}
return r143;
}
if (SubscriptionStatusTypes.PAST_DUE === r112) {
return _index_native.intl.format(_index_native.t["d+0vwo"], {
endDate: dateFormat(getBillingGracePeriodDaysAndExpiresDate(subscription).expiresDate, "LL"),
onClick: () => {
openURL("https://support.discord.com/hc/articles/23082866222871");
}
});
}
return r143;
};
export function getPremiumPlanOptions({ skuId, isPremium, defaultPlanId }) {
let r32;
if (skuId != null && isPremium) {
const r4 = defaultPlanId !== void 0 ? skuId === SubscriptionPlanInfo[defaultPlanId].skuId ? defaultPlanId : void 0 : void 0;
if (PremiumSubscriptionSKUs.TIER_0 === skuId) {
r32 = [SubscriptionPlans.PREMIUM_YEAR_TIER_0, SubscriptionPlans.PREMIUM_MONTH_TIER_0];
} else if (PremiumSubscriptionSKUs.TIER_1 === skuId) {
r32 = [SubscriptionPlans.PREMIUM_MONTH_TIER_1];
} else {
if (PremiumSubscriptionSKUs.TIER_2 !== skuId) {
if (PremiumSubscriptionSKUs.GUILD === skuId) {
return [];
}
throw new Error(`Unexpected SKU: ${skuId}`);
}
r32 = [SubscriptionPlans.PREMIUM_YEAR_TIER_2, SubscriptionPlans.PREMIUM_MONTH_TIER_2];
}
if (r4 !== void 0) {
r32.splice(r32.indexOf(r4), 1);
r32.unshift(r4);
}
return r32;
}
return [];
}
getNumPremiumGuildSubscriptions = function getNumPremiumGuildSubscriptions(a0) {
let env13651;
const r3 = env13651 = {};
const planIdsForSkus = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13651[0] = planIdsForSkus;
Module38(planIdsForSkus != null, "Missing guildSubscriptionPlanIds");
const r20 = a0.find($mk72818(r3));
return r20 != null ? r20.quantity : 0;
};
getBillingGracePeriodDaysAndExpiresDate = function getBillingGracePeriodDaysAndExpiresDate(a0) {
if (a0.isPurchasedViaApple) {
if (a0.metadata?.apple_grace_period_expires_date != null) {
const expiresDate2 = Module3771(a0.metadata.apple_grace_period_expires_date);
return {
days: Module3771.duration(expiresDate2.diff(a0.currentPeriodStart)).days(),
expiresDate: expiresDate2
};
}
}
if (a0.isPurchasedViaGoogle) {
if (a0.metadata?.google_grace_period_expires_date != null) {
if (a0.metadata?.google_original_expires_date != null) {
const expiresDate = Module3771(a0.metadata.google_grace_period_expires_date);
return {
days: Module3771.duration(expiresDate.diff(Module3771(a0.metadata.google_original_expires_date))).days(),
expiresDate
};
}
}
}
if (a0.isPurchasedExternally) {
const days2 = a0.isPurchasedViaApple ? DEFAULT_APPLE_GRACE_PERIOD_DAYS : DEFAULT_GOOGLE_GRACE_PERIOD_DAYS;
return {
days: days2,
expiresDate: Module3771(a0.currentPeriodStart).add(days2, "days")
};
}
if (a0.metadata?.grace_period_expires_date != null) {
return {
days: Module3771(a0.metadata?.grace_period_expires_date).diff(a0.currentPeriodStart, "days"),
expiresDate: Module3771(a0.metadata.grace_period_expires_date)
};
}
const days = a0.paymentSourceId == null ? DEFAULT_MAX_GRACE_PERIOD_DAYS : PAID_SUBSCRIPTION_MAX_GRACE_PERIOD_DAYS;
return {
days,
expiresDate: Module3771(a0.currentPeriodStart).add(days, "days")
};
};
getExpectedRenewalDate = function getExpectedRenewalDate(a0, a1) {
const date = new Date(a0.currentPeriodEnd);
const r13 = a1 == null || a0.isBoostOnly || a0.hasAnyPremiumGroup;
let r15 = date;
if (!r13) {
const unactivatedUnits = a1.unactivatedUnits;
const r7 = Module3771(date);
r15 = (unactivatedUnits.length > 0 ? r7.add(unactivatedUnits.map($mk72831()).reduce($mk72832(), 0), "hours") : r7).toDate();
}
return r15;
};
export function getBillingInformationString(a0, a1, r4 = null, r9 = false, r6 = {
isFractionalPremiumActive: false,
fetched: true,
fractionalState: FractionalPremiumStates.NONE,
startsAt: Module3771(0),
endsAt: Module3771(0),
currentEntitlementId: "",
currentEntitlementEndsAt: Module3771(0),
unactivatedUnits: []
}) {
let r43, r44, r45, r142, r200, r212, r235, r310, r314, r351, PAYMENT_SOURCE_MANAGEMENT, PAYMENT_SOURCE_MANAGEMENT2, SUBSCRIPTION_MANAGEMENT, U2hb3W, ZlWXgR, intl2, intl3, price;
const r36 = r4 !== null ? a0.status === SubscriptionStatusTypes.PAST_DUE ? r4 : a1 : a1;
if (r9) {
price = formatPrice(r36.invoiceItems.filter((invoiceItem) => PREMIUM_TIER_2_PLANS.has(invoiceItem.subscriptionPlanId)).map((item) => item.amount).reduce((acc, item) => item + acc, 0), r36.currency);
r43 = dependencyMap;
r44 = r43;
r45 = require;
} else {
price = formatPrice(r36.total, r36.currency);
r43 = dependencyMap;
r44 = r43;
r45 = require;
}
const currentUser = UserStore.getCurrentUser();
if (currentUser == null ? void 0 : currentUser.isOnReverseTrial()) {
const trialEnd = r6.currentEntitlementEndsAt != null ? r6.currentEntitlementEndsAt.toDate() : a0.currentPeriodEnd;
return r45(r44[17]).intl.format(r45(r44[17]).t["7ZS2m1"], {
trialEnd
});
}
if (a0.status === SubscriptionStatusTypes.CANCELED) {
return r45(r44[17]).intl.format(r45(r44[17]).t["Whp/qk"], {
endDate: a1.subscriptionPeriodStart
});
}
if (a0.status === SubscriptionStatusTypes.PAUSE_PENDING) {
return r45(r44[17]).intl.format(r45(r44[17]).t.uBLUGU, {
pauseDate: a0.currentPeriodEnd,
resumeDate: a0.pauseEndsAt
});
}
if (a0.status === SubscriptionStatusTypes.PAUSED) {
if (r6.fractionalState !== FractionalPremiumStates.NONE) {
r351 = r45(r44[17]).intl.format(r45(r44[17]).t.Q18lRK, {
renewalDate: r6.endsAt.toDate(),
price
});
} else if (a0.pauseEndsAt == null) {
const intl6 = r45(r44[17]).intl;
r351 = r9 ? intl6.format(r45(r44[17]).t.KTYQCg, {
planName: r45(r44[17]).intl.string(r45(r44[17]).t.Ipxkog),
price
}) : intl6.string(r45(r44[17]).t.fMz6Lg);
} else {
const intl5 = r45(r44[17]).intl;
const r347 = r45(r44[17]).t;
r351 = r9 ? intl5.format(r347.zcgtzf, {
planName: r45(r44[17]).intl.string(r45(r44[17]).t.Ipxkog),
resumeDate: a0.pauseEndsAt,
price
}) : intl5.format(r347["V8+l6k"], {
resumeDate: a0.pauseEndsAt
});
}
return r351;
}
if (a0.status === SubscriptionStatusTypes.PAST_DUE) {
let expiresDate = getBillingGracePeriodDaysAndExpiresDate(a0).expiresDate;
if (a0.isPurchasedViaGoogle && a0.metadata?.google_grace_period_expires_date != null) {
expiresDate = importDefault(r44[19])(a0.metadata.google_grace_period_expires_date);
}
if (a0.isPurchasedViaApple && a0.metadata?.apple_grace_period_expires_date != null) {
expiresDate = importDefault(r44[19])(a0.metadata.apple_grace_period_expires_date);
}
const isPurchasedExternally = a0.isPurchasedExternally;
const intl4 = r45(r44[17]).intl;
const r305 = r45(r44[17]).t;
if (isPurchasedExternally) {
L84: {
U2hb3W = r305.U2hb3W;
r314 = {
endDate: expiresDate.toDate(),
paymentGatewayName: PaymentGatewayToFriendlyName[a0.paymentGateway],
paymentSourceLink: null
};
const paymentGateway3 = a0.paymentGateway;
if (PaymentGateways.APPLE_PARTNER !== paymentGateway3 && PaymentGateways.APPLE_ADVANCED_COMMERCE !== paymentGateway3 && PaymentGateways.APPLE !== paymentGateway3) {
if (PaymentGateways.GOOGLE === paymentGateway3) {
PAYMENT_SOURCE_MANAGEMENT2 = c2169_52.PAYMENT_SOURCE_MANAGEMENT;
break L84;
}
throw new Error(`Invalid external payment gateway ${paymentGateway3}`);
}
PAYMENT_SOURCE_MANAGEMENT2 = c2169_51.PAYMENT_SOURCE_MANAGEMENT;
}
r314.paymentSourceLink = PAYMENT_SOURCE_MANAGEMENT2;
r310 = intl4.format(U2hb3W, r314);
} else {
r310 = intl4.format(r305.qEIzyi, {
endDate: expiresDate.toDate(),
price
});
}
return r310;
}
if (a0.status === SubscriptionStatusTypes.BILLING_RETRY) {
return r45(r44[17]).intl.format(r45(r44[17]).t.EMTLOT, {
endDate: importDefault(r44[19])(a0.currentPeriodStart).add(PAID_SUBSCRIPTION_MAX_BILLING_RETRY_DAYS, "days").toDate(),
price
});
}
if (a0.status === SubscriptionStatusTypes.ACCOUNT_HOLD) {
if (a0.isPurchasedViaGoogle && !r45(r44[23]).isGooglePlayBillingSupported()) {
L59: {
intl3 = r45(r44[17]).intl;
r200 = r45(r44[17]).t["dtcxw+"];
r212 = {
endDate: importDefault(r44[19])(a0.currentPeriodStart).add(MAX_ACCOUNT_HOLD_DAYS, "days").toDate(),
paymentGatewayName: PaymentGatewayToFriendlyName[a0.paymentGateway],
paymentSourceLink: null
};
const paymentGateway2 = a0.paymentGateway;
if (PaymentGateways.APPLE_PARTNER !== paymentGateway2 && PaymentGateways.APPLE_ADVANCED_COMMERCE !== paymentGateway2 && PaymentGateways.APPLE !== paymentGateway2) {
if (PaymentGateways.GOOGLE === paymentGateway2) {
PAYMENT_SOURCE_MANAGEMENT = c2169_52.PAYMENT_SOURCE_MANAGEMENT;
break L59;
}
throw new Error(`Invalid external payment gateway ${paymentGateway2}`);
}
PAYMENT_SOURCE_MANAGEMENT = c2169_51.PAYMENT_SOURCE_MANAGEMENT;
}
r212.paymentSourceLink = PAYMENT_SOURCE_MANAGEMENT;
r235 = intl3.format(r200, r212);
} else {
r235 = r45(r44[17]).intl.format(r45(r44[17]).t.EMTLOT, {
endDate: importDefault(r44[19])(a0.currentPeriodStart).add(MAX_ACCOUNT_HOLD_DAYS, "days").toDate(),
price
});
}
return r235;
}
let r74 = a0.paymentSourceId != null;
if (r74) {
const paymentSourceId = a0.paymentSourceId;
const r76 = paymentSourceId == null;
let r77 = false;
if (!r76) {
const paymentSource = PaymentSourceStore.getPaymentSource(paymentSourceId);
r77 = paymentSource != null && PREPAID_PAYMENT_SOURCES.has(paymentSource.type);
}
r74 = r77;
}
if (r74) {
return r45(r44[17]).intl.format(r45(r44[17]).t.awpB0C, {
prepaidEndDate: a0.currentPeriodEnd
});
}
if (a0.status === SubscriptionStatusTypes.UNPAID) {
return r45(r44[17]).intl.format(r45(r44[17]).t.CzTKom, {
maxProcessingTimeInDays: MAX_PAYMENT_PROCESSING_TIME_DAYS
});
}
if (a0.isPurchasedExternally) {
L47: {
intl2 = r45(r44[17]).intl;
ZlWXgR = r45(r44[17]).t.ZlWXgR;
r142 = {
renewalDate: a1.subscriptionPeriodStart,
paymentGatewayName: PaymentGatewayToFriendlyName[a0.paymentGateway],
subscriptionManagementLink: null
};
const paymentGateway = a0.paymentGateway;
if (PaymentGateways.APPLE_PARTNER !== paymentGateway && PaymentGateways.APPLE_ADVANCED_COMMERCE !== paymentGateway && PaymentGateways.APPLE !== paymentGateway) {
if (PaymentGateways.GOOGLE === paymentGateway) {
SUBSCRIPTION_MANAGEMENT = c2169_52.SUBSCRIPTION_MANAGEMENT;
break L47;
}
throw new Error(`Invalid external payment gateway ${paymentGateway}`);
}
SUBSCRIPTION_MANAGEMENT = c2169_51.SUBSCRIPTION_MANAGEMENT;
}
r142.subscriptionManagementLink = SUBSCRIPTION_MANAGEMENT;
return intl2.format(ZlWXgR, r142);
}
const date = new Date(a1.subscriptionPeriodStart);
const r92 = a0.isBoostOnly || a0.hasAnyPremiumGroup;
let renewalDate = date;
if (!r92) {
const unactivatedUnits = r6.unactivatedUnits;
const r99 = importDefault(r43[19])(date);
renewalDate = (unactivatedUnits.length > 0 ? r99.add(unactivatedUnits.map($mk72831()).reduce($mk72832(), 0), "hours") : r99).toDate();
}
const intl = r45(r44[17]).intl;
const r118 = r45(r44[17]).t;
return r9 ? intl.format(r118.Vl3cED, {
planName: r45(r44[17]).intl.string(r45(r44[17]).t.Ipxkog),
renewalDate,
price
}) : intl.format(r118.Q18lRK, {
renewalDate,
price
});
}
export function extendDateWithUnconsumedFractionalPremium(a0, a1, a2, a3) {
const r9 = Module3771(a3 ? void 0 : a0);
const r13 = a1.length > 0 ? r9.add(a1.map($mk72831()).reduce($mk72832(), 0), "hours") : r9;
let r21 = r13;
if (!a3) {
r21 = r13;
if (a2 !== void 0) {
const r29 = a2.diff(Module3771(), "hours", true);
r21 = r29 > 0 ? r13.add(r29, "hours") : r13;
}
}
return r21.toDate();
}
export function getUnactivatedFractionalPremiumDurationString(a0) {
const r10 = a0.unactivatedUnits.map($mk72831()).reduce($mk72832(), 0);
if (r10 > 0 && a0.fractionalState === FractionalPremiumStates.NONE) {
const r25 = {
days: _index_native.t.fYmirx,
hours: _index_native.t["C3RO+g"],
minutes: _index_native.t.r77oHc
};
return unitsAsStrings(roundFPCountdownUnits(diffAsUnits(0, r10 * Durations.Millis.HOUR)), r25);
}
return "";
}
export function isSwitchingPlansDisabled(a0) {
return a0.renewalMutations != null || a0.trialEndsAt != null || a0.status === SubscriptionStatusTypes.PAST_DUE;
}
export function getSwitchingPlansDisabledMessage(a0) {
let r10 = a0.renewalMutations != null ? a0.renewalMutations.planId !== a0.planId ? _index_native.intl.string(_index_native.t["0rzJ4J"]) : _index_native.intl.string(_index_native.t["9dLQ0/"]) : null;
if (a0.trialEndsAt != null) {
r10 = _index_native.intl.string(_index_native.t.a9Mdb3);
}
return r10;
}
getCoercedPremiumGuildSubscriptionStatus = function getCoercedPremiumGuildSubscriptionStatus({ renewalMutations, additionalPlans, status }) {
let env13653;
const r17 = env13653 = {};
env13653[0] = void 0;
const planIdsForSkus = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13653[0] = planIdsForSkus;
Module38(planIdsForSkus != null, "Missing guildSubscriptionPlanIds");
const r26 = additionalPlans.find($mk72818(r17));
const r28 = r26 != null ? r26.quantity : 0;
const r29 = renewalMutations != null;
let r30 = null;
if (r29) {
let env13654;
const additionalPlans2 = renewalMutations.additionalPlans;
const r32 = env13654 = {};
env13654[0] = void 0;
const planIdsForSkus2 = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13654[0] = planIdsForSkus2;
Module38(planIdsForSkus2 != null, "Missing guildSubscriptionPlanIds");
const r41 = additionalPlans2.find($mk72818(r32));
r30 = r41 != null ? r41.quantity : 0;
}
return r30 === 0 ? r28 !== 0 ? SubscriptionStatusTypes.CANCELED : status : status;
};
isPremiumGuildSubscriptionCanceled = function isPremiumGuildSubscriptionCanceled(a0) {
return a0.isPurchasedExternally ? a0.status === SubscriptionStatusTypes.CANCELED : getCoercedPremiumGuildSubscriptionStatus(a0) === SubscriptionStatusTypes.CANCELED;
};
getFormattedPriceForPlan = function getFormattedPriceForPlan(a0, a1, a2, r7 = false) {
let r15;
if (a1 != null) {
try {
r15 = getPrice(a0.id, false, r7, a1);
} catch ($e) {
r15 = getDefaultPrice(a0.id, false, r7);
}
} else {
r15 = getDefaultPrice(a0.id, false, r7);
}
const r28 = formatPrice(r15.amount, r15.currency);
return a0.currency !== CurrencyCodes.USD && a2 === true ? r28.concat("*") : r28;
};
export function getPlanIdFromInvoice(a0, a1) {
let subscriptionPlanId;
const planId2 = a0.planId;
if (a0.status !== SubscriptionStatusTypes.CANCELED && a0.status !== SubscriptionStatusTypes.PAUSE_PENDING) {
L8: {
L7: {
Module38(a1 != null, "Expected invoicePreview");
const r21 = a1.invoiceItems.find((invoiceItem) => c2169_65.has(invoiceItem.subscriptionPlanId));
if (r21 != null && !(0, _SubscriptionPlanRecord.isNoneSubscription)(r21.subscriptionPlanId)) {
if (a0.renewalMutations != null && a0.renewalMutations.planId !== a0.planId) {
break L7;
}
subscriptionPlanId = r21.subscriptionPlanId;
break L8;
}
}
subscriptionPlanId = a0.planId;
}
return subscriptionPlanId;
}
return planId2;
}
export function getStatusFromInvoice(a0, a1) {
const status = a0.status;
if (a0.status !== SubscriptionStatusTypes.CANCELED && a0.status !== SubscriptionStatusTypes.PAUSE_PENDING) {
Module38(a1 != null, "Expected invoicePreview");
const r21 = a1.invoiceItems.find((invoiceItem) => c2169_65.has(invoiceItem.subscriptionPlanId));
return r21 == null || (0, _SubscriptionPlanRecord.isNoneSubscription)(r21.subscriptionPlanId) ? SubscriptionStatusTypes.CANCELED : status;
}
return status;
}
export function isBaseSubscriptionCanceled(a0) {
const { status, renewalMutations } = a0;
return status === SubscriptionStatusTypes.CANCELED || renewalMutations != null && (0, _SubscriptionPlanRecord.isNoneSubscription)(renewalMutations.planId) && !a0.isPurchasedExternally;
}
getPremiumGuildIntervalPrice = function getPremiumGuildIntervalPrice(a0, a1, a2, a3) {
const r6 = a1 != null ? {
paymentSourceId: a1,
currency: a2
} : {
country: BillingInfoStore.ipCountryCodeWithFallback,
currency: a2
};
const r18 = SubscriptionPlanStore.get(a0);
if (r18 == null) {
const error2 = new Error("Unsupported plan");
captureBillingException(error2, {
tags: {
planId: a0
}
});
throw error2;
}
const forSkuAndInterval = SubscriptionPlanStore.getForSkuAndInterval(PremiumSubscriptionSKUs.GUILD, r18.interval, r18.intervalCount);
if (forSkuAndInterval == null) {
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
}
return getPrice(forSkuAndInterval.id, _PremiumTypeUtils.isPremium(a3), false, r6);
};
export function getBillingReviewSubheader(a0, a1, a2) {
let id;
L8: {
id = a1.id;
if (a0 != null) {
if (SubscriptionPlans.PREMIUM_MONTH_TIER_0 === id) {
return _index_native.intl.string(_index_native.t["0ggVqN"]);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_0 === id) {
return _index_native.intl.string(_index_native.t["jm+ZQw"]);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_1 === id) {
return _index_native.intl.string(_index_native.t.uph4Jx);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_1 === id) {
return _index_native.intl.string(_index_native.t["D/l7Yt"]);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_2 !== id && SubscriptionPlans.PREMIUM_GROUP_MONTH !== id) {
if (SubscriptionPlans.PREMIUM_YEAR_TIER_2 === id) {
return _index_native.intl.string(_index_native.t.G0mISV);
}
break L8;
}
return _index_native.intl.string(_index_native.t["5l1MuV"]);
}
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_0 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t["/G3aKw"]);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_0 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t["2eQpsL"]);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_1 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t.gueLg5);
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_1 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t["MhH/vW"]);
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_2 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t.LQVQIq);
}
if (SubscriptionPlans.PREMIUM_GROUP_MONTH === id) {
return _index_native.intl.formatToPlainString(PremiumGroup_messages.LwdrNi, {
premiumGroupProductName: (0, getPremiumGroupProductName)()
});
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_2 === id) {
return a2 ? _index_native.intl.string(_index_native.t.cRCCJ3) : _index_native.intl.string(_index_native.t["0nfg1x"]);
}
if (SubscriptionPlans.PREMIUM_3_MONTH_TIER_2 !== id && SubscriptionPlans.PREMIUM_6_MONTH_TIER_2 !== id) {
if (SubscriptionPlans.NONE_MONTH !== id && SubscriptionPlans.NONE_YEAR !== id && SubscriptionPlans.NONE_3_MONTH !== id && SubscriptionPlans.NONE_6_MONTH !== id && SubscriptionPlans.PREMIUM_MONTH_GUILD !== id && SubscriptionPlans.PREMIUM_YEAR_GUILD !== id && SubscriptionPlans.PREMIUM_3_MONTH_GUILD !== id && SubscriptionPlans.PREMIUM_6_MONTH_GUILD !== id) {
const error = new Error("User is purchasing an unsupported plan");
captureBillingException(error, {
tags: {
planId: id
}
});
throw error;
}
return _index_native.intl.string(_index_native.t.eUEeCt);
}
return _index_native.intl.formatToPlainString(_index_native.t.BCD4fT, {
intervalCount: a1.intervalCount
});
}
export function getIntervalForInvoice(a0) {
const r9 = SubscriptionPlanStore.get(a0.invoiceItems[0].subscriptionPlanId);
Module38(r9 != null, "Missing subscriptionPlan");
return {
intervalType: r9.interval,
intervalCount: r9.intervalCount
};
}
getDefaultCurrency = function getDefaultCurrency() {
let currency;
CurrencyCodes.USD;
try {
currency = getDefaultPrice(SubscriptionPlans.PREMIUM_MONTH_TIER_2, false, false, void 0, false).currency;
} catch ($e) {}
return currency;
};
formatTrialCtaIntervalDuration = function formatTrialCtaIntervalDuration({ intervalType = SubscriptionIntervalTypes.MONTH, intervalCount = 1 }) {
const price = formatPrice(0, getDefaultCurrency(), {
maximumFractionDigits: 0,
minimumFractionDigits: 0
});
if (SubscriptionIntervalTypes.DAY === intervalType) {
return intervalCount >= 7 && intervalCount % 7 === 0 ? _index_native.intl.formatToPlainString(_index_native.t.C6i5Jt, {
weeks: intervalCount / 7,
price
}) : _index_native.intl.formatToPlainString(_index_native.t.cR9ifw, {
days: intervalCount,
price
});
}
if (SubscriptionIntervalTypes.MONTH === intervalType) {
return _index_native.intl.formatToPlainString(_index_native.t["8FZfNo"], {
months: intervalCount,
price
});
}
if (SubscriptionIntervalTypes.YEAR === intervalType) {
return _index_native.intl.formatToPlainString(_index_native.t.xzAcST, {
years: intervalCount,
price
});
}
throw new Error("Unsupported interval duration.");
};
getItemsWithUpsertedPlanIdForGroup = function getItemsWithUpsertedPlanIdForGroup(a0, a1, a2, a3) {
let c13656_3;
const planId = a1;
const quantity = a2;
if (a3.has(a1)) {
c13656_3 = false;
let r26 = a0.renewalMutations?.items;
if (r26 == null) {
r26 = a0.items;
}
const r29 = r26.map((item) => {
const r8 = a3.has(item.planId);
let r9 = item;
if (r8) {
c13656_3 = true;
r9 = {
...item,
quantity,
planId
};
}
return r9;
});
if (!c13656_3) {
const r31 = {
planId: a1,
quantity: a2
};
const r35 = a0.items.find((item) => item.planId === planId);
if (r35 != null) {
r31.id = r35.id;
}
r29.push(r31);
}
return r29.filter((item) => item.quantity !== 0);
}
throw new CheckoutError({
message: "Expected planId in group",
extraSentryInformation: {
newPlanId: a1,
planGroup: a3
}
});
};
export function getGuildBoostPlanItem(a0) {
return a0 != null ? a0.items.find($mk72830()) : null;
}
export function isBoostOnlySubscription(a0) {
return a0 != null && a0.items.find($mk72811()) == null && (a0 == null ? null : a0.items.find($mk72830())) != null;
}
export function getPremiumSkuIdForSubscription(a0) {
const r4 = a0 != null ? a0.items.find($mk72811()) : null;
const r12 = r4 != null;
let r13 = null;
if (r12) {
const planId2 = r4.planId;
const r15 = SubscriptionPlanInfo[planId2];
if (r15 == null) {
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: planId2
}
});
throw error;
}
r13 = r15.skuId;
}
return r13;
}
export function getPremiumTypeFromSubscription(a0) {
if (a0 != null) {
const r13 = a0.items.find($mk72811());
if (r13 != null) {
const planId2 = r13.planId;
const r15 = SubscriptionPlanInfo[planId2];
if (r15 != null) {
return r15.premiumType;
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: planId2
}
});
throw error;
}
}
}
export function isNewUser(a0) {
return a0 != null && Date.now() - a0.createdAt.getTime() < 2592000000;
}
export function formatPriceString(a0, a1) {
let r32;
const r15 = formatPrice(a0.amount, a0.currency);
if (SubscriptionIntervalTypes.MONTH === a1) {
r32 = _index_native.intl.string(_index_native.t.FPybU7);
} else {
if (SubscriptionIntervalTypes.YEAR !== a1) {
throw new Error("Unexpected interval");
}
r32 = _index_native.intl.string(_index_native.t.tfqrhj);
}
return `${r15}/${r32}`;
}
export function castPremiumSubscriptionAsSkuId(a0) {
return a0;
}
export function formatInterval(a0) {
if (a0 === SubscriptionIntervalTypes.YEAR) {
return _index_native.intl.string(_index_native.t.tfqrhj);
}
if (a0 === SubscriptionIntervalTypes.MONTH) {
return _index_native.intl.string(_index_native.t.FPybU7);
}
throw new Error(`Invalid interval type: ${a0}`);
}
export function isPremiumEligible(a0) {
return a0 != null && !a0.isProvisional && !a0.bot;
}
export function getFractionalPremiumUnitsHours(a0) {
return a0.map($mk72831()).reduce($mk72832(), 0);
}
getMonthlyPrice = function getMonthlyPrice({ subscriptionPlan, isGift = false, priceOptions = {} }) {
const r14 = PREMIUM_SKU_TO_MONTHLY_PLAN[subscriptionPlan.skuId];
return r14 != null ? getPrice(r14, false, isGift, priceOptions) : null;
};
calculateMonthlyPriceEquivalentTotal = function calculateMonthlyPriceEquivalentTotal(a0) {
const subscriptionPlan = a0.subscriptionPlan;
let isGift = a0.isGift;
if (isGift === void 0) {
isGift = false;
}
let priceOptions = a0.priceOptions;
if (priceOptions === void 0) {
priceOptions = {};
}
if (subscriptionPlan.interval === SubscriptionIntervalTypes.DAY) {
return null;
}
if (subscriptionPlan.interval === SubscriptionIntervalTypes.MONTH && subscriptionPlan.intervalCount === 1) {
return null;
}
if (isGift === void 0) {
isGift = false;
}
if (priceOptions === void 0) {
priceOptions = {};
}
const r22 = PREMIUM_SKU_TO_MONTHLY_PLAN[subscriptionPlan.skuId];
const r23 = r22 == null ? null : getPrice(r22, false, isGift, priceOptions);
if (r23 == null) {
return null;
}
return r23.amount * (subscriptionPlan.interval === SubscriptionIntervalTypes.MONTH ? subscriptionPlan.intervalCount : 12 * subscriptionPlan.intervalCount);
};
calculateDiscountPercentageForYearlyPlan = function calculateDiscountPercentageForYearlyPlan(a0, isGift = false, priceOptions = {}) {
let r18, price;
L8: {
if (a0.interval === SubscriptionIntervalTypes.YEAR) {
L10: {
try {
const monthlyPrice = getMonthlyPrice({
subscriptionPlan: a0,
isGift,
priceOptions
});
r18 = monthlyPrice;
if (monthlyPrice == null) {
break L10;
}
price = getPrice(a0.id, false, isGift, priceOptions);
} catch ($e) {
return void 0;
}
if (r18.amount !== 0) {
return Math.floor(100 * (1 - price.amount / (12 * r18.amount)));
}
break L8;
}
return void 0;
}
}
};
export function calculateYearlyPlanDollarSavingsAmount(a0, isGift = false, priceOptions = {}) {
const r15 = calculateMonthlyPriceEquivalentTotal({
subscriptionPlan: a0,
isGift,
priceOptions
});
if (r15 != null && !(r15 <= 0)) {
const price = getPrice(a0.id, false, isGift, priceOptions);
const amount = r15 - price.amount;
return amount <= 0 ? null : {
amount,
currency: price.currency
};
}
return null;
}
export function calculateYearlyPlanMonthsSaved(a0, isGift = false, priceOptions = {}) {
if (a0.interval !== SubscriptionIntervalTypes.YEAR) {
return null;
}
const r7 = isGift !== void 0;
const r16 = r7 ? isGift : false;
const r3 = priceOptions !== void 0;
const r15 = r3 ? priceOptions : {};
const r11 = PREMIUM_SKU_TO_MONTHLY_PLAN[a0.skuId];
const r25 = r11 == null ? null : getPrice(r11, false, r16, r15);
if (r25 != null && r25.amount !== 0) {
if (!r7) {
isGift = false;
}
if (!r3) {
priceOptions = {};
}
const r30 = calculateMonthlyPriceEquivalentTotal({
subscriptionPlan: a0,
isGift,
priceOptions
});
let r31 = null;
if (r30 != null) {
r31 = null;
if (!(r30 <= 0)) {
const price = getPrice(a0.id, false, isGift, priceOptions);
const amount = r30 - price.amount;
r31 = amount <= 0 ? null : {
amount,
currency: price.currency
};
}
}
if (r31 == null) {
return null;
}
const r51 = Math.floor(r31.amount / r25.amount * 2) / 2;
return r51 <= 0 ? null : r51;
}
return null;
}
export function calculateYearlyPlanMonthlyRateAmount(a0, r6 = false, r5 = {}) {
if (a0.interval !== SubscriptionIntervalTypes.YEAR) {
return null;
}
const price = getPrice(a0.id, false, r6, r5);
return price.amount !== 0 ? {
amount: Math.round(price.amount / 12),
currency: price.currency
} : null;
}
export function getDaysSincePremium(a0) {
return a0 == null ? 0 : Math.max(differenceInCalendarDays(new Date(), new Date(a0)), 0);
}
export function getDaysRemainingUntilSubscriptionCurrentPeriodEnds(a0) {
return Math.max(1, Math.ceil(differenceInDays(new Date(a0.currentPeriodEnd), new Date())));
}
const SubscriptionPlans2 = SubscriptionPlans;
c2169_51 = {
PAYMENT_SOURCE_MANAGEMENT: "https://support.apple.com/HT201266",
BILLING_HISTORY: "https://support.apple.com/HT201266",
SUBSCRIPTION_MANAGEMENT: "https://support.apple.com/HT202039"
};
c2169_52 = {
SUBSCRIPTION_MANAGEMENT: "https://play.google.com/store/account/subscriptions",
PAYMENT_SOURCE_MANAGEMENT: "https://play.google.com/store/paymentmethods",
BILLING_HISTORY: "https://play.google.com/store/account/orderhistory"
};
c2169_53 = new Logger("PremiumUtils.tsx");
c2169_54 = {
BUNDLE: "bundle",
TIER_0: "tier_0",
TIER_1: "tier_1",
TIER_2: "tier_2",
PREMIUM_GUILD: "premium_guild"
};
c2169_55 = {
MID: "mid",
HIGH: "high"
};
c2169_65 = new Set([SubscriptionPlans2.NONE_MONTH, SubscriptionPlans2.NONE_3_MONTH, SubscriptionPlans2.NONE_6_MONTH, SubscriptionPlans2.NONE_YEAR, SubscriptionPlans2.PREMIUM_MONTH_TIER_0, SubscriptionPlans2.PREMIUM_MONTH_TIER_1, SubscriptionPlans2.PREMIUM_MONTH_TIER_2, SubscriptionPlans2.PREMIUM_YEAR_TIER_0, SubscriptionPlans2.PREMIUM_YEAR_TIER_1, SubscriptionPlans2.PREMIUM_YEAR_TIER_2, SubscriptionPlans2.PREMIUM_3_MONTH_TIER_2, SubscriptionPlans2.PREMIUM_6_MONTH_TIER_2, SubscriptionPlans2.PREMIUM_GROUP_MONTH]);
const r220 = Object.freeze({
isNewUser,
isPremiumAtLeast: _PremiumTypeUtils.isPremiumAtLeast,
isPremium: _PremiumTypeUtils.isPremium,
isPremiumExactly: _PremiumTypeUtils.isPremiumExactly,
isPremiumEligible,
getPrice,
getDefaultPrice,
getInterval,
getIntervalString,
getIntervalStringAsNoun,
getPremiumType,
getTierDisplayNameByPlanId,
getDisplayName,
getPremiumPlanOptions,
formatInterval,
getPlanDescription,
isPremiumSku: function isPremiumSku(a0) {
return a0 === PremiumSubscriptionSKUs.TIER_0 || a0 === PremiumSubscriptionSKUs.TIER_1 || a0 === PremiumSubscriptionSKUs.TIER_2;
},
getIntervalMonths: function getIntervalMonths(a0, a1) {
if (a0 === SubscriptionIntervalTypes.MONTH) {
return a1;
}
if (a0 === SubscriptionIntervalTypes.YEAR) {
return 12 * a1;
}
throw new Error(`${a0} interval subscription period not implemented`);
},
getUserMaxFileSize: _PremiumFeatureUtils.getUserMaxFileSize,
getSkuIdForPlan: function getSkuIdForPlan(a0) {
const r10 = SubscriptionPlanInfo[a0];
if (r10 == null) {
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
}
return r10.skuId;
},
getSkuIdForPremiumType: function getSkuIdForPremiumType(a0) {
if (PremiumTypes.TIER_0 === a0) {
return PremiumSubscriptionSKUs.TIER_0;
}
if (PremiumTypes.TIER_1 === a0) {
return PremiumSubscriptionSKUs.TIER_1;
}
if (PremiumTypes.TIER_2 === a0) {
return PremiumSubscriptionSKUs.TIER_2;
}
},
getNumIncludedPremiumGuildSubscriptionSlots: function getNumIncludedPremiumGuildSubscriptionSlots(a0) {
const r12 = SubscriptionPlanInfo[a0];
if (r12 != null) {
return r12.premiumType === PremiumTypes.TIER_2 ? NUM_FREE_GUILD_BOOSTS_WITH_PREMIUM : 0;
}
const error = new Error("Unsupported plan");
captureBillingException(error, {
tags: {
planId: a0
}
});
throw error;
},
getBillingInformationString,
getExpectedRenewalDate,
extendDateWithUnconsumedFractionalPremium,
getUnactivatedFractionalPremiumDurationString,
isSwitchingPlansDisabled,
getSwitchingPlansDisabledMessage,
isNoneSubscription: _SubscriptionPlanRecord.isNoneSubscription,
getPlanIdFromInvoice,
getStatusFromInvoice,
isBaseSubscriptionCanceled,
getPremiumGuildIntervalPrice,
hasAccountCredit: function hasAccountCredit(a0) {
return a0 != null && a0.size !== 0 && Array.from(a0).some(({ subscriptionPlanId, parentId, consumed }) => subscriptionPlanId != null && parentId != null && !consumed);
},
hasUnconsumedGiftForSubscriptionPlan: function hasUnconsumedGiftForSubscriptionPlan(a0, a1) {
return a0 != null && a0.size !== 0 && a1 != null && Array.from(a0).some(({ subscriptionPlanId, parentId, consumed }) => subscriptionPlanId != null && parentId != null && !consumed && subscriptionPlanId === a1);
},
getBillingReviewSubheader,
getIntervalForInvoice,
getPremiumPlanItem,
getGuildBoostPlanItem,
isBoostOnlySubscription,
getPremiumSkuIdForSubscription,
getPremiumTypeFromSubscription,
getUnactivatedFractionalPremiumHours: getFractionalPremiumUnitsHours,
castPremiumSubscriptionAsSkuId,
calculateDiscountPercentageForYearlyPlan,
calculateYearlyPlanDollarSavingsAmount,
calculateYearlyPlanMonthsSaved,
calculateYearlyPlanMonthlyRateAmount,
getDaysSincePremium,
getDaysRemainingUntilSubscriptionCurrentPeriodEnds,
canUseAnimatedEmojis: function canUseAnimatedEmojis(a0) {
return canUserUse(ANIMATED_EMOJIS, a0);
},
canUseEmojisEverywhere: function canUseEmojisEverywhere(a0) {
return canUserUse(EMOJIS_EVERYWHERE, a0);
},
canUseSoundboardEverywhere: function canUseSoundboardEverywhere(a0) {
return canUserUse(SOUNDBOARD_EVERYWHERE, a0);
},
canUseCustomCallSounds: function canUseCustomCallSounds(a0) {
return canUserUse(CUSTOM_CALL_SOUNDS, a0);
},
canUploadLargeFiles: function canUploadLargeFiles(a0) {
return canUserUse(UPLOAD_LARGE_FILES, a0);
},
canUseBadges: function canUseBadges(a0) {
return canUserUse(PROFILE_BADGES, a0);
},
canUseHighVideoUploadQuality: function canUseHighVideoUploadQuality(a0) {
return canUserUse(INCREASED_VIDEO_UPLOAD_QUALITY, a0);
},
canEditDiscriminator: function canEditDiscriminator(a0) {
return canUserUse(CUSTOM_DISCRIMINATOR, a0);
},
hasBoostDiscount: function hasBoostDiscount(a0) {
return canUserUse(BOOST_DISCOUNT, a0);
},
canUseAnimatedAvatar: function canUseAnimatedAvatar(a0) {
return canUserUse(ANIMATED_AVATAR, a0);
},
canInstallPremiumApplications: function canInstallPremiumApplications(a0) {
return canUserUse(INSTALL_PREMIUM_APPLICATIONS, a0);
},
canUseIncreasedMessageLength: function canUseIncreasedMessageLength(a0) {
return canUserUse(INCREASED_MESSAGE_LENGTH, a0);
},
canUseIncreasedGuildCap: function canUseIncreasedGuildCap(a0) {
return canUserUse(INCREASED_GUILD_LIMIT, a0);
},
canRedeemPremiumPerks: function canRedeemPremiumPerks(a0) {
return canUserUse(REDEEM_PREMIUM_PERKS, a0);
},
canUsePremiumProfileCustomization: function canUsePremiumProfileCustomization(a0) {
return canUserUse(PROFILE_PREMIUM_FEATURES, a0);
},
canUsePremiumAppIcons: function canUsePremiumAppIcons(a0) {
return canUserUse(APP_ICONS, a0);
},
canUsePremiumGuildMemberProfile: function canUsePremiumGuildMemberProfile(a0) {
return canUserUse(PREMIUM_GUILD_MEMBER_PROFILE, a0);
},
canUseClientThemes: function canUseClientThemes(a0) {
return canUserUse(CLIENT_THEMES, a0);
},
canStreamQuality: function canStreamQuality(a0, a1) {
return a0 === c2169_55.HIGH ? canUserUse(STREAM_HIGH_QUALITY, a1) : canUserUse(STREAM_MID_QUALITY, a1);
},
canUseQuestOrbMultiplier: function canUseQuestOrbMultiplier(a0) {
return canUserUse(QUEST_ORB_MULTIPLIER, a0);
},
hasFreeBoosts: function hasFreeBoosts(a0) {
return canUserUse(FREE_BOOSTS, a0);
},
canUseCustomStickersEverywhere: function canUseCustomStickersEverywhere(a0) {
return canUserUse(STICKERS_EVERYWHERE, a0);
},
canUseCustomBackgrounds: function canUseCustomBackgrounds(a0) {
return canUserUse(VIDEO_FILTER_ASSETS, a0);
},
canUseCollectibles: function canUseCollectibles(a0) {
return canUserUse(COLLECTIBLES, a0);
},
canUseMonthlyOrbs: function canUseMonthlyOrbs(a0) {
return !!getIsCrepeEnabled("canUseMonthlyOrbs") && hasPerk(a0?.perks, Perk.MONTHLY_ORBS);
},
canUseShopDiscounts: function canUseShopDiscounts(a0) {
return getIsCrepeEnabled("canUseShopDiscounts") && hasPerk(a0?.perks, Perk.SHOP_DISCOUNTS) || canUserUse(COLLECTIBLES, a0);
},
canUseMoreQuestOrbs: function canUseMoreQuestOrbs(a0) {
return getIsCrepeEnabled("canUseMoreQuestOrbs") && hasPerk(a0?.perks, Perk.MORE_QUEST_ORBS) || canUserUse(QUEST_ORB_MULTIPLIER, a0);
},
formatPriceString,
StreamQuality: c2169_55
});
export default r220;
export { c2169_54 as Branding };
export { c2169_55 as StreamQuality };
export function getPremiumBranding(a0) {
let BUNDLE;
L20: {
const planId2 = a0.planId;
if (PREMIUM_PLANS.has(planId2)) {
let env13658;
const additionalPlans = a0.additionalPlans;
const r14 = env13658 = {};
env13658[0] = void 0;
const planIdsForSkus = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13658[0] = planIdsForSkus;
Module38(planIdsForSkus != null, "Missing guildSubscriptionPlanIds");
const r26 = additionalPlans.find($mk72818(r14));
if ((r26 != null ? r26.quantity : 0) > 0) {
BUNDLE = c2169_54.BUNDLE;
break L20;
}
}
if (planId2 !== SubscriptionPlans.PREMIUM_MONTH_TIER_0 && planId2 !== SubscriptionPlans.PREMIUM_YEAR_TIER_0) {
if (planId2 !== SubscriptionPlans.PREMIUM_MONTH_TIER_1 && planId2 !== SubscriptionPlans.PREMIUM_YEAR_TIER_1) {
if (planId2 !== SubscriptionPlans.PREMIUM_MONTH_TIER_2 && planId2 !== SubscriptionPlans.PREMIUM_YEAR_TIER_2 && planId2 !== SubscriptionPlans.PREMIUM_3_MONTH_TIER_2 && planId2 !== SubscriptionPlans.PREMIUM_6_MONTH_TIER_2) {
BUNDLE = c2169_54.PREMIUM_GUILD;
break L20;
}
BUNDLE = c2169_54.TIER_2;
break L20;
}
BUNDLE = c2169_54.TIER_1;
} else {
BUNDLE = c2169_54.TIER_0;
}
}
return BUNDLE;
}
export { getDefaultPrice };
export function withContextPlanPrices(a0, a1) {
return a1 != null ? {
...a0,
contextPlanPrices: Object.fromEntries(a1.map($mk72812()))
} : a0;
}
export function usePlanSelectPriceState(a0, a1, a2) {
const memo = useMemo(() => a1 == null ? null : a1.checkoutContext == null ? null : a1.checkoutContext.available_plans == null ? null : a1.checkoutContext.available_plans, [a1]);
return useMemo(() => ({
priceOptions: memo != null ? {
...a0,
contextPlanPrices: Object.fromEntries(memo.map($mk72812()))
} : a0,
planPricesLoading: a0.currency != null && a1 != null && a1.currency !== a0.currency && a2 == null
}), [a0, a1, memo, a2]);
}
export { getPrice };
export function getCountryPrices(a0, r4 = PriceSetAssignmentPurchaseTypes.DEFAULT) {
return getPurchaseTypePrices(a0, r4).countryPrices;
}
export { experimentalGetPrices };
export function experimentalGetPrice(a0, r3 = {
purchaseType: PriceSetAssignmentPurchaseTypes.DEFAULT
}) {
let env13649;
const r23 = env13649 = {};
const { paymentSourceId, purchaseType, currency } = r3;
env13649[0] = currency;
const r26 = experimentalGetPrices(a0, {
paymentSourceId,
purchaseType
});
if (r26.length === 0) {
c2169_53.warn(`No prices found for planId: ${a0}, paymentSourceId: ${paymentSourceId}, purchaseType: ${purchaseType}`);
}
if (currency != null) {
let r35 = r26.find($mk72813(r23));
if (r35 == null) {
r35 = paymentSourceId != null ? experimentalGetPrices(a0, {
purchaseType
}).find($mk72814(r23)) : void 0;
}
return r35;
}
return r26[0];
}
export { getServerPriceFromClientPrice };
export { getItemPlansTotalServerPrice };
export function getSubscriptionWithNewPlansTotalServerPrice(a0, a1, a2, a3) {
let r21;
let r10 = a1;
if (a1 === null) {
Module38(a0 !== null, "Subscription can't be null");
r10 = [];
}
if (a0 !== null) {
let env13660;
const r22 = env13660 = {
$parent: env2169
};
env13660[0] = a0;
let r11 = a0.renewalMutations?.items;
if (r11 == null) {
r11 = a0.items;
}
const r24 = [];
const r27 = r11.find($mk72824());
if (r27 != null) {
r24.push(r27);
}
r24.push.apply(r24, [...r10]);
r21 = r24.map($mk72825(r22));
} else {
r21 = r10.filter($mk72826());
}
return getItemPlansTotalServerPrice(r21, a2, a3);
}
export function getDiscountIntervalString(a0) {
if (DiscountUserUsageLimitIntervalTypes.MONTH === a0) {
return _index_native.intl.string(_index_native.t.FPybU7);
}
if (DiscountUserUsageLimitIntervalTypes.YEAR === a0) {
return _index_native.intl.string(_index_native.t.tfqrhj);
}
if (DiscountUserUsageLimitIntervalTypes.DAY !== a0) {
DiscountUserUsageLimitIntervalTypes.WEEK;
}
throw new Error("Unexpected interval");
}
export { getDisplayName };
export function getDisplayNameFromSku(a0) {
if (PremiumSubscriptionSKUs.TIER_0 === a0) {
return _index_native.intl.string(_index_native.t["t9uG/o"]);
}
if (PremiumSubscriptionSKUs.TIER_1 === a0) {
return _index_native.intl.string(_index_native.t.FSOz78);
}
if (PremiumSubscriptionSKUs.TIER_2 === a0) {
return _index_native.intl.string(_index_native.t.lG6a5x);
}
const error = new Error("Unsupported sku");
captureBillingException(error, {
tags: {
skuId: a0
}
});
throw error;
}
export function getPremiumTypeDisplayName(a0, r4 = false) {
if (PremiumTypes.TIER_0 === a0) {
return r4 ? "Basic" : _index_native.intl.string(_index_native.t["t9uG/o"]);
}
if (PremiumTypes.TIER_1 === a0) {
return r4 ? "Classic" : _index_native.intl.string(_index_native.t.FSOz78);
}
if (PremiumTypes.TIER_2 === a0) {
return _index_native.intl.string(_index_native.t.lG6a5x);
}
}
export function getPlanDescriptionFromInvoice({ renewalInvoicePreview, renewalInvoiceWithEntitlementsPreview, subscription, planId: planId2, includePremiumGuilds = false, hasDiscountApplied = false, activeDiscountInfo, hasFractionalPremiumWithSub = false, fractionalPremiumInfo }) {
const r27 = SubscriptionPlanStore.get(planId2);
Module38(r27 != null, "Missing plan");
const r36 = renewalInvoicePreview.findInvoiceItemByPlanId(r27.id);
return getPlanDescription({
subscription,
planId: r27.id,
price: formatRate(formatPrice(r36 == null ? getPrice(r27.id, false, false, {
paymentSourceId: subscription.paymentSourceId,
currency: subscription.currency
}).amount : r36.amount, renewalInvoicePreview.currency), r27.interval, r27.intervalCount),
includePremiumGuilds,
hasDiscountApplied,
activeDiscountInfo,
renewalInvoiceWithoutEntitlementsPreview: renewalInvoicePreview,
renewalInvoiceWithEntitlementsPreview,
hasFractionalPremiumWithSub,
fractionalPremiumInfo
});
}
export function getExternalPlanDisplayName({ planId: planId2, additionalPlans }) {
const premiumDescription = (0, _SubscriptionPlanRecord.isNoneSubscription)(planId2) ? null : getDisplayName(planId2);
const r17 = additionalPlans == null ? void 0 : additionalPlans.find((additionalPlan) => PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(additionalPlan.planId));
const r9 = r17?.planId !== SubscriptionPlans.PREMIUM_MONTH_GUILD ? r17?.planId === SubscriptionPlans.PREMIUM_YEAR_GUILD ? _index_native.t.Pi5yMJ : null : _index_native.t.Pi5yMJ;
const premiumGuildDescription = r9 != null ? _index_native.intl.formatToPlainString(r9, {
num: r17?.quantity
}) : void 0;
if (premiumDescription != null && premiumGuildDescription != null) {
return _index_native.intl.formatToPlainString(_index_native.t.FN5T9r, {
premiumDescription,
premiumGuildDescription
});
}
if (premiumDescription != null) {
return premiumDescription;
}
if (premiumGuildDescription != null) {
return premiumGuildDescription;
}
throw new Error("Subscription without premium or premium guild subscription");
}
export function getPlanIdForPremiumType(a0, a1) {
if (new Set([SubscriptionIntervalTypes.MONTH, SubscriptionIntervalTypes.YEAR]).has(a1)) {
if (PremiumTypes.TIER_0 === a0) {
return a1 === SubscriptionIntervalTypes.MONTH ? SubscriptionPlans.PREMIUM_MONTH_TIER_0 : SubscriptionPlans.PREMIUM_YEAR_TIER_0;
}
if (PremiumTypes.TIER_1 === a0) {
return a1 === SubscriptionIntervalTypes.MONTH ? SubscriptionPlans.PREMIUM_MONTH_TIER_1 : SubscriptionPlans.PREMIUM_YEAR_TIER_1;
}
if (PremiumTypes.TIER_2 === a0) {
return a1 === SubscriptionIntervalTypes.MONTH ? SubscriptionPlans.PREMIUM_MONTH_TIER_2 : SubscriptionPlans.PREMIUM_YEAR_TIER_2;
}
throw new Error(`Unsupported premium type: ${a0}`);
}
throw new Error(`Unsupported plan interval for premium type: ${a1}`);
}
export { getNumPremiumGuildSubscriptions };
export function subscriptionHasPremiumGuildPlan({ additionalPlans }) {
let env13652;
const r11 = env13652 = {};
env13652[0] = void 0;
const planIdsForSkus = SubscriptionPlanStore.getPlanIdsForSkus([PremiumSubscriptionSKUs.GUILD]);
env13652[0] = planIdsForSkus;
Module38(planIdsForSkus != null, "Missing guildSubscriptionPlanIds");
const r22 = additionalPlans.find($mk72818(r11));
return (r22 != null ? r22.quantity : 0) > 0;
}
export function isPremiumBaseSubscriptionPlan(a0) {
return c2169_65.has(a0);
}
export function isPremiumGuildSubscriptionPlan(a0) {
return PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(a0);
}
export function isPremiumSubscriptionPlan(a0) {
return c2169_65.has(a0) || PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(a0);
}
export function isPremiumGroupSubscriptionPlan(a0) {
return a0 != null && a0 === SubscriptionPlans.PREMIUM_GROUP_MONTH;
}
export { getBillingGracePeriodDaysAndExpiresDate };
export { getExpectedRenewalDate };
export function isSubscriptionPrepaidPaymentSource(a0) {
let r8 = a0.paymentSourceId != null;
if (r8) {
const paymentSourceId = a0.paymentSourceId;
const r1 = paymentSourceId == null;
let r9 = false;
if (!r1) {
const paymentSource = PaymentSourceStore.getPaymentSource(paymentSourceId);
r9 = paymentSource != null && PREPAID_PAYMENT_SOURCES.has(paymentSource.type);
}
r8 = r9;
}
return r8;
}
export function isPrepaidPaymentSource(a0) {
if (a0 == null) {
return false;
}
const paymentSource = PaymentSourceStore.getPaymentSource(a0);
return paymentSource != null && PREPAID_PAYMENT_SOURCES.has(paymentSource.type);
}
export { getCoercedPremiumGuildSubscriptionStatus };
export { isPremiumGuildSubscriptionCanceled };
export function getPremiumGuildHeaderDescription({ subscription, user, price, renewalInvoicePreview, fractionalPremiumInfo }) {
let r107, r108;
const { planId: planId2, additionalPlans, renewalMutations } = subscription;
const r29 = SubscriptionPlanStore.get(planId2);
Module38(r29 != null, "Missing plan");
const quantity2 = getNumPremiumGuildSubscriptions(additionalPlans);
const activeQuantity = renewalMutations?.additionalPlans != null ? getNumPremiumGuildSubscriptions(renewalMutations.additionalPlans) : quantity2;
const pendingQuantity = Math.max(0, quantity2 - activeQuantity);
const r45 = activeQuantity > 0 && pendingQuantity > 0;
const isPurchasedExternally = subscription.isPurchasedExternally;
let r47 = false;
let r17 = void 0;
if (!isPurchasedExternally) {
const r48 = price == null;
r47 = false;
r17 = price;
if (r48) {
let r49 = null;
if (renewalInvoicePreview != null) {
const r52 = renewalInvoicePreview.invoiceItems.find((invoiceItem) => PREMIUM_GUILD_SUBSCRIPTION_PLANS.has(invoiceItem.subscriptionPlanId));
if (r52 != null) {
r49 = r52.amount;
}
}
const r54 = r49 == null;
let r55 = false;
if (r54) {
const r56 = r45 ? activeQuantity : quantity2;
try {
r49 = getPremiumGuildIntervalPrice(subscription.planId, subscription.paymentSourceId, subscription.currency, user).amount * r56;
r55 = false;
} catch ($e) {
r55 = true;
}
}
r17 = r49 != null ? formatPrice(r49, subscription.currency) : void 0;
r47 = r55;
}
}
const r68 = subscription.isPurchasedExternally || r47;
const rate = r17 != null ? formatRate(r17, r29.interval, r29.intervalCount) : "";
let r78 = renewalInvoicePreview?.taxInclusive;
if (r78 == null) {
r78 = subscription.latestInvoice?.taxInclusive;
}
if (r78 == null) {
r78 = true;
}
if (isPremiumGuildSubscriptionCanceled(subscription)) {
return r68 ? _index_native.intl.format(_index_native.t["3/WTrI"], {
quantity: quantity2
}) : r78 ? _index_native.intl.format(_index_native.t["0ozBSB"], {
quantity: quantity2,
rate
}) : _index_native.intl.format(_index_native.t["yjsv/s"], {
quantity: quantity2,
rate
});
}
const status = subscription.status;
if (SubscriptionStatusTypes.ACCOUNT_HOLD === status) {
return r68 ? _index_native.intl.format(_index_native.t.Nlf3nc, {
quantity: quantity2,
boostQuantity: quantity2
}) : r78 ? _index_native.intl.format(_index_native.t.oiRy7v, {
quantity: quantity2,
boostQuantity: quantity2,
rate
}) : _index_native.intl.format(_index_native.t["0QxOAi"], {
quantity: quantity2,
boostQuantity: quantity2,
rate
});
}
if (SubscriptionStatusTypes.PAUSE_PENDING !== status && SubscriptionStatusTypes.PAUSED !== status) {
if (SubscriptionStatusTypes.PAST_DUE === status && subscription.isBoostOnly) {
return _index_native.intl.format(_index_native.t["d+0vwo"], {
endDate: dateFormat(getBillingGracePeriodDaysAndExpiresDate(subscription).expiresDate, "LL"),
onClick: () => {
openURL("https://support.discord.com/hc/articles/23082866222871");
}
});
}
if (r45) {
if (r68) {
return _index_native.intl.format(_index_native.t["krRy+d"], {
activeQuantity,
pendingQuantity
});
}
const r106 = _index_native.t;
if (r78) {
r107 = r106["4nc7+E"];
r108 = require;
} else {
r107 = r106.BmaudS;
r108 = require;
}
return r108(dependencyMap[17]).intl.format(r107, {
activeQuantity,
pendingQuantity,
rate
});
}
const intl = _index_native.intl;
return r68 ? intl.format(_index_native.t["5iud9s"], {
quantity: quantity2
}) : r78 ? intl.format(_index_native.t.eDwrLA, {
quantity: quantity2,
rate
}) : intl.format(_index_native.t.ijSDcI, {
quantity: quantity2,
rate
});
}
return fractionalPremiumInfo != null && !fractionalPremiumInfo.isFractionalPremiumActive ? _index_native.intl.string(_index_native.t.CduWAm) : _index_native.intl.format(_index_native.t["5iud9s"], {
quantity: quantity2
});
}
export { getFormattedPriceForPlan };
export function getFormattedRateForPlan(a0, a1, a2) {
return formatRate(getFormattedPriceForPlan(a0, a1, a2), a0.interval, a0.intervalCount);
}
export function isSubscriptionStatusFailedPayment(a0) {
return a0 === SubscriptionStatusTypes.PAST_DUE || a0 === SubscriptionStatusTypes.ACCOUNT_HOLD || a0 === SubscriptionStatusTypes.BILLING_RETRY;
}
export function getFormattedPlanPriceFromInvoice(a0, a1, a2) {
const r16 = a0.findInvoiceItemByPlanId(a2.id);
return formatRate(formatPrice(r16 == null ? getPrice(a2.id, false, false, {
paymentSourceId: a1.paymentSourceId,
currency: a1.currency
}).amount : r16.amount, a0.currency), a2.interval, a2.intervalCount);
}
export { getPremiumGuildIntervalPrice };
export { getDefaultCurrency };
export function formatTrialOfferIntervalDuration({ intervalType = SubscriptionIntervalTypes.MONTH, intervalCount = 1, capitalize = false }) {
if (SubscriptionIntervalTypes.DAY === intervalType) {
return intervalCount >= 7 && intervalCount % 7 === 0 ? capitalize ? _index_native.intl.formatToPlainString(_index_native.t.fRNBRX, {
weeks: intervalCount / 7
}) : _index_native.intl.formatToPlainString(_index_native.t.EIpHEj, {
weeks: intervalCount / 7
}) : capitalize ? _index_native.intl.formatToPlainString(_index_native.t["6Cdzoy"], {
days: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t["kbBj/h"], {
days: intervalCount
});
}
if (SubscriptionIntervalTypes.MONTH === intervalType) {
return capitalize ? _index_native.intl.formatToPlainString(_index_native.t.x5MgxS, {
months: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t["4SEnCZ"], {
months: intervalCount
});
}
if (SubscriptionIntervalTypes.YEAR === intervalType) {
return capitalize ? _index_native.intl.formatToPlainString(_index_native.t["h+63yl"], {
years: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t["9DFiHk"], {
years: intervalCount
});
}
throw new Error("Unsupported interval duration.");
}
export { formatTrialCtaIntervalDuration };
export function formatTrialCtaIntervalDurationFromTrialOffer(a0, a1) {
if (a0 != null && a0.subscription_trial != null && a0.subscription_trial.sku_id === a1) {
const subscription_trial = a0.subscription_trial;
return formatTrialCtaIntervalDuration({
intervalType: subscription_trial.interval,
intervalCount: subscription_trial.interval_count
});
}
return null;
}
export function formatIntervalDuration({ intervalType = SubscriptionIntervalTypes.MONTH, intervalCount = 1, capitalize = false }) {
if (SubscriptionIntervalTypes.DAY === intervalType) {
return intervalCount >= 7 && intervalCount % 7 === 0 ? capitalize ? _index_native.intl.formatToPlainString(_index_native.t.iVZYyl, {
weeks: intervalCount / 7
}) : _index_native.intl.formatToPlainString(_index_native.t.EmoBD2, {
weeks: intervalCount / 7
}) : capitalize ? _index_native.intl.formatToPlainString(_index_native.t.jzH70Z, {
days: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t["k2UNz+"], {
days: intervalCount
});
}
if (SubscriptionIntervalTypes.MONTH === intervalType) {
return capitalize ? _index_native.intl.formatToPlainString(_index_native.t.erUSmA, {
months: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t.kridzK, {
months: intervalCount
});
}
if (SubscriptionIntervalTypes.YEAR === intervalType) {
return capitalize ? _index_native.intl.formatToPlainString(_index_native.t.IfYQVC, {
years: intervalCount
}) : _index_native.intl.formatToPlainString(_index_native.t.PClsrw, {
years: intervalCount
});
}
throw new Error("Unsupported interval duration.");
}
export function getExternalSubscriptionMethodUrl(a0, a1) {
if (PaymentGateways.APPLE_PARTNER !== a0 && PaymentGateways.APPLE_ADVANCED_COMMERCE !== a0 && PaymentGateways.APPLE !== a0) {
if (PaymentGateways.GOOGLE === a0) {
return c2169_52[a1];
}
throw new Error(`Invalid external payment gateway ${a0}`);
}
return c2169_51[a1];
}
export function hasPremiumSubscriptionToDisplay(a0, a1) {
let r9 = _PremiumTypeUtils.isPremium(a0);
if (!r9) {
const status = a1?.status;
r9 = status === SubscriptionStatusTypes.PAST_DUE || status === SubscriptionStatusTypes.ACCOUNT_HOLD || status === SubscriptionStatusTypes.BILLING_RETRY;
}
return r9;
}
export function useHasPremiumSubscriptionToDisplay() {
const stateFromStores = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getPremiumTypeSubscription());
let r22 = _PremiumTypeUtils.isPremium(useStateFromStores([UserStore], () => UserStore.getCurrentUser()));
if (!r22) {
const status = stateFromStores?.status;
r22 = status === SubscriptionStatusTypes.PAST_DUE || status === SubscriptionStatusTypes.ACCOUNT_HOLD || status === SubscriptionStatusTypes.BILLING_RETRY;
}
return r22;
}
export function getItemsFromNewAdditionalPlans(a0, a1) {
let env13655;
const r3 = env13655 = {
$parent: env2169
};
env13655[0] = a0;
let r7 = a0.renewalMutations?.items;
if (r7 == null) {
r7 = a0.items;
}
const r12 = [];
const r14 = r7.find($mk72824());
if (r14 != null) {
r12.push(r14);
}
r12.push.apply(r12, [...a1]);
return r12.map($mk72825(r3));
}
export function getItemsWithoutPremiumPlanItem(a0) {
return a0.filter($mk72826());
}
export { getItemsWithUpsertedPlanIdForGroup };
export function getItemsWithUpsertedPremiumPlanId(a0, a1) {
return getItemsWithUpsertedPlanIdForGroup(a0, a1, 1, PREMIUM_PLANS);
}
export function getItemsWithUpsertedPremiumGuildPlan(a0, a1, a2) {
return getItemsWithUpsertedPlanIdForGroup(a0, a2, a1, PREMIUM_GUILD_SUBSCRIPTION_PLANS);
}
export function coerceExistingItemsToNewItemInterval(a0) {
let r4 = a0.find((item) => !("id" in item));
if (r4 == null) {
r4 = a0.find((item) => PREMIUM_PLANS.has(item.planId));
}
let c13661_1;
let c13661_0 = r4;
let r12 = a0;
if (r4 != null) {
const r14 = SubscriptionPlanStore.get(r4.planId);
c13661_1 = r14;
Module38(r14 != null, "Missing plan");
r12 = a0.map((item) => {
if (item === c13661_0) {
return item;
}
const r15 = SubscriptionPlanStore.get(item.planId);
Module38(r15 != null, "Missing plan");
if (c13661_1.interval === r15.interval && c13661_1.intervalCount === r15.intervalCount) {
return item;
}
const forSkuAndInterval = SubscriptionPlanStore.getForSkuAndInterval(r15.skuId, c13661_1.interval, c13661_1.intervalCount);
Module38(forSkuAndInterval != null, "Missing planForInterval");
return {
...item,
planId: forSkuAndInterval.id
};
});
}
return r12;
}
export function getMaxFileSizeForPremiumType(a0, r5 = {
useSpace: true
}) {
return formatSize(PremiumUserLimits[a0].fileSize / 1024, {
useKibibytes: true,
useSpace: r5.useSpace
});
}
export function getPremiumTypeFromPlanId(a0) {
if (SubscriptionPlans.PREMIUM_MONTH_TIER_0 === a0) {
return {
premiumType: PremiumTypes.TIER_0,
planInterval: SubscriptionIntervalTypes.MONTH
};
}
if (SubscriptionPlans.PREMIUM_YEAR_TIER_0 === a0) {
return {
premiumType: PremiumTypes.TIER_0,
planInterval: SubscriptionIntervalTypes.YEAR
};
}
if (SubscriptionPlans.PREMIUM_MONTH_TIER_2 !== a0 && SubscriptionPlans.PREMIUM_GROUP_MONTH !== a0) {
if (SubscriptionPlans.PREMIUM_YEAR_TIER_2 === a0) {
return {
premiumType: PremiumTypes.TIER_2,
planInterval: SubscriptionIntervalTypes.YEAR
};
}
throw new Error(`Unsupported gifting planId: ${a0}`);
}
return {
premiumType: PremiumTypes.TIER_2,
planInterval: SubscriptionIntervalTypes.MONTH
};
}
export function isNitroLockedState(a0) {
return "isNitroLocked" in a0;
}
export const isPremiumAtLeast = _PremiumTypeUtils.isPremiumAtLeast;
export const isPremiumAtMost = _PremiumTypeUtils.isPremiumAtMost;
export const isPremium = _PremiumTypeUtils.isPremium;
export const isPremiumExactly = _PremiumTypeUtils.isPremiumExactly;
export function useHasTier2Premium() {
return _PremiumTypeUtils.isPremiumExactly(useStateFromStores([UserStore], () => UserStore.getCurrentUser()), PremiumTypes.TIER_2);
}
export function getOfferNoticeThreshold(a0) {
if (a0 != null && "trial_id" in a0) {
const trial_id = a0.trial_id;
if (PREMIUM_TIER_2_REVERSE_FOLLOWUP_TRIAL_ID === trial_id) {
return USER_PREMIUM_OFFER_EXPIRES_APPROACHING_4_DAY_THRESHOLD;
}
if (PREMIUM_TIER_2_TRIAL_FOR_EVERYONE_TRIAL_ID === trial_id) {
return TRIAL_FOR_EVERYONE_OFFER_EXPIRES_APPROACHING_THRESHOLD;
}
return USER_PREMIUM_OFFER_EXPIRES_APPROACHING_7_DAY_THRESHOLD;
}
if (a0 != null && "discountId" in a0) {
return USER_PREMIUM_OFFER_EXPIRES_APPROACHING_7_DAY_THRESHOLD;
}
return USER_PREMIUM_OFFER_EXPIRES_APPROACHING_7_DAY_THRESHOLD;
}
export function isTrialOffer(a0) {
return a0 != null && "trial_id" in a0;
}
export function isDiscountOffer(a0) {
return a0 != null && "discountId" in a0;
}
export function getFractionalPremiumUnitsHoursFromSkuIds(a0) {
return a0.reduce($mk72832(), 0);
}
export { getMonthlyPrice };
export function getSavingsPercent({ planId: planId2, isGift, priceOptions, subscriptionPlan }) {
let r8 = DISCOUNTS[planId2];
if (subscriptionPlan != null) {
r8 = calculateDiscountPercentageForYearlyPlan(subscriptionPlan, isGift, priceOptions);
}
return r8;
}
export { calculateMonthlyPriceEquivalentTotal };
export { calculateDiscountPercentageForYearlyPlan };