Loading
function(t,e,i){i.d(e,{J_:()=>R,N4:()=>T,l9:()=>m});var r=i(636537),n=i(228366),s=i(615405),l=i(927813),a=i(561573),o=i(937427);i(321073);var u=i(17928);let d={};function c(){d={}}class p extends u.Ay.Store{static displayName="StorefrontPromotionStore";getFetchState(t){return d[t]?.state}getFetchedAt(t){let e=d[t];if(e?.state==="success"||e?.state==="error")return e.fetchedAt}getPromotionsForApplication(t){let e=d[t];return e?.state==="success"||e?.state==="loading"?e.promotions??null:null}}new p(n.h,{LOGOUT:c,STOREFRONT_PROMOTIONS_FETCH_START:function(t){let{applicationIds:e}=t;for(let t of e){let e=d[t];d[t]={state:"loading",promotions:e?.state==="success"?[...e.promotions]:void 0}}},STOREFRONT_PROMOTIONS_FETCH_SUCCESS:function(t){let{applicationIds:e,promotions:i}=t,r=Date.now(),n={...d};for(let t of e)n[t]={state:"success",promotions:[],fetchedAt:r};for(let t of i){let e=t.applicationId;n[e]?.state==="success"&&n[e].promotions.push(t)}d=n},STOREFRONT_PROMOTIONS_FETCH_FAIL:function(t){let{applicationIds:e}=t,i=Date.now();for(let t of e)d[t]={state:"error",fetchedAt:i}},STOREFRONT_PROMOTION_ID_OVERRIDE_SET:c});var S=i(117218),I=i(315069);class f extends I.A{id;applicationId;displayName;rewardType;rewardConfig;skuIds;appliesToAllSkus;startsAt;endsAt;static createFromServer(t){var e;return new f({id:t.id,applicationId:t.application_id,displayName:t.display_name??null,rewardType:t.reward_type,rewardConfig:null!=t.reward_config?null==(e=t.reward_config)?null:{discount:null!=e.discount?{id:e.discount.id,type:e.discount.type,amount:e.discount.amount}:null}:null,skuIds:function(t){if(null==t)return null;let e={};for(let[i,r]of Object.entries(t))e[i]={priceTiers:r.price_tiers};return e}(t.sku_ids),appliesToAllSkus:t.applies_to_all_skus,startsAt:null!=t.starts_at?new Date(t.starts_at):null,endsAt:null!=t.ends_at?new Date(t.ends_at):null})}constructor(t){super(),this.id=t.id,this.applicationId=t.applicationId,this.displayName=t.displayName,this.rewardType=t.rewardType,this.rewardConfig=t.rewardConfig,this.skuIds=t.skuIds,this.appliesToAllSkus=t.appliesToAllSkus,this.startsAt=t.startsAt,this.endsAt=t.endsAt}}var h=i(652215);l.A.Millis.HOUR;let A=10*l.A.Millis.MINUTE,_=l.A.Millis.MINUTE;function E(t){return t?.type==="error"?A:_}async function m(t){let{applicationId:e}=t;await y({type:"application",applicationId:e})}async function T(t){let{skuIds:e}=t;await y({type:"skus",skuIds:e})}async function y(t){let{shouldFetch:e,filteredSkuIds:i,applicationId:l}=function(t){if("application"===t.type){let e=a.A.getFetchStateForApplicationId(t.applicationId),i=E(e);return null!=e&&("loading"===e.type||e.fetchedAt>Date.now()-i)?{shouldFetch:!1,filteredSkuIds:[],applicationId:t.applicationId}:{shouldFetch:!0,filteredSkuIds:[],applicationId:t.applicationId}}{let e=t.skuIds.filter(t=>{let e=a.A.getFetchStateForSkuId(t);if(null==e)return!0;let i=E(e);return"loading"!==e.type&&e.fetchedAt<Date.now()-i}).sort((t,e)=>{let i=a.A.getFetchStateForSkuId(t),r=a.A.getFetchStateForSkuId(e);return null==i&&null!=r?-1:+(null!=i&&null==r)});return 0===e.length?{shouldFetch:!1,filteredSkuIds:[],applicationId:null}:{shouldFetch:!0,filteredSkuIds:e.slice(0,50),applicationId:null}}}(t);if(!e)return;let u=null!=l?{type:"application",applicationId:l}:{type:"skus",skuIds:i};try{n.h.dispatch({type:"SKUS_PRICING_FETCH_START",priceId:u});let t=o.A.getPromotionIdOverride(),e=(await r.Bo.get({url:h.Rsh.STOREFRONT_PRICES,query:{...null!=l?{application_id:l}:{sku_ids:i},country_code:s.A.ipCountryCode??void 0,...null!=t?{promotion_id_override:t}:{}},rejectWithError:!0})).body;n.h.dispatch({type:"SKUS_PRICING_FETCH_SUCCESS",priceId:u,data:(0,S.Oj)(e)})}catch{n.h.dispatch({type:"SKUS_PRICING_FETCH_FAIL",priceId:u})}}function R(t){n.h.dispatch({type:"STOREFRONT_PROMOTION_ID_OVERRIDE_SET",promotionIdOverride:t})}}