var R=Object.defineProperty;var C=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var g=(s,a,t)=>a in s?R(s,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[a]=t,h=(s,a)=>{for(var t in a||(a={}))w.call(a,t)&&g(s,t,a[t]);if(C)for(var t of C(a))F.call(a,t)&&g(s,t,a[t]);return s};import{u as I,r,j as l}from"./main-406.js";import{d as E,_ as T,I as L,G as O,c as i}from"./bi.394.85.js";import{S as W}from"./bi.68.941.js";import z from"./bi.217.315.js";import{h as A,c as _}from"./bi.662.887.js";import{C as B}from"./bi.577.888.js";import"./bi.150.760.js";function Z({formFields:s,setFlow:a,flow:t,allIntegURL:c}){const m=I(),[x,y]=r.useState(!1),[b,f]=r.useState({}),[o,k]=r.useState(1),[N,p]=r.useState({show:!1}),S=[{key:"name",label:"Name",required:!0},{key:"email_domain",label:"Email",required:!1},{key:"details",label:"Description",required:!1},{key:"street",label:"Street",required:!1},{key:"city",label:"City",required:!1},{key:"state",label:"State",required:!1},{key:"postal_code",label:"Postal Code",required:!1},{key:"country",label:"Country",required:!1},{key:"phone_numbers",label:"Phone",required:!1},{key:"websites",label:"Website",required:!1}],v=[{key:"name",label:"Name",required:!0},{key:"title",label:"Title",required:!1},{key:"details",label:"Description",required:!1},{key:"email_domain",label:"Email",required:!1},{key:"phone_numbers",label:"Phone",required:!1},{key:"street",label:"Street",required:!1},{key:"city",label:"City",required:!1},{key:"state",label:"State",required:!1},{key:"postal_code",label:"Postal Code",required:!1},{key:"country",label:"Country",required:!1},{key:"websites",label:"Website",required:!1}],j=[{key:"name",label:"Opportunity Name",required:!0},{key:"close_date",label:"Close Date",required:!1},{key:"details",label:"Opportunity Details",required:!1},{key:"monetary_value",label:"Value",required:!1}],P=[{key:"name",label:"Task Name",required:!0},{key:"due_date",label:"Due Date",required:!1},{key:"reminder_date",label:"Reminder Date",required:!1},{key:"details",label:"Description",required:!1}],[e,n]=r.useState({name:"CopperCRM",type:"CopperCRM",api_key:"",api_email:"",field_map:[{formField:"",coppercrmFormField:""}],actionName:"",companyFields:S,personFields:v,opportunityFields:j,taskFields:P,actions:{}}),M=()=>{y(!0),O(t,a,c,e,m,"","",y).then(u=>{var q;u.success?(i.success((q=u.data)==null?void 0:q.msg),m(c)):i.error(u.data||u)})},D=d=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!_(e)){i.error("Please map mandatory fields");return}if(e.actionName==="opportunity"){if(!e.selectedCRMPeople){i.error("Please select a people");return}if(!e.selectedCRMPipelines&&e.actionName==="opportunity"){i.error("Please select a Pipeline");return}}e.field_map.length>0&&k(d)};return l.jsxs("div",{children:[l.jsx(E,{snack:N,setSnackbar:p}),l.jsx("div",{className:"txt-center mt-2",children:l.jsx(W,{step:3,active:o})}),l.jsx(z,{coppercrmConf:e,setCopperCRMConf:n,step:o,setStep:k,loading:b,setLoading:f,setSnackbar:p}),l.jsxs("div",{className:"btcd-stp-page",style:h({},o===2&&{width:900,height:"auto",overflow:"visible"}),children:[l.jsx(B,{formFields:s,handleInput:d=>A(d,e,n),coppercrmConf:e,setCopperCRMConf:n,loading:b,setLoading:f,setSnackbar:p}),(e==null?void 0:e.actionName)&&l.jsxs("button",{onClick:()=>D(3),disabled:!_(e),className:"btn f-right btcd-btn-lg purple sh-sm flx",type:"button",children:[T("Next","bit-integrations")," "," ",l.jsx("div",{className:"btcd-icn icn-arrow_back rev-icn d-in-b"})]})]}),(e==null?void 0:e.actionName)&&l.jsx(L,{step:o,saveConfig:()=>M(),isLoading:x,dataConf:e,setDataConf:n,formFields:s})]})}export{Z as default};
