"use strict";(self.webpackChunkshopwp=self.webpackChunkshopwp||[]).push([["AdminSettingProductsMetafields-admin"],{rjjh:function(e,t,n){n.r(t);var a=n("/0+J"),s=n("oYSA"),i=n("o0o1"),p=n.n(i),o=n("qZpH"),l=n("16zp"),r=n("FxId"),c=n("PLDx"),d=n("Ancs"),f=n("bVwy");function u(e){var t=e.metafields,n=e.adminDispatch;return t.map((function(e){return(0,o.tZ)(g,{key:e.id,metafieldNamespace:e.namespace,metafieldKey:e.key,metafieldId:e.id,adminDispatch:n})}))}var m={name:"1m7gtz0-ProductsMetafieldsEmptyCSS",styles:"display:flex;justify-content:center;align-items:center;flex-direction:column;>p{margin-top:0;};label:ProductsMetafieldsEmptyCSS;"};function h(){var e=m;return(0,o.tZ)("div",{css:e},(0,o.tZ)("p",null,"No metafields are currently activated. Click below to start."))}function w(e){var t=e.metafields,n=e.setMetafields,a=wp.components.Button,s=t.length?wp.i18n.__("+ Add metafield","shopwp"):wp.i18n.__("Start activating metafields!","shopwp"),i=t.length?"flex-start":"center";return(0,o.tZ)(c.Z,{align:i},(0,o.tZ)(a,{onClick:function(){var e={id:Date.now().toString(),key:!1,namespace:!1};if(!1===t)var a=[e];else a=t.concat([e]);n(a)},isSecondary:!0,isSmall:!0,text:s}))}var y={name:"jjf35o-MetafieldRowCSS",styles:"display:flex;justify-content:space-between;margin-bottom:22px;position:relative;.components-base-control{width:40.5%;margin-right:8px;}.components-button{position:relative;top:20px;top:25px;height:31px;width:88px;justify-content:center;};label:MetafieldRowCSS;"};function g(e){var t=e.metafieldNamespace,n=e.metafieldKey,i=e.metafieldId,c=e.adminDispatch,d=wp.components,f=d.TextControl,u=d.Button,m=d.Notice,h=React.useState,w=h(n||""),g=(0,s.Z)(w,2),Z=g[0],x=g[1],_=h(t||""),v=(0,s.Z)(_,2),S=v[0],b=v[1],k=h(!!n),C=(0,s.Z)(k,2),M=C[0],N=C[1],E=h(!!i.includes("gid://")),P=(0,s.Z)(E,2),D=P[0],T=P[1],j=h(!1),I=(0,s.Z)(j,2),K=I[0],R=I[1],A=h(!1),O=(0,s.Z)(A,2),B=O[0],H=O[1];function L(){return W.apply(this,arguments)}function W(){return(W=(0,a.Z)(p().mark((function e(){var t,n,a,o,d,f,u;return p().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(R(!0),N(!M),H(!1),D){e.next=16;break}return e.next=6,(0,r.Z)((0,l.EN)({key:Z,namespace:S}));case 6:if(t=e.sent,n=(0,s.Z)(t,2),a=n[0],o=n[1],R(!1),!(0,l.HL)(a,o,c)){e.next=13;break}return e.abrupt("return");case 13:a||(o.success?(c({type:"SET_NOTICE",payload:{type:"success",message:wp.i18n.__("Successfully added metafield to ShopWP","shopwp")}}),T(!0)):(d=getWordPressErrorMessage(o),H(d))),e.next=24;break;case 16:return e.next=18,(0,r.Z)((0,l.Nw)({id:i}));case 18:f=e.sent,u=(0,s.Z)(f,2),a=u[0],o=u[1],R(!1),a?c({type:"SET_NOTICE",payload:{type:"error",message:B}}):(x(""),b(""),c({type:"SET_NOTICE",payload:{type:"success",message:wp.i18n.__("Successfully added metafield to ShopWP","shopwp")}}));case 24:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var z=y;function F(e){"Enter"===e.key&&L()}return(0,o.tZ)(React.Fragment,null,(0,o.tZ)("div",{css:z},(0,o.tZ)(f,{name:wp.i18n.__("Metafield Namespace","shopwp"),type:"text",placeholder:wp.i18n.__("Namespace","shopwp"),onChange:function(e){b(e)},value:S,readOnly:D,disabled:D||K,label:wp.i18n.__("Namespace","shopwp"),onKeyDown:F}),(0,o.tZ)(f,{name:wp.i18n.__("Metafield Key","shopwp"),type:"text",placeholder:wp.i18n.__("Key","shopwp"),onChange:function(e){x(e)},value:Z,readOnly:D,disabled:D||K,label:wp.i18n.__("Key","shopwp"),onKeyDown:F}),(0,o.tZ)(u,{onClick:L,disabled:K,isBusy:K,isPrimary:!0,text:D?wp.i18n.__("Deactivate","shopwp"):wp.i18n.__("Activate","shopwp")})),B&&(0,o.tZ)(m,{status:"error",onRemove:function(){H(!1)}},(0,o.tZ)("div",{dangerouslySetInnerHTML:{__html:B}})))}t.default=function(){var e=React,t=e.useState,n=e.useContext,a=t(shopwp.metafields?shopwp.metafields:[]),i=(0,s.Z)(a,2),p=i[0],l=i[1],r=n(d.Z),c=(0,s.Z)(r,2),m=(c[0],c[1]),y=(0,o.iv)("background-image:",p.length?"none":"linear-gradient(to top, #f4edfe 0%, #ffffff 99%, #e3eeff 100%)",";margin-top:",p.length?"0px":"-25px",";padding:",p.length?"0":"20px 0px",";width:",p.length?"100%":"107%",";margin-left:",p.length?"0":"-3.6%",";;label:ProductsMetafieldsCSS;");return shopwp.misc.isPro?(0,o.tZ)("div",{css:y},0===p.length?(0,o.tZ)(h,null):(0,o.tZ)(u,{metafields:p,adminDispatch:m}),(0,o.tZ)(w,{metafields:p,setMetafields:l})):(0,o.tZ)(f.lx,null)}}}]);