import{D as b,g as z,r as d,f as I,j as s,M as P,_ as x,S as v}from"./main-634.js";import"./bf-25-81.js";import{S as F}from"./bf-54-258.js";import{C as T}from"./bf-4-87.js";import{ac as C,s as L,a7 as O}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{N as J}from"./bf-123-109.js";import{b as j,Z as k,h as B,c as G}from"./bf-705-95.js";import{Z as H}from"./bf-861-191.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function ae({formFields:y,setIntegration:N,integrations:_,allIntegURL:f}){const S=b(),{formID:p}=z(),[u,l]=d.useState(!1),[D,g]=d.useState(!1),[o,m]=d.useState(1),[E,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)},Z=(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(p,e,r,l,a)},[e.parentAppId]),d.useEffect(()=>{window.opener&&L("zohoDesk")},[]);const M=t=>{var i;if(t===3){if(!G(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(p,e,r,l,a)};return s.jsxs("div",{children:[s.jsx(P,{title:x("Authorize New Zoho Desk App"),show:D,setModal:()=>g(!1),children:s.jsx(k,{formID:p,deskConf:e,setDeskConf:r,step:o,setstep:m,isLoading:u,setisLoading:l,setSnackbar:a,authorizedAction:A})}),s.jsx(v,{snack:E,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:Z,allowAddNew:!0,addNewAction:()=>g(!0)}),o===1&&w.length===0&&s.jsx(k,{formID:p,deskConf:e,setDeskConf:r,step:o,setstep:m,isLoading:u,setisLoading:l,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:p,formFields:y,handleInput:t=>B(t,e,r,p,l,a),deskConf:e,setDeskConf:r,isLoading:u,setisLoading:l,setSnackbar:a}),s.jsx(J,{nextPageHandler:()=>M(3),disabled:e.department===""||e.table===""||e.field_map.length<1})]}),s.jsx($,{step:o,saveConfig:()=>O(_,N,f,e,S)})]})}export{ae as default};
