import{D as v,g as b,r as i,f as I,j as t,M as T,S as z,_ as P}from"./main-634.js";import"./bf-25-81.js";import{S as F}from"./bf-54-258.js";import{C}from"./bf-4-87.js";import{ac as L,s as $,a7 as B}from"./bf-746-82.js";import{I as J}from"./bf-942-184.js";import{N as O}from"./bf-123-109.js";import{d as G,Z as j,h as H,c as q}from"./bf-56-99.js";import{Z as K}from"./bf-518-195.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function ie({formFields:y,setIntegration:k,integrations:N,allIntegURL:u}){const w=v(),{formID:p}=b(),[f,m]=i.useState(!1),[E,g]=i.useState(!1),[a,h]=i.useState(1),[_,n]=i.useState({show:!1}),[x,D]=i.useState(0),[e,r]=i.useState({name:"Zoho Recruit API",type:"Zoho Recruit",clientId:"",clientSecret:"",module:"",field_map:[{formField:"",zohoFormField:""}],relatedlists:[],actions:{}}),S=L([e.type]),A=()=>{setTimeout(()=>{w(`${u}/new/${e.type}`)},1e3),g(!1)},M=(d,c)=>{if(d.integration_type===e.type){const o=JSON.parse(d.integration_details);r(s=>I(s,l=>{l.parentAppId=d.id,l.clientId=o.clientId,l.clientSecret=o.clientSecret,l.tokenDetails=o.tokenDetails,l.dataCenter=o.dataCenter,l.ownerEmail=o.ownerEmail})),h(2)}};i.useEffect(()=>{r(d=>I(d,c=>{const o=S.find(s=>s.id===e.parentAppId);if(o){const s=JSON.parse(o.integration_details);c.clientId=s.clientId,c.clientSecret=s.clientSecret,c.tokenDetails=s.tokenDetails,c.dataCenter=s.dataCenter,c.ownerEmail=s.ownerEmail}})),e!=null&&e.parentAppId&&G(p,e,r,m,n)},[e.parentAppId]),i.useEffect(()=>{window.opener&&$("zohoRecruit")},[]);const Z=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!q(e)){n({show:!0,msg:P("Please map mandatory fields")});return}e.module!==""&&e.field_map.length>0&&h(3)};return t.jsxs("div",{children:[t.jsx(T,{title:"Authorize New Zoho Recruit App",show:E,setModal:()=>g(!1),children:t.jsx(j,{formID:p,recruitConf:e,setRecruitConf:r,step:a,setStep:h,isLoading:f,setisLoading:m,setSnackbar:n,authorizedAction:A})}),t.jsx(z,{snack:_,setSnackbar:n}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(F,{step:3,active:a})}),S.length>0&&a===1&&t.jsx(C,{allIntegURL:u,specificTypes:[e.type],onClickAction:M,allowAddNew:!0,addNewAction:()=>g(!0)}),a===1&&S.length===0&&t.jsx(j,{formID:p,recruitConf:e,setRecruitConf:r,step:a,setStep:h,isLoading:f,setisLoading:m,setSnackbar:n,authorizedAction:A}),t.jsxs("div",{className:"btcd-stp-page",style:{width:a===2&&900,height:a===2&&"100%"},children:[t.jsx(K,{tab:x,settab:D,formID:p,formFields:y,handleInput:d=>H(d,x,e,r,p,m,n),recruitConf:e,setRecruitConf:r,isLoading:f,setisLoading:m,setSnackbar:n}),t.jsx(O,{nextPageHandler:()=>Z(),disabled:e.module===""||e.field_map.length<1})]}),t.jsx(J,{step:a,saveConfig:()=>B(N,k,u,e,w)})]})}export{ie as default};
