var M=Object.defineProperty;var q=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var A=(r,a,t)=>a in r?M(r,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[a]=t,S=(r,a)=>{for(var t in a||(a={}))T.call(a,t)&&A(r,t,a[t]);if(q)for(var t of q(a))z.call(a,t)&&A(r,t,a[t]);return r};import{D as C,r as n,f as j,j as s,M as L,_ as D,S as P,V as B}from"./main-634.js";import"./bf-25-81.js";import{S as J}from"./bf-54-258.js";import{C as O}from"./bf-4-87.js";import{ac as V,a7 as $}from"./bf-746-82.js";import{I as G}from"./bf-942-184.js";import{N as H}from"./bf-123-109.js";import E from"./bf-990-118.js";import{b as Z,a as K,c as Q}from"./bf-184-172.js";import{R as W}from"./bf-323-204.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function ce({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=V([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&&Z(e,d,c)},[e.parentAppId]);const R=()=>{$(t,a,m,e,g)},F=i=>{if(!Q(e)){B.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:D("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(P,{snack:N,setSnackbar:u}),s.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:s.jsx(J,{step:3,active:l})}),h.length>0&&l===1&&s.jsx(O,{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=>K(i,e,d),rapidmailConf:e,setRapidmailConf:d,isLoading:x,setIsLoading:c,setSnackbar:u}),s.jsx(H,{nextPageHandler:()=>F(3),disabled:!(e!=null&&e.recipient_id)})]}),s.jsx(G,{step:l,saveConfig:()=>R()})]})}export{ce as default};
