"use strict";(self.webpackChunkshopwp=self.webpackChunkshopwp||[]).push([["AdminSettingSyncingByCollections-admin"],{DlMW:function(n,t,e){e.r(t),e.d(t,{default:function(){return w}});var i=e("/0+J"),o=e("oYSA"),s=e("o0o1"),a=e.n(s),r=e("qZpH"),l=e("ALIA"),c=e("k4Da"),u=e.n(c),p=e("Ancs"),f=e("Qjib"),y=e("X6Ea"),d=e("OFL0"),C=e.n(d),h=e("Z0cm"),m=e.n(h),b=e("DTvD"),_=e("FxId"),S=e("16zp"),Z={name:"1sgh0nt-styles",styles:"margin:60px 0!important;display:flex;.components-spinner{margin-top:0;};label:styles;"},w=function(){var n,t=React,e=t.useContext,s=t.useState,c=t.useEffect,d=wp.components,h=d.Spinner,w=d.Notice,L=d.Button,v=(()=>{const n=(0,b.useRef)(!1);return(0,b.useEffect)((()=>(n.current=!0,()=>n.current=!1)),[]),n})(),E=e(l.Z),g=(0,o.Z)(E,2),k=g[0],T=g[1],A=e(p.Z),I=(0,o.Z)(A,2),O=I[0],D=I[1],x=s(k.syncByCollections?k.syncByCollections.map((function(n){return n.id})):[]),N=(0,o.Z)(x,2),B=N[0],G=N[1],P=s(!1),q=(0,o.Z)(P,2),F=q[0],M=q[1],R=Z;function U(n){return n&&m()(n)?n.map((function(n){return{id:n.id,title:n.title,handle:n.handle,smart:!!C()(n,"rules")}})):[]}return c((function(){function n(){return(n=(0,i.Z)(a().mark((function n(){var t,e,i,s;return a().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return D({type:"SET_IS_LOADING_COLLECTIONS",payload:!0}),n.next=3,(0,_.Z)((0,S.Lg)());case 3:if(t=n.sent,e=(0,o.Z)(t,2),i=e[0],s=e[1],D({type:"SET_IS_LOADING_COLLECTIONS",payload:!1}),v.current){n.next=10;break}return n.abrupt("return");case 10:if(!(0,S.nq)(s)){n.next=13;break}return M((0,S.OM)(s)),n.abrupt("return");case 13:if(!i){n.next=16;break}return M(i),n.abrupt("return");case 16:C()(s,"data")&&(s=s.data),D({type:"SET_AVAILABLE_COLLECTIONS",payload:U(s)}),(s?s.filter((function(n){return B.includes(n.id)})):[]).length||(G([]),T({type:"UPDATE_SETTING",payload:{key:"syncByCollections",value:[]}}));case 20:case"end":return n.stop()}}),n)})))).apply(this,arguments)}!function(){n.apply(this,arguments)}()}),[]),O.hasConnection?O.availableCollections?(0,r.tZ)(f.P,{label:wp.i18n.__("Only sync from these collections:","shopwp"),settingsKey:"syncByCollections",options:(n=O.availableCollections,n?n.map((function(n){return{label:n.title,value:n.id}})):[]),customValue:B,customOnChange:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];G(n),T({type:"UPDATE_SETTING",payload:{key:"syncByCollections",value:u()(O.availableCollections,(function(t){if(n)return n.includes(t.id.toString())}))}})},multiple:!0}):F?(0,r.tZ)(w,{status:"error",isDismissible:!1},F):(0,r.tZ)("div",{css:R},wp.i18n.__("Loading Collections ... ","shopwp")," ",(0,r.tZ)(h,null)):(0,r.tZ)(w,{status:"warning",isDismissible:!1},wp.i18n.__("No Shopify connection found! Please connect your store from ","shopwp"),(0,r.tZ)(L,{isLink:!0,onClick:function(n){(0,y.md)("connect")}},wp.i18n.__("inside the Connect tab.","shopwp")))}}}]);