(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{withFilteredAttributes:()=>w,withProductDataContext:()=>p});const r=window.wp.element,o=window.wc.wcBlocksData,n=window.wp.data,a=window.wp.isShallowEqual;var s=e.n(a);function c(e){const t=(0,r.useRef)(e);return s()(e,t.current)||(t.current=e),t.current}const u=e=>{const t={namespace:"/wc/store/v1",resourceName:"products"},{results:a,isLoading:s}=(e=>{const{namespace:t,resourceName:a,resourceValues:s=[],query:u={},shouldSelect:i=!0}=e;if(!t||!a)throw new Error("The options object must have valid values for the namespace and the resource properties.");const l=(0,r.useRef)({results:[],isLoading:!0}),d=c(u),p=c(s),w=(()=>{const[,e]=(0,r.useState)();return(0,r.useCallback)((t=>{e((()=>{throw t}))}),[])})(),h=(0,n.useSelect)((e=>{if(!i)return null;const r=e(o.COLLECTIONS_STORE_KEY),n=[t,a,d,p],s=r.getCollectionError(...n);if(s){if(!(s instanceof Error))throw new Error("TypeError: `error` object is not an instance of Error constructor");w(s)}return{results:r.getCollection(...n),isLoading:!r.hasFinishedResolution("getCollection",n)}}),[t,a,p,d,i]);return null!==h&&(l.current=h),l.current})({...t,query:e}),{value:u}=((e,t)=>{const{namespace:r,resourceName:a,resourceValues:s=[],query:u={}}=t;if(!r||!a)throw new Error("The options object must have valid values for the namespace and the resource name properties.");const i=c(u),l=c(s),{value:d,isLoading:p=!0}=(0,n.useSelect)((t=>{const n=t(o.COLLECTIONS_STORE_KEY),s=[e,r,a,i,l];return{value:n.getCollectionHeader(...s),isLoading:n.hasFinishedResolution("getCollectionHeader",s)}}),[e,r,a,l,i]);return{value:d,isLoading:p}})("x-wp-total",{...t,query:e});return{products:a,totalProducts:parseInt(u,10),productsLoading:s}},i=window.wc.wcBlocksSharedContext,l=(e,t)=>e.find((e=>e.id===t)),d=e=>{const{productId:t,OriginalComponent:o,postId:n,product:a}=e,s=null!=e&&e.isDescendentOfQueryLoop?n:t,{products:c,productsLoading:d}=u({include:s}),p={product:s>0&&c.length>0?l(c,s):null,isLoading:d};return a?(0,r.createElement)(i.ProductDataContextProvider,{product:a,isLoading:!1},(0,r.createElement)(o,{...e})):(0,r.createElement)(i.ProductDataContextProvider,{product:p.product,isLoading:p.isLoading},(0,r.createElement)(o,{...e}))},p=e=>t=>{const o=(0,i.useProductDataContext)();return t.product||!o.hasContext?(0,r.createElement)(d,{...t,OriginalComponent:e}):(0,r.createElement)(e,{...t})},w=e=>t=>o=>{const n=((e,t)=>{const r=[];return Object.keys(e).forEach((o=>{if(void 0!==t[o])switch(e[o].type){case"boolean":r[o]="false"!==t[o]&&!1!==t[o];break;case"number":r[o]=parseInt(t[o],10);break;case"array":case"object":r[o]=JSON.parse(t[o]);break;default:r[o]=t[o]}else r[o]=e[o].default})),r})(e,o);return(0,r.createElement)(t,{...o,...n})};(this.wc=this.wc||{}).wcBlocksSharedHocs=t})();