import{G as b,g as z,r as d,f as I,j as s,M as P,_ as x,S as v}from"./main-343.js";import"./bf-649-79.js";import{S as F}from"./bf-149-261.js";import{C as T}from"./bf-559-89.js";import{ac as C,s as L,a7 as O}from"./bf-659-81.js";import{I as $}from"./bf-58-184.js";import{N as G}from"./bf-713-109.js";import{b as j,Z as k,h as J,c as B}from"./bf-566-97.js";import{Z as H}from"./bf-160-191.js";import"./bf-974-82.js";import"./bf-594-113.js";function se({formFields:y,setIntegration:N,integrations:_,allIntegURL:f}){const S=b(),{formID:l}=z(),[u,p]=d.useState(!1),[E,g]=d.useState(!1),[o,m]=d.useState(1),[Z,a]=d.useState({show:!1}),[e,r]=d.useState({name:"Zoho Desk API",type:"Zoho Desk",clientId:"",clientSecret:"",orgId:"",department:"",field_map:[{formField:"",zohoFormField:""}],actions:{}}),w=C([e.type]),A=()=>{setTimeout(()=>{S(`${f}/new/${e.type}`)},1e3),g(!1)},D=(t,i)=>{if(t.integration_type===e.type){const c=JSON.parse(t.integration_details);r(n=>I(n,h=>{h.parentAppId=t.id,h.clientId=c.clientId,h.clientSecret=c.clientSecret,h.tokenDetails=c.tokenDetails,h.dataCenter=c.dataCenter,h.ownerEmail=c.ownerEmail})),m(2)}};d.useEffect(()=>{r(t=>I(t,i=>{const c=w.find(n=>n.id===e.parentAppId);if(c){const n=JSON.parse(c.integration_details);i.clientId=n.clientId,i.clientSecret=n.clientSecret,i.tokenDetails=n.tokenDetails,i.dataCenter=n.dataCenter,i.ownerEmail=n.ownerEmail}})),e!=null&&e.parentAppId&&j(l,e,r,p,a)},[e.parentAppId]),d.useEffect(()=>{window.opener&&L("zohoDesk")},[]);const M=t=>{var i;if(t===3){if(!B(e)){a({show:!0,msg:x("Please map mandatory fields")});return}if(!((i=e.actions)!=null&&i.ticket_owner)){a({show:!0,msg:x("Please select a ticket owner")});return}e.department!==""&&e.table!==""&&e.field_map.length>0&&m(t)}else m(t),t===2&&!e.department&&j(l,e,r,p,a)};return s.jsxs("div",{children:[s.jsx(P,{title:x("Authorize New Zoho Desk App"),show:E,setModal:()=>g(!1),children:s.jsx(k,{formID:l,deskConf:e,setDeskConf:r,step:o,setstep:m,isLoading:u,setisLoading:p,setSnackbar:a,authorizedAction:A})}),s.jsx(v,{snack:Z,setSnackbar:a}),s.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:s.jsx(F,{step:3,active:o})}),w.length>0&&o===1&&s.jsx(T,{allIntegURL:f,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>g(!0)}),o===1&&w.length===0&&s.jsx(k,{formID:l,deskConf:e,setDeskConf:r,step:o,setstep:m,isLoading:u,setisLoading:p,setSnackbar:a,authorizedAction:A}),s.jsxs("div",{className:"btcd-stp-page",style:{width:o===2&&900,height:o===2&&"100%"},children:[s.jsx(H,{formID:l,formFields:y,handleInput:t=>J(t,e,r,l,p,a),deskConf:e,setDeskConf:r,isLoading:u,setisLoading:p,setSnackbar:a}),s.jsx(G,{nextPageHandler:()=>M(3),disabled:e.department===""||e.table===""||e.field_map.length<1})]}),s.jsx($,{step:o,saveConfig:()=>O(_,N,f,e,S)})]})}export{se as default};
