import{G as M,g as T,r as c,f as g,j as t,M as z,S as P}from"./main-343.js";import"./bf-649-79.js";import{S as b}from"./bf-149-261.js";import{C}from"./bf-559-89.js";import{ac as L,a7 as _}from"./bf-659-81.js";import{I as $}from"./bf-58-184.js";import{N as G}from"./bf-713-109.js";import{r as j,s as J,Z as I}from"./bf-476-103.js";import{Z as O}from"./bf-987-197.js";import"./bf-974-82.js";import"./bf-188-107.js";function U({formFields:k,setIntegration:y,integrations:N,allIntegURL:f}){const w=M(),{formID:l}=T(),[u,h]=c.useState(!1),[E,x]=c.useState(!1),[i,m]=c.useState(1),[Z,p]=c.useState({show:!1}),[e,r]=c.useState({name:"Zoho Sign API",type:"Zoho Sign",clientId:"",clientSecret:"",template:"",actions:{}}),S=L([e.type]),A=()=>{setTimeout(()=>{w(`${f}/new/${e.type}`)},1e3),x(!1)},D=(o,s)=>{if(o.integration_type===e.type){const n=JSON.parse(o.integration_details);r(a=>g(a,d=>{d.parentAppId=o.id,d.clientId=n.clientId,d.clientSecret=n.clientSecret,d.tokenDetails=n.tokenDetails,d.dataCenter=n.dataCenter,d.ownerEmail=n.ownerEmail})),m(2)}};c.useEffect(()=>{r(o=>g(o,s=>{const n=S.find(a=>a.id===e.parentAppId);if(n){const a=JSON.parse(n.integration_details);s.clientId=a.clientId,s.clientSecret=a.clientSecret,s.tokenDetails=a.tokenDetails,s.dataCenter=a.dataCenter,s.ownerEmail=a.ownerEmail}})),e.parentAppId&&j(l,e,r,h,p)},[e.parentAppId]),c.useEffect(()=>{window.opener&&J("zohoSign")},[]);const v=o=>{var s;o===2&&((s=e==null?void 0:e.default)!=null&&s.templates||j(l,e,r,h,p)),m(o)};return t.jsxs("div",{children:[t.jsx(z,{title:"Authorize New Zoho Sign App",show:E,setModal:()=>x(!1),children:t.jsx(I,{formID:l,signConf:e,setSignConf:r,step:i,setStep:m,isLoading:u,setisLoading:h,setSnackbar:p,authorizedAction:A})}),t.jsx(P,{snack:Z,setSnackbar:p}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(b,{step:3,active:i})}),S.length>0&&i===1&&t.jsx(C,{allIntegURL:f,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>x(!0)}),i===1&&S.length===0&&t.jsx(I,{formID:l,signConf:e,setSignConf:r,step:i,setStep:m,isLoading:u,setisLoading:h,setSnackbar:p,authorizedAction:A}),t.jsxs("div",{className:"btcd-stp-page",style:{width:i===2&&900,height:i===2&&"100%"},children:[t.jsx(O,{formID:l,formFields:k,signConf:e,setSignConf:r,isLoading:u,setisLoading:h,setSnackbar:p}),t.jsx(G,{nextPageHandler:()=>v(3),disabled:e.template===""})]}),t.jsx($,{step:i,saveConfig:()=>_(N,y,f,e,w)})]})}export{U as default};
