Loading
function(e,t,n){n.d(t,{h:()=>H,I:()=>N});var r=n(64700),l=n(17928),i=n(228366),s=n(181658),o=n(773669),a=n(927813),u=n(371794);let c={},d={};class f extends l.Ay.Store{static displayName="StorefrontCollectionStore";getFetchState(e){return null!=e?c[e]?.state:void 0}getFetchStateForApplication(e){return null!=e?d[e]?.state:void 0}getFetchedAt(e){return null!=e?c[e]?.fetchedAt:void 0}getFetchedAtForApplication(e){return null!=e?d[e]?.fetchedAt:void 0}getFetchError(e){return null!=e?c[e]?.fetchError:void 0}getFetchErrorForApplication(e){return null!=e?d[e]?.fetchError:void 0}getCollection(e){let t=null!=e?c[e]:null;return null==t||t?.state==="error"||null==t.collection?null:t.collection}getCollectionsForApplication(e){let t=null!=e?d[e]:null;return null==t||"error"===t.state||null==t.collections?null:t.collections}}let C=new f(i.h,{STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH:function(e){let{collectionIds:t}=e;t.forEach(e=>{c[e]={state:"loading",collection:c[e]?.collection}})},STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_SUCCESS:function(e){let{collectionIds:t,collections:n}=e,r=Date.now(),l=new Set;n.forEach(e=>{l.add(e.id),c[e.id]={state:"success",collection:e,fetchedAt:r}}),t.forEach(e=>{l.has(e)||delete c[e]})},STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_FAILURE:function(e){let{collectionIds:t,apiError:n}=e,r=Date.now();t.forEach(e=>{c[e]={state:"error",fetchedAt:r,fetchError:n}})},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH:function(e){let{applicationId:t}=e;d[t]={state:"loading",collections:d[t]?.collections}},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH_SUCCESS:function(e){let{applicationId:t,collections:n}=e,r=Date.now();d[t]={state:"success",collections:n,fetchedAt:r},n.forEach(e=>{c[e.id]={state:"success",collection:e,fetchedAt:r}})},STOREFRONT_COLLECTIONS_FOR_APPLICATION_FETCH_FAILURE:function(e){let{applicationId:t,apiError:n}=e;d[t]={state:"error",fetchedAt:Date.now(),fetchError:n}},LOGOUT:function(e){c={},d={}}});var p=n(442007),I=n(652215);let g=12*a.A.Millis.HOUR,h=10*a.A.Millis.MINUTE;async function _(e){let{collectionIds:t,includeUnpublishedProducts:n=!1,includeUnpublishedCollections:r=!1,ignoreCache:l=!1}=e,a=t.filter(e=>{if(!e)return!1;let t=C.getFetchState(e);if("loading"===t)return!1;let n=C.getFetchedAt(e);return null==n||Date.now()-n>("error"===t?h:g)});if(0!==a.length)try{i.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH",collectionIds:a});let e=await (0,u.aP)({url:I.Rsh.STOREFRONT_COLLECTIONS_WITH_PRODUCTS,query:{collection_ids:a,locale:o.default.locale,with_bundled_skus:!0,include_google_sku_ids:!1,include_unpublished_products:n,include_unpublished_collections:r,ignore_cache:l},rejectWithError:!0});i.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_SUCCESS",collectionIds:a,collections:e.body.collections.map(p.A.fromServer)})}catch(e){i.h.dispatch({type:"STOREFRONT_COLLECTIONS_WITH_PRODUCTS_FETCH_FAILURE",collectionIds:a,apiError:new s.A(e)})}}var A=n(540737),E=n(821925),m=n(662388);n(321073);let k=new Set,x=new Set,T=null,v=null;function R(e){let t=[];for(let n=0;n<e.length;n+=100)t.push(e.slice(n,n+100));return t}function S(){T=null;let e=[...k];for(let t of(k.clear(),R(e)))(0,A.tu)({skuIds:t})}function O(){v=null;let e=[...x];for(let t of(x.clear(),R(e)))_({collectionIds:t})}let y={requestProducts(e){for(let t of e)""!==t&&"loading"!==E.A.getFetchStateForSku(t)&&k.add(t);k.size>0&&null==T&&(T=setTimeout(S,32))},requestCollections(e){for(let t of e)""!==t&&"loading"!==C.getFetchState(t)&&x.add(t);x.size>0&&null==v&&(v=setTimeout(O,32))},reset(){k.clear(),x.clear(),null!=T&&(clearTimeout(T),T=null),null!=v&&(clearTimeout(v),v=null)}};i.h.subscribe("LOGOUT",y.reset);var L=n(510801),P=n(986630);function j(e){let{productFetchState:t,productAbsent:n,collectionFetchState:r,collectionAbsent:l,needsCategory:i,collectionId:s,product:o,category:a}=e;return"error"===t||n||i&&("error"===r||l)||"success"===t&&(null==o||i&&""===s)?"error":null==o||i&&null==a?"loading":"ready"}function b(e,t){let[n,l]=r.useState({id:e,sawFetch:!1}),i=n.sawFetch;return n.id!==e?l({id:e,sawFetch:i=null!=t}):null==t||n.sawFetch||l({id:e,sawFetch:i=!0}),""!==e&&null==t&&i}function N(e){let{needsCategory:t=!0,seedCategoryStore:n=!1,shouldFetchProduct:i=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.useEffect(()=>{i&&y.requestProducts([e])},[e,i]);let{products:s,fetchState:o}=(0,l.cf)([E.A],()=>({products:E.A.getProductsForSku(e),fetchState:E.A.getFetchStateForSku(e)}),[e]),a=s?.[0],u=t?a?.primaryCollectionId??"":"";r.useEffect(()=>{t&&""!==u&&y.requestCollections([u])},[t,u]);let{collection:c,fetchState:d}=(0,l.cf)([C],()=>({collection:C.getCollection(u),fetchState:C.getFetchState(u)}),[u]),f=r.useMemo(()=>null!=a?P.A.fromStorefrontProductRecord(a)??null:null,[a]),p=r.useMemo(()=>t&&null!=c?L.A.fromStorefrontCollectionRecord(c):null,[t,c]),I=b(e,o),g=b(t?u:"",d),h=r.useMemo(()=>j({productFetchState:o,productAbsent:I,collectionFetchState:d,collectionAbsent:g,needsCategory:t,collectionId:u,product:f,category:p}),[o,I,d,g,t,u,f,p]);return r.useEffect(()=>{n&&null!=f&&(0,m.rh)(f)},[n,f]),{product:f,category:p,state:h,retry:r.useCallback(()=>{(0,A.tu)({skuIds:[e],ignoreCache:!0}),t&&""!==u&&_({collectionIds:[u],ignoreCache:!0})},[e,t,u])}}function F(e){let[t,n]=r.useState(()=>new Set),l=Object.entries(e).filter(e=>{let[t,n]=e;return""!==t&&null!=n}).map(e=>{let[t]=e;return t}),i=l.some(e=>!t.has(e)),s=i?new Set([...t,...l]):t;i&&n(s);let o=new Set;for(let[t,n]of Object.entries(e))""!==t&&null==n&&s.has(t)&&o.add(t);return o}function H(e){let{needsCategory:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.useMemo(()=>e.filter(e=>""!==e),[e]),i=n.join(",");r.useEffect(()=>{n.length>0&&y.requestProducts(n)},[i]);let s=(0,l.cf)([E.A],()=>{let e={};for(let t of n)e[t]=E.A.getProductsForSku(t)?.[0];return e},[n]),o=(0,l.cf)([E.A],()=>{let e={};for(let t of n)e[t]=E.A.getFetchStateForSku(t);return e},[n]),a=r.useMemo(()=>{let e={};for(let r of n)e[r]=t?s[r]?.primaryCollectionId??"":"";return e},[n,s,t]),u=r.useMemo(()=>[...new Set(Object.values(a).filter(e=>""!==e))],[a]),c=u.join(",");r.useEffect(()=>{t&&u.length>0&&y.requestCollections(u)},[t,c]);let d=(0,l.cf)([C],()=>{let e={};for(let t of u)e[t]=C.getCollection(t);return e},[u]),f=(0,l.cf)([C],()=>{let e={};for(let t of u)e[t]=C.getFetchState(t);return e},[u]),p=F(o),I=F(f);return r.useMemo(()=>{let e={};for(let r of n){let n=s[r],l=o[r],i=a[r]??"",u=d[i]??null,c=f[i],C=null!=n?P.A.fromStorefrontProductRecord(n)??null:null,g=t&&null!=u?L.A.fromStorefrontCollectionRecord(u):null;e[r]={product:C,category:g,state:j({productFetchState:l,productAbsent:p.has(r),collectionFetchState:c,collectionAbsent:""!==i&&I.has(i),needsCategory:t,collectionId:i,product:C,category:g})}}return e},[n,s,o,a,d,f,p,I,t])}}