Loading
function(t,e,i){i.d(e,{J_:()=>R,N4:()=>T,l9:()=>m});var r=i(636537),s=i(228366),l=i(615405),n=i(927813),a=i(561573),u=i(937427);i(321073);var o=i(17928);let d={};function c(){d={}}class p extends o.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(s.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(),s={...d};for(let t of e)s[t]={state:"success",promotions:[],fetchedAt:r};for(let t of i){let e=t.applicationId;s[e]?.state==="success"&&s[e].promotions.push(t)}d=s},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 h extends I.A{id;applicationId;displayName;rewardType;rewardConfig;skuIds;appliesToAllSkus;startsAt;endsAt;static createFromServer(t){var e;return new h({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 A=i(652215);n.A.Millis.HOUR;let f=10*n.A.Millis.MINUTE,_=n.A.Millis.MINUTE;function E(t){return t?.type==="error"?f:_}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:n}=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 o=null!=n?{type:"application",applicationId:n}:{type:"skus",skuIds:i};try{s.h.dispatch({type:"SKUS_PRICING_FETCH_START",priceId:o});let t=u.A.getPromotionIdOverride(),e=(await r.Bo.get({url:A.Rsh.STOREFRONT_PRICES,query:{...null!=n?{application_id:n}:{sku_ids:i},country_code:l.A.ipCountryCode??void 0,...null!=t?{promotion_id_override:t}:{}},rejectWithError:!0})).body;s.h.dispatch({type:"SKUS_PRICING_FETCH_SUCCESS",priceId:o,data:(0,S.Oj)(e)})}catch{s.h.dispatch({type:"SKUS_PRICING_FETCH_FAIL",priceId:o})}}function R(t){s.h.dispatch({type:"STOREFRONT_PROMOTION_ID_OVERRIDE_SET",promotionIdOverride:t})}}