173 lines
5.2 KiB
TypeScript
173 lines
5.2 KiB
TypeScript
// Metro module 6220 (f6221).
|
|
import Record from "../../../lib/Record";
|
|
import add from "../../../_bundle/add_5671";
|
|
import { formatPrice } from "../../../utils/PriceUtils";
|
|
import { $callWithNewTarget } from "../../../_hermes/prelude";
|
|
class AvailablePlanRecord extends Record {
|
|
constructor(a0) {
|
|
super();
|
|
this.id = a0.id;
|
|
this.quantity = a0.quantity;
|
|
this.price = a0.price;
|
|
this.total = a0.total;
|
|
let addOnPlans = a0.addOnPlans;
|
|
if (addOnPlans == null) {
|
|
addOnPlans = [];
|
|
}
|
|
this.addOnPlans = addOnPlans;
|
|
}
|
|
static createFromServer(a0) {
|
|
const { id, quantity, price, total } = a0;
|
|
let add_on_plans = a0.add_on_plans;
|
|
if (add_on_plans == null) {
|
|
add_on_plans = [];
|
|
}
|
|
const prototypeOf = Object.getPrototypeOf(AvailablePlanRecord);
|
|
const r15 = Object.create(AvailablePlanRecord.prototype);
|
|
const r16 = $callWithNewTarget(prototypeOf, r15, AvailablePlanRecord);
|
|
const r17 = r16 instanceof Object ? r16 : r15;
|
|
r17.id = id;
|
|
r17.quantity = quantity;
|
|
r17.price = price;
|
|
r17.total = total;
|
|
if (add_on_plans == null) {
|
|
add_on_plans = [];
|
|
}
|
|
r17.addOnPlans = add_on_plans;
|
|
return r17;
|
|
}
|
|
getPlanQuantities() {
|
|
const map = new Map([[this.id, this.quantity]]);
|
|
for (const addOnPlan of this.addOnPlans) {
|
|
const r34 = addOnPlan;
|
|
const id = addOnPlan.id;
|
|
let r37 = map.get(addOnPlan.id);
|
|
if (r37 == null) {
|
|
r37 = 0;
|
|
}
|
|
map.set(id, r37 + r34.quantity);
|
|
}
|
|
return map;
|
|
}
|
|
matchesItems(a0) {
|
|
return (function quantitiesEqual(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;
|
|
})(this.getPlanQuantities(), (function toQuantitiesByPlanId(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;
|
|
})(a0));
|
|
}
|
|
getPriceString() {
|
|
const total = this.total;
|
|
return formatPrice(new add(total.amount).dividedBy(10 ** total.exponent).toNumber(), total.currency, {
|
|
convertToMajorUnits: false
|
|
});
|
|
}
|
|
getAddOnPrice() {
|
|
if (this.addOnPlans.length === 0) {
|
|
return null;
|
|
}
|
|
const price = this.addOnPlans[0].price;
|
|
const { currency, exponent } = price;
|
|
return {
|
|
majorUnits: new add(this.addOnPlans.reduce((acc, addOnPlan) => acc + addOnPlan.price.amount * addOnPlan.quantity, 0)).dividedBy(10 ** exponent).toNumber(),
|
|
currency
|
|
};
|
|
}
|
|
}
|
|
class CheckoutContextRecord extends Record {
|
|
constructor(a0) {
|
|
super();
|
|
let paymentSources = a0.paymentSources;
|
|
if (paymentSources == null) {
|
|
paymentSources = [];
|
|
}
|
|
this.paymentSources = paymentSources;
|
|
let storeCountry = a0.storeCountry;
|
|
if (storeCountry == null) {
|
|
storeCountry = null;
|
|
}
|
|
this.storeCountry = storeCountry;
|
|
let allowedCurrencies = a0.allowedCurrencies;
|
|
if (allowedCurrencies == null) {
|
|
allowedCurrencies = [];
|
|
}
|
|
this.allowedCurrencies = allowedCurrencies;
|
|
let availablePlans = a0.availablePlans;
|
|
if (availablePlans == null) {
|
|
availablePlans = [];
|
|
}
|
|
this.availablePlans = availablePlans;
|
|
}
|
|
static createFromOrder(a0) {
|
|
const checkout_context = a0?.checkout_context;
|
|
const r13 = checkout_context == null;
|
|
let r14 = null;
|
|
if (!r13) {
|
|
let payment_sources = checkout_context.payment_sources;
|
|
if (payment_sources == null) {
|
|
payment_sources = [];
|
|
}
|
|
let storeCountry = checkout_context.store_country != null ? checkout_context.store_country.country : null;
|
|
let allowed_currencies = checkout_context.allowed_currencies;
|
|
if (allowed_currencies == null) {
|
|
allowed_currencies = [];
|
|
}
|
|
let available_plans = checkout_context.available_plans;
|
|
if (available_plans == null) {
|
|
available_plans = [];
|
|
}
|
|
let availablePlans = available_plans.map(AvailablePlanRecord.createFromServer);
|
|
const prototypeOf = Object.getPrototypeOf(CheckoutContextRecord);
|
|
const r25 = Object.create(CheckoutContextRecord.prototype);
|
|
const r26 = $callWithNewTarget(prototypeOf, r25, CheckoutContextRecord);
|
|
if (payment_sources == null) {
|
|
payment_sources = [];
|
|
}
|
|
const r28 = r26 instanceof Object ? r26 : r25;
|
|
r28.paymentSources = payment_sources;
|
|
if (storeCountry == null) {
|
|
storeCountry = null;
|
|
}
|
|
r28.storeCountry = storeCountry;
|
|
if (allowed_currencies == null) {
|
|
allowed_currencies = [];
|
|
}
|
|
r28.allowedCurrencies = allowed_currencies;
|
|
if (availablePlans == null) {
|
|
availablePlans = [];
|
|
}
|
|
r28.availablePlans = availablePlans;
|
|
r14 = r28;
|
|
}
|
|
return r14;
|
|
}
|
|
getAvailablePlanForItems(c15593_0) {
|
|
let r7 = this.availablePlans.find((availablePlan) => availablePlan.matchesItems(c15593_0));
|
|
if (r7 == null) {
|
|
r7 = null;
|
|
}
|
|
return r7;
|
|
}
|
|
}
|
|
export default CheckoutContextRecord;
|
|
export { AvailablePlanRecord };
|