var P=Object.defineProperty;var v=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var j=(a,t,s)=>t in a?P(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,C=(a,t)=>{for(var s in t||(t={}))w.call(t,s)&&j(a,s,t[s]);if(v)for(var s of v(t))y.call(t,s)&&j(a,s,t[s]);return a};import{u as M,r,j as n}from"./main-406.js";import{d as F,_ as R,I as E,G as L,c as i}from"./bi.394.85.js";import{S as T}from"./bi.68.941.js";import O from"./bi.987.321.js";import{h as z,c as N}from"./bi.945.899.js";import{S as A}from"./bi.177.900.js";import"./bi.150.760.js";function V({formFields:a,setFlow:t,flow:s,allIntegURL:u}){const f=M(),[g,m]=r.useState(!1),[S,h]=r.useState({}),[o,x]=r.useState(1),[I,p]=r.useState({show:!1}),[e,c]=r.useState({name:"Salesmate",type:"Salesmate",session_token:"",link_name:"",field_map:[{formField:"",salesmateFormField:""}],actionName:"",actionId:"",salesmateFields:[],actions:{}}),_=()=>{m(!0),L(s,t,u,e,f,"","",m).then(d=>{var b;d.success?(i.success((b=d.data)==null?void 0:b.msg),f(u)):i.error(d.data||d)})},k=l=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!N(e)){i.error("Please map mandatory fields");return}if(!e.selectedCRMOwner){i.error("Please select a Owner");return}if(Number(e.actionId)===4){if(!e.selectedCRMContact){i.error("Please select a Contact");return}if(!e.selectedCRMPipeline){i.error("Please select a Pipeline");return}if(!e.selectedCRMStage){i.error("Please select a Stage");return}}e.field_map.length>0&&x(l)};return n.jsxs("div",{children:[n.jsx(F,{snack:I,setSnackbar:p}),n.jsx("div",{className:"txt-center mt-2",children:n.jsx(T,{step:3,active:o})}),n.jsx(O,{salesmateConf:e,setSalesmateConf:c,step:o,setStep:x,loading:S,setLoading:h,setSnackbar:p}),n.jsxs("div",{className:"btcd-stp-page",style:C({},o===2&&{width:900,height:"auto",overflow:"visible"}),children:[n.jsx(A,{formFields:a,handleInput:l=>z(l,e,c),salesmateConf:e,setSalesmateConf:c,loading:S,setLoading:h,isLoading:g,setIsLoading:m,setSnackbar:p}),(e==null?void 0:e.actionName)&&n.jsxs("button",{onClick:()=>k(3),disabled:!N(e),className:"btn f-right btcd-btn-lg purple sh-sm flx",type:"button",children:[R("Next","bit-integrations")," "," ",n.jsx("div",{className:"btcd-icn icn-arrow_back rev-icn d-in-b"})]})]}),(e==null?void 0:e.actionName)&&n.jsx(E,{step:o,saveConfig:()=>_(),isLoading:g,dataConf:e,setDataConf:c,formFields:a})]})}export{V as default};
