(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,n=window.wp.element,a=window.wp.apiFetch;var s=e.n(a);const l=window.wp.i18n,c=window.wp.components;function i(){const[e,a]=(0,n.useState)(generateCloud.license),[i,o]=(0,n.useState)(""),[r,d]=(0,n.useState)(!1);async function u(t){var n;d(!0);const c=document.querySelector(".generatecloud-licensing__license-message");c.style.display="none";const i=await s()({path:"/generatecloud/v1/save-license-key",method:"POST",data:{license:{key:t}}});let o="";i.success?o="valid"===i?.response?.license?(0,l.__)("License key activated.","generatecloud"):"deactivated"===i?.response?.license?(0,l.__)("License key deactivated.","generatecloud"):i.response:(c.style.color="red",o=i?.response),o&&(c.style.display="block",c.textContent=o),a({...e,key:t,status:null!==(n=i.response?.license)&&void 0!==n?n:"invalid"}),d(!1),setTimeout((()=>{c.style.display="none"}),3e3)}return(0,t.createElement)("div",{className:"generateblocks-settings-main"},(0,t.createElement)(c.PanelBody,{title:(0,l.__)("GenerateCloud License Key","generatecloud")},(0,t.createElement)("div",{className:"gblocks-dashboard-panel-row-wrapper"},(0,t.createElement)("div",{className:"generatecloud-licensing"},(0,t.createElement)(c.Notice,{className:"gblocks-licensing-notice",isDismissible:!1,status:"valid"===e.status?"success":"warning"},"valid"===e.status?(0,t.createElement)("span",null,(0,l.__)("Receiving updates","generatecloud")):(0,t.createElement)("span",null,(0,l.__)("Not receiving updates","generatecloud"))),e?.key?(0,t.createElement)("div",{className:"generatecloud-licensing__license-key"},(0,t.createElement)(c.TextControl,{disabled:!0,value:e?.key}),(0,t.createElement)(c.Button,{variant:"secondary",size:"compact",isBusy:r,onClick:()=>{u("")}},(0,l.__)("Clear","generatecloud"))):(0,t.createElement)("div",{className:"generatecloud-licensing__license-key"},(0,t.createElement)(c.TextControl,{value:i,onChange:o}),(0,t.createElement)(c.Button,{variant:"primary",size:"compact",isBusy:r,disabled:!i,onClick:()=>{i&&u(i)}},(0,l.__)("Save","generatecloud"))),(0,t.createElement)("div",{className:"generatecloud-licensing__license-message",style:{display:"none"}})))))}window.addEventListener("DOMContentLoaded",(()=>{var e,a;e=(0,t.createElement)(i,null),a=document.getElementById("generatecloud-licensing"),void 0!==n.createRoot?(0,n.createRoot)(a).render(e):(0,n.render)(e,a)}))})();