var O=Object.defineProperty;var N=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var S=(i,s,a)=>s in i?O(i,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[s]=a,j=(i,s)=>{for(var a in s||(s={}))$.call(s,a)&&S(i,a,s[a]);if(N)for(var a of N(s))U.call(s,a)&&S(i,a,s[a]);return i};import{G as J,g as H,u as V,r as p,a as Z,f as M,j as t,M as K,S as Q,U as R,h as W,_ as X,$ as Y}from"./main-343.js";import{B as ee}from"./bf-649-79.js";import{S as te}from"./bf-149-261.js";import{C as se}from"./bf-559-89.js";import{ac as I,a7 as ae}from"./bf-659-81.js";import{I as ie}from"./bf-58-184.js";import q from"./bf-692-123.js";import{a as oe,c as re,b as ne}from"./bf-695-178.js";import{G as le}from"./bf-713-223.js";import"./bf-974-82.js";import"./bf-541-186.js";import"./bf-594-113.js";function we({formFields:i,setIntegration:s,integrations:a,allIntegURL:h}){var x;const b=J(),{formID:_}=H(),v=V(Y),[u,y]=p.useState(!1),[o,m]=p.useState(1),[C,l]=p.useState({show:!1}),[F,k]=p.useState(!1),{css:T}=Z(),G=[{key:"email",label:"Email",required:!0},{key:"first_name",label:"First Name",required:!1},{key:"last_name",label:"Last Name",required:!1},{key:"user_id",label:"User Id",required:!1},{key:"owner_id",label:"Owner Id",required:!1},{key:"optin_status",label:"Optin Status",required:!1}],P=[{key:"primary_phone",label:"Primary Phone",required:!1},{key:"street_address_1",label:"Street Address 1",required:!1},{key:"street_address_2",label:"Street Address 2",required:!1},{key:"postal_zip",label:"Postal Zip",required:!1},{key:"city",label:"City",required:!1},{key:"country",label:"Country",required:!1}],E=[{key:"1",label:"Create Contact"},{key:"2",label:"Add tag to user"}],[e,d]=p.useState({name:"Groundhogg",type:"Groundhogg",token:"",public_key:"",id:"",mainAction:"",addTagToUser:"",emailAddress:"",domainName:v.siteURL,showMeta:!1,field_map:[{formField:"",GroundhoggMapField:""}],field_map_meta:[{formField:"",GroundhoggMetaMapField:""}],contactsFields:G,contactMetaFields:P,allActions:E,address_field:[],actions:{}}),L=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),e.mainAction==="1"&&!re(e)){l({show:!0,msg:"Please map fields to continue."});return}if(e.showMeta&&!ne(e)){l({show:!0,msg:"Please map fields to continue."});return}e.listId!==""&&m(3)},z=!(e.mainAction==="2"&&e.addTagToUser!==""),B=()=>{ae(a,s,h,e,b)},A=I([e.type]),w=()=>{setTimeout(()=>{b(`${h}/new/${e.type}`)},1e3),k(!1)},D=(r,f)=>{if(r.integration_type===e.type){const c=JSON.parse(r.integration_details);d(n=>M(n,g=>{g.parentAppId=r.id,g.public_key=c.public_key,g.token=c.token,g.domainName=c.domainName})),m(2)}};return p.useEffect(()=>{d(r=>M(r,f=>{const c=I([e.type]).find(n=>n.id===e.parentAppId);if(c){const n=JSON.parse(c.integration_details);f.public_key=n.public_key,f.token=n.token,f.domainName=n.domainName}}))},[e.parentAppId]),t.jsxs("div",{children:[t.jsx(K,{title:"Authorize New Groundhogg App",show:F,setModal:()=>k(!1),children:t.jsx(q,{formID:_,groundhoggConf:e,setGroundhoggConf:d,step:o,setStep:m,isLoading:u,setIsLoading:y,setSnackbar:l,authorizedAction:w})}),t.jsx(Q,{snack:C,setSnackbar:l}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(te,{step:3,active:o})}),A.length>0&&o===1&&t.jsx(se,{allIntegURL:h,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>k(!0)}),o===1&&A.length===0&&t.jsx(q,{formID:_,groundhoggConf:e,setGroundhoggConf:d,step:o,setStep:m,isLoading:u,setIsLoading:y,setSnackbar:l,authorizedAction:w}),t.jsxs("div",{className:"btcd-stp-page",style:j({},o===2&&{width:900,height:"auto",overflow:"visible"}),children:[t.jsx(le,{formFields:i,handleInput:r=>oe(r,e,d),groundhoggConf:e,setGroundhoggConf:d,isLoading:u,setIsLoading:y,setSnackbar:l}),t.jsxs(R,{variant:"success",onClick:()=>L(),disabled:(e.mainAction==="2"?z:!(((x=e.field_map)==null?void 0:x.length)>=1))||u,className:T(W.mt3,{ml:3}),children:[X("Next")," ",t.jsx(ee,{className:"ml-1 rev-icn"})]})]}),t.jsx(ie,{step:o,saveConfig:()=>B()})]})}export{we as default};
