Loading
function(t,e,r){r.d(e,{x:()=>T,j:()=>g});var i=r(64700),l=r(636537),s=r(228366),n=r(615405),u=r(927813),o=r(561573);r(321073);var a=r(17928);let d={};class c extends a.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 c(s.h,{LOGOUT:function(){d={}},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:r}=t,i=Date.now(),l={...d};for(let t of e)l[t]={state:"success",promotions:[],fetchedAt:i};for(let t of r){let e=t.applicationId;l[e]?.state==="success"&&l[e].promotions.push(t)}d=l},STOREFRONT_PROMOTIONS_FETCH_FAIL:function(t){let{applicationIds:e}=t,r=Date.now();for(let t of e)d[t]={state:"error",fetchedAt:r}}});var p=r(723090),S=r(315069);class I extends S.A{id;applicationId;displayName;rewardType;rewardConfig;skuIds;appliesToAllSkus;startsAt;endsAt;static createFromServer(t){var e;return new I({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[r,i]of Object.entries(t))e[r]={priceTiers:i.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 _=r(652215);u.A.Millis.HOUR;let h=10*u.A.Millis.MINUTE,A=u.A.Millis.MINUTE;function f(t){return t?.type==="error"?h:A}async function E(t){let{applicationId:e}=t;await y({type:"application",applicationId:e})}async function m(t){let{skuIds:e}=t;await y({type:"skus",skuIds:e})}async function y(t){let{shouldFetch:e,filteredSkuIds:r,applicationId:i}=function(t){if("application"===t.type){let e=o.A.getFetchStateForApplicationId(t.applicationId),r=f(e);return null!=e&&("loading"===e.type||e.fetchedAt>Date.now()-r)?{shouldFetch:!1,filteredSkuIds:[],applicationId:t.applicationId}:{shouldFetch:!0,filteredSkuIds:[],applicationId:t.applicationId}}{let e=t.skuIds.filter(t=>{let e=o.A.getFetchStateForSkuId(t);if(null==e)return!0;let r=f(e);return"loading"!==e.type&&e.fetchedAt<Date.now()-r}).sort((t,e)=>{let r=o.A.getFetchStateForSkuId(t),i=o.A.getFetchStateForSkuId(e);return null==r&&null!=i?-1:+(null!=r&&null==i)});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!=i?{type:"application",applicationId:i}:{type:"skus",skuIds:r};try{s.h.dispatch({type:"SKUS_PRICING_FETCH_START",priceId:u});let t=(await l.Bo.get({url:_.Rsh.STOREFRONT_PRICES,query:{...null!=i?{application_id:i}:{sku_ids:r},country_code:n.A.ipCountryCode??void 0},rejectWithError:!0})).body;s.h.dispatch({type:"SKUS_PRICING_FETCH_SUCCESS",priceId:u,data:(0,p.Oj)(t)})}catch{s.h.dispatch({type:"SKUS_PRICING_FETCH_FAIL",priceId:u})}}function T(t){let{applicationId:e}=t;i.useEffect(()=>{null!=e&&E({applicationId:e})},[e])}function g(t){let{skuIds:e}=t;i.useEffect(()=>{0!==e.length&&m({skuIds:e})},[e])}}