"use strict";(self.webpackJSONPwpmdb=self.webpackJSONPwpmdb||[]).push([[513],{76513:function(e,t,c){c.r(t),c.d(t,{default:function(){return A}});var n=c(88368),a=c(4665),i=c(7354),s=c(62295),r=c(42233),l=c(19085),o=c(27325),u=c(66055),_=(c(19826),c(59299)),m=c(68424),d=c(29942),v=c(87326),p=c(27114),f=c(4516),g=e=>e.dbi_api_data;function b(e,t){return(0,f.fX)(g,"settings",e,t)}var k=c(31998);function x(e){return async t=>await t((0,d.wM)({preRequest:(0,s.dC)((()=>{t((0,v.c9)("licence_action",!0)),t((0,v.rT)("licence"))})),asyncFn:e,requestFailed:e=>{var c,n;t((c=e,n="licence_action",e=>(e((0,v.nE)("licence",(0,r.__)("API error: ")+(0,p.Y)(c))),e((0,v.c9)(n,!1)),!1)))},requestSuccess:e=>{t((0,v.c9)("licence_action",!1))}}))}function E(e,t){return c=>{var a=e.data,i=a.errors;if(i){if(c((0,v.c9)(t,!1)),Object.keys(i).length>0){var s=Object.keys(i),r=(0,n.Z)(s,1)[0];a.hasOwnProperty("licence_status")&&(r=a.licence_status),c(y(r))}c((0,u.m)(_.eD,i))}else c(y("active_licence"))}}function h(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:x,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"ui";return async(n,a)=>{var i=(0,o.u)("licence",a()),r=b("api_time",a()),l=Date.now()-r,v=b("license_check_context",a());if(t||!(l<36e5)||c!==v){var p=await n(e((0,d.op)("/check-license",{licence:i,context:"all",message_context:c},!1,n)));if(!p)return null;var f=p.data;return n(E(p,"check_licence")),(0,s.dC)((()=>{n((0,u.m)(_._K,p.data)),n((0,u.m)(_.I,Date.now())),n((0,u.m)(_.aJ,c)),n((e=>{(0,d.op)("/local-site-details").then((t=>{t.success&&e((0,u.m)(k.dN,t.data))}))})),t&&n((0,m.Ax)())})),f}}}function w(e,t){if(!t)return null;var c=t.data,n=c.errors,a=c.error_type;return e(E(t,"licence_action")),"undefined"!==typeof t.data.dbrains_api_down?(e((0,u.m)(_.zB,!0)),e((0,m.Ax)()),e(h())):e((0,u.m)(_.zB,!1)),!(n&&!Object.keys(n).includes("subscription_expired"))&&(1===Number(t.data.is_first_activation)&&"subscription_expired"!==a&&e((0,u.m)(_.x_,"first_activation")),"subscription_expired"!==a&&e((0,u.m)(_.qi,!0)),t.success&&t.data&&(0,s.dC)((async()=>{"subscription_expired"!==a&&e(y("active_licence")),e((0,m.Ax)()),e((0,v.m7)("masked_licence",t.data.masked_licence)),e((0,u.m)(_._K,t.data)),"subscription_expired"!==a&&e((0,u.m)(_.eD,[])),e(h())})),setTimeout((()=>{e((0,u.m)(_.qi,!1))}),2500),t)}function y(e){return async t=>t((0,u.m)(_.Ih,e))}var N=(0,s.$j)((e=>({settingsStatus:(0,o.u)("status",e)})),{checkLicenceAgain:function(e,t){return async(c,n)=>{c((0,v.c9)("check_again",!0));var a=x;e&&!t&&(a=()=>{return t=e,async e=>{var c=await e(x((0,d.op)("/activate-license",{licence_key:t,context:"all",message_context:"settings"},!1,e)));return w(e,c)};var t});var i=await c(h(a,!0));return c((0,v.c9)("check_again","success")),i}}})((e=>{var t,c,n=!1,i=e.settingsStatus,s=e.settings;return s&&(t=s.licence,c=s.masked_licence),i.check_again&&(n=!0===i.check_again),a.createElement(a.Fragment,null,a.createElement("div",{className:"flex-container licence-action"},a.createElement("a",{onClick:()=>{e.checkLicenceAgain(t,c)}},(0,r.__)("Check my license again","wp-migrate-db")),a.createElement("div",{className:"relative"},n&&a.createElement(l.Q,{className:"license-notification-spinner"}))))})),S=c(46415),C=e=>{var t=e.settings,c=t.status,n=t.errors,i=c.disable_ssl;return a.createElement(a.Fragment,null,a.createElement("div",{className:"flex-container licence-action"},a.createElement("button",{className:"btn-tooltip-stroke",onClick:()=>e.disableSSL()},(0,r.gB)((0,r.__)("Temporarily disable SSL for connections to %s","wp-migrate-db"),"api.deliciousbrains.com")),a.createElement(S.OP,{position:!1,condition:i,errorMsg:n.disable_ssl,spinnerCond:i&&!0===i})))},O=(0,s.$j)((e=>({settingsStatus:(0,o.u)("status",e)})),{reactivateLicense:function(){return async e=>{e((0,v.c9)("reactivate_license",!0));var t=await e(x((0,d.op)("/reactivate-license",{context:"all",message_context:"settings"},!1,e))),c=w(e,t);return e((0,v.c9)("reactivate_license","success")),e(h(x,!0)),c}}})((e=>{var t=!1,c=e.settingsStatus,n=e.className,i=e.btnText;return c.reactivate_license&&(t=!0===c.reactivate_license),a.createElement(a.Fragment,null,a.createElement("div",{className:"flex-container licence-action"},a.createElement("a",{onClick:()=>{e.reactivateLicense()},className:n||""},i||(0,r.__)("Reactivate license","wp-migrate-db")),a.createElement("div",{className:"relative"},t&&a.createElement(l.Q,{className:"license-notification-spinner"}))))})),A=e=>{var t=(0,s.v9)((e=>e.dbi_api_data.licence)),c=t.license_ui_status,r=t.licence_status,l=(0,a.useState)(null),o=(0,n.Z)(l,2),u=o[0],_=o[1],m=["subscription_expired","licence_not_found","no_activations_left"];return(0,a.useEffect)((()=>{(0,i.includes)(m,r)?_(a.createElement(N,e)):"activation_deactivated"===r&&_(a.createElement(O,e))}),[]),u||(""===c?null:"check_again"===c?a.createElement(N,e):"connection_failed"===c?a.createElement(C,e):null)}}}]);