var $=Object.defineProperty;var N=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var S=(i,s,a)=>s in i?$(i,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[s]=a,j=(i,s)=>{for(var a in s||(s={}))B.call(s,a)&&S(i,a,s[a]);if(N)for(var a of N(s))J.call(s,a)&&S(i,a,s[a]);return i};import{D as U,g as H,u as V,r as p,a as W,f as M,j as t,M as Z,S as K,W as Q,h as R,_ as X,$ as Y}from"./main-634.js";import{m as ee}from"./bf-25-81.js";import{S as te}from"./bf-54-258.js";import{C as se}from"./bf-4-87.js";import{ac as I,a7 as ae}from"./bf-746-82.js";import{I as ie}from"./bf-942-184.js";import q from"./bf-402-124.js";import{a as oe,c as re,b as ne}from"./bf-935-178.js";import{G as le}from"./bf-252-223.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-824-186.js";import"./bf-438-114.js";function xe({formFields:i,setIntegration:s,integrations:a,allIntegURL:h}){var x;const b=U(),{formID:_}=H(),v=V(Y),[m,y]=p.useState(!1),[o,u]=p.useState(1),[C,l]=p.useState({show:!1}),[F,k]=p.useState(!1),{css:T}=W(),P=[{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}],G=[{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}],D=[{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:P,contactMetaFields:G,allActions:D,address_field:[],actions:{}}),E=()=>{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!==""&&u(3)},L=!(e.mainAction==="2"&&e.addTagToUser!==""),z=()=>{ae(a,s,h,e,b)},A=I([e.type]),w=()=>{setTimeout(()=>{b(`${h}/new/${e.type}`)},1e3),k(!1)},O=(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})),u(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(Z,{title:"Authorize New Groundhogg App",show:F,setModal:()=>k(!1),children:t.jsx(q,{formID:_,groundhoggConf:e,setGroundhoggConf:d,step:o,setStep:u,isLoading:m,setIsLoading:y,setSnackbar:l,authorizedAction:w})}),t.jsx(K,{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:O,allowAddNew:!0,addNewAction:()=>k(!0)}),o===1&&A.length===0&&t.jsx(q,{formID:_,groundhoggConf:e,setGroundhoggConf:d,step:o,setStep:u,isLoading:m,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:m,setIsLoading:y,setSnackbar:l}),t.jsxs(Q,{variant:"success",onClick:()=>E(),disabled:(e.mainAction==="2"?L:!(((x=e.field_map)==null?void 0:x.length)>=1))||m,className:T(R.mt3,{ml:3}),children:[X("Next")," ",t.jsx(ee,{className:"ml-1 rev-icn"})]})]}),t.jsx(ie,{step:o,saveConfig:()=>z()})]})}export{xe as default};
