"use strict";(self.webpackChunkshopwp=self.webpackChunkshopwp||[]).push([["CollectionProducts-public"],{XyGs:function(e,t,r){r.d(t,{H:function(){return a},I:function(){return n}});var o=r("r+mp");function n(){var e=wp.element.useContext(o.g);if(!e)throw new Error("useCollectionState must be used within the CollectionProvider");return e}function a(){var e=wp.element.useContext(o.u);if(!e)throw new Error("useCollectionDispatch must be used within the CollectionProvider");return e}},zDbN:function(e,t,r){r.r(t),r.d(t,{default:function(){return C}});var o=r("a6K/"),n=r("8fid"),a=r("LpH3"),l=r("1hfm"),c=r("dGr1"),s=r("DGrm"),i=r("XyGs");function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){(0,n.Z)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var y={name:"y0nm4u-CollectionsSortingWrapperCSS",styles:"width:100%;display:flex;align-items:flex-end;justify-content:flex-end;margin-bottom:20px;align-items:baseline;#swp-collections-sorting *:hover{cursor:pointer;};label:CollectionsSortingWrapperCSS;"},d=function(e){var t=e.settings,r=(0,i.H)(),o=(0,i.I)(),n=y,u=[{label:"Title (A-Z)",value:"TITLE"},{label:"Title (Z-A)",value:"TITLE-REVERSE"},{label:"Price (Low to high)",value:"PRICE"},{label:"Price (high to low)",value:"PRICE-REVERSE"},{label:"Best Selling",value:"BEST_SELLING"},{label:"Recently Added",value:"CREATED"},{label:"Collection default",value:"COLLECTION_DEFAULT"},{label:"Manual",value:"MANUAL"}];return(0,a.tZ)("div",{css:n},o.isLoading&&(0,a.tZ)(s.default,{color:"#000"}),(0,a.tZ)(l.Z,{labelText:wp.i18n.__("Sort by:","shopwp"),selectId:"swp-collections-sorting",options:u,customOnChange:function(e){var t=(0,c.OW)(e.value),n=p(p({},o.productQueryParams),t);r({type:"SET_CURSOR",payload:!1}),r({type:"SET_PRODUCT_QUERY_PARAMS",payload:n}),r({type:"SET_IS_FETCHING_NEW",payload:!0}),r({type:"SET_SHOULD_REPLACE",payload:!0})},defaultValue:(0,c.j5)(u,t.sortBy,t.reverse),isLoading:o.isLoading}))},E=r("U039"),f=r("Qu7M"),O=r("V+k2"),g=r("16zp"),b=r("MesI"),S=r("3mso"),P=r.n(S),m=r("/FEU"),h=r.n(m);function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}var v=r("38MY"),C=function(){var e=(0,i.I)(),t=(0,i.H)(),r=(0,f.Q)(),a=(0,O.v)();return(0,E.sc)(),function(e,t,r){(0,b.useQuery)(["fetchProductsByCollections",e.productQueryParams,e.cursor],(function(){return t({type:"SET_IS_LOADING",payload:!0}),(0,g.tb)(e.productQueryParams,r,e.cursor)}),function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?T(Object(r),!0).forEach((function(t){(0,n.Z)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):T(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({enabled:e.isFetchingNew,retry:!1,onError:function(e){t({type:"SET_IS_LOADING",payload:!1}),t({type:"SET_IS_FETCHING_NEW",payload:!1}),console.error("ShopWP fetchProductsByCollections Error",e)},onSuccess:function(r){if(t({type:"SET_IS_LOADING",payload:!1}),t({type:"SET_IS_FETCHING_NEW",payload:!1}),(0,g.HL)(!1,r,t))t({type:"SET_PRODUCTS",payload:{products:[],replace:!0}});else if(r&&!P()(r)&&(!h()(r,"edges")||r.edges&&r.edges.length)){t({type:"SET_PRODUCTS",payload:{products:r.edges,replace:e.shouldReplace}});var o=(0,c.lV)(r);t({type:"SET_CURSOR",payload:o.cursor})}else t({type:"SET_PRODUCTS",payload:{products:[],replace:!0}})}},g.li))}(e,t,a),React.createElement(React.Fragment,null,React.createElement(o.Z,{settings:e.productOptions.settings,element:e.productOptions.element,queryType:e.productOptions.queryType,id:e.productOptions.id,isLoading:e.isLoading,payload:e.products,queryParams:e.productQueryParams,initialFetch:!1}),React.createElement(v.Z,{customPaginator:function(){t({type:"SET_SHOULD_REPLACE",payload:!1}),t({type:"SET_IS_FETCHING_NEW",payload:!0})},customHasNextPage:e.productsHasNextPage,customIsLoading:e.isLoading}),r.settings.sorting?(0,E.vI)(React.createElement(d,{settings:r.settings}),e.productOptions.sortingElement):null)}}}]);