"use strict";(self.webpackChunkshopwp=self.webpackChunkshopwp||[]).push([["AdminSettingExternalApiKey-admin"],{"l2+p":function(e,t,n){n.r(t);var p=n("/0+J"),a=n("oYSA"),r=n("o0o1"),s=n.n(r),i=n("qZpH"),o=n("16zp"),c=n("Ancs"),l=n("FxId");function u(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1?arguments[1]:void 0;return e||(e=t),e?e.substring(e.length-30):""}var h={name:"1z927q-FormFieldsWrapperCSS",styles:"display:flex;flex-direction:column;flex:1;.shopwp-help{margin-top:16px!important;}.components-base-control+.components-base-control{margin-top:20px;}.components-button{width:100px;};label:FormFieldsWrapperCSS;"},y={name:"3pm7kj-ErrorCSS",styles:".components-notice{width:100%;margin-top:0;}.components-button{top:0px;};label:ErrorCSS;"};t.default=function(e){var t=e.activator,n=e.deactivator,r=e.defaultApiKey,d=e.defaultApiSecretKey,w=e.serviceName,m=e.serviceLink,_=e.hasCustomFields,f=void 0!==_&&_,v=wp.components,x=v.TextControl,b=v.Button,g=v.Notice,Z=React,S=Z.useState,k=(0,Z.useContext)(c.Z),C=(0,a.Z)(k,2)[1],A=S(!1),E=(0,a.Z)(A,2),K=E[0],I=E[1],T=S(r),F=(0,a.Z)(T,2),P=F[0],N=F[1],O=S(d),R=(0,a.Z)(O,2),q=R[0],j=R[1],z=S((function(){return!!r})),B=(0,a.Z)(z,2),M=B[0],D=B[1],H=S(!1),L=(0,a.Z)(H,2),W=L[0],G=L[1];function J(){return Y.apply(this,arguments)}function Y(){return Y=(0,p.Z)(s().mark((function e(){var n,p,r,i,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return I(!1),G(!0),C({type:"SET_NOTICE",message:!1}),n=f?{apiKey:P,apiSecretKey:q}:{apiKey:P},e.next=6,(0,l.Z)(t(n));case 6:if(p=e.sent,r=(0,a.Z)(p,2),i=r[0],c=r[1],G(!1),!i){e.next=14;break}return I(i.message),e.abrupt("return");case 14:if(!(0,o.nq)(c)){e.next=17;break}return I((0,o.OM)(c)),e.abrupt("return");case 17:D(!0),f?(N(c.data.api_key),j(c.data.api_secret_key)):N(u(c.data,P)),C({type:"SET_NOTICE",payload:{type:"success",message:wp.i18n.__("Successfully activated "+w+" API key","shopwp")}});case 20:case"end":return e.stop()}}),e)}))),Y.apply(this,arguments)}function Q(){return U.apply(this,arguments)}function U(){return U=(0,p.Z)(s().mark((function e(){var t,p,r,i,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return I(!1),G(!0),C({type:"SET_NOTICE",message:!1}),t=f?{apiKey:P,apiSecretKey:q}:{apiKey:P},e.next=6,(0,l.Z)(n(t));case 6:if(p=e.sent,r=(0,a.Z)(p,2),i=r[0],c=r[1],G(!1),!i){e.next=15;break}return I(i.message),G(!1),e.abrupt("return");case 15:if(!(0,o.nq)(c)){e.next=18;break}return I((0,o.OM)(c)),e.abrupt("return");case 18:D(!1),N(""),j(""),C({type:"SET_NOTICE",payload:{type:"success",message:wp.i18n.__("Successfully deactivated "+w+" API key","shopwp")}});case 22:case"end":return e.stop()}}),e)}))),U.apply(this,arguments)}var V=(0,i.iv)("display:flex;justify-content:space-between;margin-bottom:22px;position:relative;.components-base-control{flex:1;margin-right:8px;}.components-button{position:relative;top:20px;top:25px;height:31px;justify-content:center;}.shopwp-help{margin-top:",f?"14px":"-15px","!important;font-size:12px;color:rgb(117, 117, 117);};label:RowCSS;"),X=y,$=h,ee=f?"them":"it";return(0,i.tZ)(React.Fragment,null,(0,i.tZ)("div",{css:V},f?(0,i.tZ)("div",{css:$},(0,i.tZ)("div",{css:$},(0,i.tZ)(x,{type:"text",value:P,onChange:N,disabled:W||M,placeholder:wp.i18n.__("Enter your "+w+" api key here","shopwp"),label:wp.i18n.__(w+" API Key","shopwp")}),(0,i.tZ)(x,{type:"text",value:q,onChange:j,disabled:W||M,placeholder:wp.i18n.__("Enter your "+w+" api secret key here","shopwp"),label:wp.i18n.__(w+" API Secret Key","shopwp")})),(0,i.tZ)(b,{onClick:M?Q:J,disabled:W,isBusy:W,isPrimary:!0,text:M?wp.i18n.__("Deactivate","shopwp"):wp.i18n.__("Activate","shopwp")})):(0,i.tZ)(React.Fragment,null,(0,i.tZ)(x,{type:"text",value:P,onChange:N,disabled:W||M,placeholder:wp.i18n.__("Enter your "+w+" api key here","shopwp"),label:wp.i18n.__(w+" API Key","shopwp")}),(0,i.tZ)(b,{onClick:M?Q:J,disabled:W,isBusy:W,isPrimary:!0,text:M?wp.i18n.__("Deactivate","shopwp"):wp.i18n.__("Activate","shopwp")}))),(0,i.tZ)("div",{css:V},(0,i.tZ)("p",{className:"shopwp-help"},"Get started by"," ",(0,i.tZ)("a",{href:m,target:"_blank"},wp.i18n.__("generating a "+w+" API key","shopwp"))," ",wp.i18n.__("and adding "+ee+" here.","shopwp"))),K&&(0,i.tZ)("div",{css:[V,X,";label:ExternalApiKey;"]},(0,i.tZ)(g,{status:"error",onRemove:function(){I(!1)}},(0,i.tZ)("div",{dangerouslySetInnerHTML:{__html:K}}))))}}}]);