import{G as D,g as b,r as i,f as I,j as t,M as T,S as z,_ as P}from"./main-343.js";import"./bf-649-79.js";import{S as F}from"./bf-149-261.js";import{C}from"./bf-559-89.js";import{ac as L,s as $,a7 as B}from"./bf-659-81.js";import{I as G}from"./bf-58-184.js";import{N as J}from"./bf-713-109.js";import{d as O,Z as j,h as H,c as q}from"./bf-989-101.js";import{Z as K}from"./bf-502-195.js";import"./bf-974-82.js";import"./bf-594-113.js";function oe({formFields:y,setIntegration:k,integrations:N,allIntegURL:u}){const w=D(),{formID:p}=b(),[f,h]=i.useState(!1),[E,g]=i.useState(!1),[a,m]=i.useState(1),[_,n]=i.useState({show:!1}),[x,M]=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)},Z=(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})),m(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&&O(p,e,r,h,n)},[e.parentAppId]),i.useEffect(()=>{window.opener&&$("zohoRecruit")},[]);const v=()=>{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&&m(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:m,isLoading:f,setisLoading:h,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:Z,allowAddNew:!0,addNewAction:()=>g(!0)}),a===1&&S.length===0&&t.jsx(j,{formID:p,recruitConf:e,setRecruitConf:r,step:a,setStep:m,isLoading:f,setisLoading:h,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:M,formID:p,formFields:y,handleInput:d=>H(d,x,e,r,p,h,n),recruitConf:e,setRecruitConf:r,isLoading:f,setisLoading:h,setSnackbar:n}),t.jsx(J,{nextPageHandler:()=>v(),disabled:e.module===""||e.field_map.length<1})]}),t.jsx(G,{step:a,saveConfig:()=>B(N,k,u,e,w)})]})}export{oe as default};
