Loading
function(t,e,r){r.d(e,{A:()=>P});var l=r(64700),o=r(228366),c=r(181658),n=r(773669),u=r(927813),s=r(371794),a=r(17928);let S={},_={};class i extends a.Ay.Store{static displayName="StorefrontCollectionStore";getFetchState(t){return null!=t?S[t]?.state:void 0}getFetchStateForApplication(t){return null!=t?_[t]?.state:void 0}getFetchedAt(t){return null!=t?S[t]?.fetchedAt:void 0}getFetchedAtForApplication(t){return null!=t?_[t]?.fetchedAt:void 0}getFetchError(t){return null!=t?S[t]?.fetchError:void 0}getFetchErrorForApplication(t){return null!=t?_[t]?.fetchError:void 0}getCollection(t){let e=null!=t?S[t]:null;return null==e||e?.state==="error"||null==e.collection?null:e.collection}getCollectionsForApplication(t){let e=null!=t?_[t]:null;return null==e||"error"===e.state||null==e.collections?null:e.collections}}let d=new i(o.h,{STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH:t=>{let{collectionIds:e}=t;e.forEach(t=>{S[t]={state:"loading",collection:S[t]?.collection}})},STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_SUCCESS:t=>{let{collectionIds:e,collections:r}=t,l=Date.now(),o=new Set;r.forEach(t=>{o.add(t.id),S[t.id]={state:"success",collection:t,fetchedAt:l}}),e.forEach(t=>{o.has(t)||delete S[t]})},STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_FAILURE:t=>{let{collectionIds:e,apiError:r}=t,l=Date.now();e.forEach(t=>{S[t]={state:"error",fetchedAt:l,fetchError:r}})},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH:t=>{let{applicationId:e}=t;_[e]={state:"loading",collections:_[e]?.collections}},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH_SUCCESS:t=>{let{applicationId:e,collections:r}=t,l=Date.now();_[e]={state:"success",collections:r,fetchedAt:l},r.forEach(t=>{S[t.id]={state:"success",collection:t,fetchedAt:l}})},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH_FAILURE:t=>{let{applicationId:e,apiError:r}=t;_[e]={state:"error",fetchedAt:Date.now(),fetchError:r}},LOGOUT:t=>{S={},_={}}});var T=r(442007),E=r(652215);let h=12*u.A.Millis.HOUR,O=10*u.A.Millis.MINUTE;async function C(t){let{collectionIds:e,includeUnpublishedProducts:r=!1,includeUnpublishedCollections:l=!1,ignoreCache:u=!1}=t,a=e.filter(t=>{if(!t)return!1;let e=d.getFetchState(t);if("loading"===e)return!1;let r=d.getFetchedAt(t);return null==r||Date.now()-r>("error"===e?O:h)});if(0!==a.length)try{o.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH",collectionIds:a});let t=await (0,s.aP)({url:E.Rsh.STOREFRONT_COLLECTIONS_WITH_PRODUCTS,query:{collection_ids:a,locale:n.default.locale,with_bundled_skus:!0,include_google_sku_ids:!1,include_unpublished_products:r,include_unpublished_collections:l,ignore_cache:u},rejectWithError:!0});o.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_SUCCESS",collectionIds:a,collections:t.body.collections.map(T.A.fromServer)})}catch(t){o.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_FAILURE",collectionIds:a,apiError:new c.A(t)})}}r(321073);let F={},R={};class f extends a.Ay.Store{static displayName="StorefrontProductStore";getFetchState(t){return null!=t?F[t]?.state:void 0}getFetchStateForSku(t){return null!=t?R[t]?.state:void 0}getFetchedAt(t){return null!=t?F[t]?.fetchedAt:void 0}getFetchedAtForSku(t){return null!=t?R[t]?.fetchedAt:void 0}getFetchError(t){return null!=t?F[t]?.fetchError:void 0}getFetchErrorForSku(t){return null!=t?R[t]?.fetchError:void 0}getProduct(t){let e=null!=t?F[t]:null;return null==e||e?.state==="error"||null==e.product?null:e.product}getProductsForSku(t){return null!=t?R[t]?.products:void 0}}let I=new f(o.h,{STOREFRONT_PRODUCTS_WITH_SKUS_FETCH:t=>{let{productIds:e}=t;e.forEach(t=>{F[t]={state:"loading",product:F[t]?.product}})},STOREFRONT_PRODUCTS_WITH_SKUS_FETCH_SUCCESS:t=>{let{productIds:e,products:r}=t,l=Date.now(),o=new Set;r.forEach(t=>{o.add(t.id),F[t.id]={state:"success",product:t,fetchedAt:l}}),e.forEach(t=>{o.has(t)||delete F[t]})},STOREFRONT_PRODUCTS_WITH_SKUS_FETCH_FAILURE:t=>{let{productIds:e,apiError:r}=t,l=Date.now();e.forEach(t=>{F[t]={state:"error",fetchedAt:l,fetchError:r}})},STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH:t=>{let{skuIds:e}=t;e.forEach(t=>{R[t]={state:"loading",products:R[t]?.products}})},STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH_SUCCESS:t=>{let{skuIds:e,products:r}=t,l=Date.now(),o=r.reduce((t,e)=>(e.skuIds.forEach(r=>{null==t[r]?t[r]=[e]:t[r].push(e)}),t),{});e.forEach(t=>{null==o[t]?delete R[t]:R[t]={state:"success",products:o[t],fetchedAt:l}}),r.forEach(t=>{F[t.id]={state:"success",product:t,fetchedAt:l}})},STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH_FAILURE:t=>{let{skuIds:e,apiError:r}=t,l=Date.now();e.forEach(t=>{R[t]={state:"error",fetchedAt:l,fetchError:r}})},STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_SUCCESS:t=>{let{collections:e}=t,r=Date.now();e.forEach(t=>{t.products.forEach(t=>{F[t.id]={state:"success",product:t,fetchedAt:r}})})},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH_SUCCESS:t=>{let{collections:e}=t,r=Date.now();e.forEach(t=>{t.products.forEach(t=>{F[t.id]={state:"success",product:t,fetchedAt:r}})})},LOGOUT:t=>{F={},R={}}});var p=r(103348);let U=12*u.A.Millis.HOUR,g=10*u.A.Millis.MINUTE;async function A(t){let{skuIds:e,ignoreCache:r=!1}=t,l=e.filter(t=>{if(!t)return!1;let e=I.getFetchStateForSku(t);if("loading"===e)return!1;let r=I.getFetchedAtForSku(t);return null==r||Date.now()-r>("error"===e?g:U)});if(0!==l.length)try{o.h.dispatch({type:"STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH",skuIds:l});let t=await (0,s.aP)({url:E.Rsh.STOREFRONT_PRODUCTS_BY_SKU_IDS,query:{sku_ids:l,locale:n.default.locale,with_bundled_skus:!0,include_google_sku_ids:!1,ignore_cache:r},rejectWithError:!0});o.h.dispatch({type:"STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH_SUCCESS",skuIds:l,products:t.body.products.map(p.A.fromServer)})}catch(t){o.h.dispatch({type:"STOREFRONT_PRODUCTS_BY_SKU_IDS_FETCH_FAILURE",skuIds:l,apiError:new c.A(t)})}}var N=r(564064),D=r(510801),L=r(986630);function H(t,e){let[r,o]=l.useState({id:t,sawFetch:!1}),c=r.sawFetch;return r.id!==t?o({id:t,sawFetch:c=null!=e}):null==e||r.sawFetch||o({id:t,sawFetch:c=!0}),""!==t&&null==e&&c}function P(t){let{needsCategory:e=!0,seedCategoryStore:r=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{products:o,fetchState:c}=function(t){let{skuId:e,ignoreCache:r=!1}=t;return l.useEffect(()=>{A({skuIds:[e],ignoreCache:r})},[e,r]),(0,a.cf)([I],()=>({products:I.getProductsForSku(e),fetchState:I.getFetchStateForSku(e),fetchedAt:I.getFetchedAtForSku(e),fetchError:I.getFetchErrorForSku(e)}))}({skuId:t}),n=o?.[0],u=e?n?.primaryCollectionId??"":"",{collection:s,fetchState:S}=function(t){let{collectionId:e,includeUnpublishedProducts:r=!1,includeUnpublishedCollections:o=!1,ignoreCache:c=!1}=t;return l.useEffect(()=>{C({collectionIds:[e],includeUnpublishedProducts:r,includeUnpublishedCollections:o,ignoreCache:c})},[e,r,o,c]),(0,a.cf)([d],()=>({collection:d.getCollection(e),fetchState:d.getFetchState(e),fetchedAt:d.getFetchedAt(e),fetchError:d.getFetchError(e)}))}({collectionId:u}),_=l.useMemo(()=>null!=n?L.A.fromStorefrontProductRecord(n)??null:null,[n]),i=l.useMemo(()=>e&&null!=s?D.A.fromStorefrontCollectionRecord(s):null,[e,s]),T=H(t,c),E=H(e?u:"",S),h=l.useMemo(()=>"error"===c||T||e&&("error"===S||E)||"success"===c&&(null==_||e&&""===u)?"error":null==_||e&&null==i?"loading":"ready",[c,T,S,E,e,u,_,i]);return l.useEffect(()=>{r&&null!=_&&(0,N.rh)(_)},[r,_]),{product:_,category:i,state:h,retry:l.useCallback(()=>{A({skuIds:[t],ignoreCache:!0}),e&&""!==u&&C({collectionIds:[u],ignoreCache:!0})},[t,e,u])}}}