var F=Object.defineProperty;var q=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var A=(r,a,t)=>a in r?F(r,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[a]=t,S=(r,a)=>{for(var t in a||(a={}))M.call(a,t)&&A(r,t,a[t]);if(q)for(var t of q(a))T.call(a,t)&&A(r,t,a[t]);return r};import{G as C,r as n,f as j,j as s,M as L,_ as P,S as B,z as D}from"./main-343.js";import"./bf-649-79.js";import{S as G}from"./bf-149-261.js";import{C as J}from"./bf-559-89.js";import{ac as O,a7 as $}from"./bf-659-81.js";import{I as H}from"./bf-58-184.js";import{N as Z}from"./bf-713-109.js";import E from"./bf-751-117.js";import{b as K,a as Q,c as V}from"./bf-746-172.js";import{R as W}from"./bf-336-204.js";import"./bf-974-82.js";import"./bf-594-113.js";function pe({formFields:r,setIntegration:a,integrations:t,allIntegURL:m}){const g=C(),[x,c]=n.useState(!1),[v,y]=n.useState(!1),[l,f]=n.useState(1),[N,u]=n.useState({show:!1}),I=[{key:"email",label:"Email",required:!0},{key:"firstname",label:"First name",required:!1},{key:"lastname",label:"Last name",required:!1},{key:"gender",label:"Gender",required:!1},{key:"title",label:"Title",required:!1},{key:"zip",label:"Zip",required:!1},{key:"birthdate",label:"Birthdate",required:!1},{key:"extra1",label:"Extra field 1",required:!1},{key:"extra2",label:"Extra field 2",required:!1},{key:"extra3",label:"Extra field 3",required:!1},{key:"extra4",label:"Extra field 4",required:!1},{key:"extra5",label:"Extra field 5",required:!1},{key:"extra6",label:"Extra field 6",required:!1},{key:"extra7",label:"Extra field 7",required:!1},{key:"extra8",label:"Extra field 8",required:!1},{key:"extra9",label:"Extra field 9",required:!1},{key:"extra10",label:"Extra field 10",required:!1}],[e,d]=n.useState({name:"Rapidmail",type:"Rapidmail",username:"",password:"",field_map:[{formField:"",rapidmailFormField:""}],recipientsFields:I,actions:{}}),h=O([e.type]),w=()=>{setTimeout(()=>{g(`${m}/new/${e.type}`)},1e3),y(!1)},_=(i,b)=>{if(i.integration_type===e.type){const p=JSON.parse(i.integration_details);d(o=>j(o,k=>{k.parentAppId=i.id,k.username=p.username,k.password=p.password})),f(2)}};n.useEffect(()=>{d(i=>j(i,b=>{const p=h.find(o=>o.id===e.parentAppId);if(p){const o=JSON.parse(p.integration_details);b.username=o.username,b.password=o.password}})),e!=null&&e.parentAppId&&K(e,d,c)},[e.parentAppId]);const R=()=>{$(t,a,m,e,g)},z=i=>{if(!V(e)){D.error("Please map mandatory fields");return}e.field_map.length>0&&f(i)};return document.querySelector(".btcd-s-wrp").scrollTop=0,s.jsxs("div",{children:[s.jsx(L,{title:P("Authorize New Rapidmail Account"),show:v,setModal:()=>y(!1),children:s.jsx(E,{rapidmailConf:e,setRapidmailConf:d,step:l,setstep:f,isLoading:x,setIsLoading:c,setSnackbar:u,authorizedAction:w})}),s.jsx(B,{snack:N,setSnackbar:u}),s.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:s.jsx(G,{step:3,active:l})}),h.length>0&&l===1&&s.jsx(J,{allIntegURL:m,specificTypes:[e.type],onClickAction:_,allowAddNew:!0,addNewAction:()=>y(!0)}),l===1&&h.length===0&&s.jsx(E,{rapidmailConf:e,setRapidmailConf:d,step:l,setstep:f,isLoading:x,setIsLoading:c,setSnackbar:u,authorizedAction:w}),s.jsxs("div",{className:"btcd-stp-page",style:S({},l===2&&{width:900,height:"auto",overflow:"visible"}),children:[s.jsx(W,{formFields:r,handleInput:i=>Q(i,e,d),rapidmailConf:e,setRapidmailConf:d,isLoading:x,setIsLoading:c,setSnackbar:u}),s.jsx(Z,{nextPageHandler:()=>z(3),disabled:!(e!=null&&e.recipient_id)})]}),s.jsx(H,{step:l,saveConfig:()=>R()})]})}export{pe as default};
