"use strict";(self.webpackChunkautonami=self.webpackChunkautonami||[]).push([[9610],{39610(t,e,n){n.r(e),n.d(e,{default:()=>h});var a=n(86087),o=n(54016),r=n(67408),i=n(27723),s=n(1455),l=n.n(s),u=n(66087),c=n(83583),f=n(47111),m=n(87361),d=n(71050);function b(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var a,o,r,i,s=[],l=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;l=!1}else for(;!(l=(a=r.call(n)).done)&&(s.push(a.value),s.length!==e);l=!0);}catch(t){u=!0,o=t}finally{try{if(!l&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw o}}return s}}(t,e)||function(t,e){if(t){if("string"==typeof t)return g(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?g(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,a=Array(e);n<e;n++)a[n]=t[n];return a}const h=function(t){var e=t.match.params,n=e.tab,s=void 0===n?"general":n,g=e.subTab,h=void 0===g?"":g;(0,o.A)("general",!1,""),(0,c.Ls)((0,i.__)("Settings","wp-marketing-automations"));var v=(0,a.useContext)(c.Xj),_=(0,a.useContext)(d.J).setHasUnsavedChanges,w=bwfanParams,y=w.bwfan_global_settings_schema,p=void 0===y?{}:y,A=w.bwfan_global_settings,S=void 0===A?{}:A,k=b((0,a.useState)(p),2),C=k[0],x=k[1],E=b((0,a.useState)(S),2),T=E[0],j=E[1],O=b((0,a.useState)({}),2),P=O[0],Y=O[1],I=[];C.forEach(function(t){Array.isArray(t.tabs)&&t.tabs.forEach(function(t){(0,u.isNull)(t)||Array.isArray(t.fields)&&t.fields.forEach(function(t){t.required&&I.push({id:t.id,label:t.label})})})});var q=function(t,e,n){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return new Promise(function(o,r){var s=S.bwfan_sandbox_mode,u=void 0!==s&&s,f=t.bwfan_sandbox_mode,m=void 0!==f&&f;if(m!==u&&!a)return e(!1),void Y({title:m?(0,i.__)("Enable Sandbox Mode?","wp-marketing-automations"):(0,i.__)("Disable Sandbox mode?","wp-marketing-automations"),content:m?(0,i.__)("You are about to enable sandbox mode. All active automation and ongoing broadcasts will be halted.","wp-marketing-automations"):(0,i.__)("You are about to disable sandbox mode. All active automation and ongoing broadcasts will start running again.","wp-marketing-automations"),status:!0,onConfirm:function(){e(!0),Y({}),q(t,e,n,!0).then(function(){o()})},onCancel:function(){e(!1),r()}});try{l()({path:(0,c.er)("/settings"),method:"POST",data:{bwfan_global_settings:t}}).then(function(t){if(200===t.code){v(t.message);var e=t.result;e&&(window.bwfanParams.bwfan_global_settings=n,window.bwfanParams.bwfan_global_settings_schema=e.schema,j(e.values),x(e.schema),_(!1))}else v(t.message);o()}).catch(function(t){console.log(t),v(t.message),r()}).finally(function(){e(!1),(0,c.fY)(v,3e3)})}catch(t){console.log(t),v(t.message),(0,c.fY)(v,3e3),e(!1)}})},D=function(t){var e={};return I.forEach(function(n){(0,u.isEmpty)(t[n.id])&&(e[n.id]=n.label+(0,i.__)(" field is required !","wp-marketing-automations"))}),e};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(m.A,null),C.map(function(t){return(0,a.createElement)(r.A,{key:"setting-tab--"+t.key,fields:t.tabs,values:T,onSubmit:q,validate:D,setSettingFieldSchema:x,activeTab:s,activeSubTab:h})}),(0,a.createElement)(f.A,{modalTitle:P.title,deleteDescriptionText:P.content,confirmButtonText:(0,i.__)("Yes, I confirm","wp-marketing-automations"),onConfirm:P.onConfirm,onCancel:P.onCancel,isLoading:!1,onRequestClose:function(){return Y({status:!1})},isOpen:P.status,isDelete:!0}))}}}]);