import{D as M,g as T,r as c,f as g,j as t,M as z,S as P}from"./main-634.js";import"./bf-25-81.js";import{S as b}from"./bf-54-258.js";import{C}from"./bf-4-87.js";import{ac as L,a7 as _}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{N as J}from"./bf-123-109.js";import{r as j,s as O,Z as I}from"./bf-961-101.js";import{Z as B}from"./bf-836-197.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-723-105.js";function ee({formFields:k,setIntegration:y,integrations:N,allIntegURL:f}){const w=M(),{formID:l}=T(),[u,h]=c.useState(!1),[D,x]=c.useState(!1),[i,m]=c.useState(1),[E,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)},Z=(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&&O("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:D,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:E,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:Z,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(B,{formID:l,formFields:k,signConf:e,setSignConf:r,isLoading:u,setisLoading:h,setSnackbar:p}),t.jsx(J,{nextPageHandler:()=>v(3),disabled:e.template===""})]}),t.jsx($,{step:i,saveConfig:()=>_(N,y,f,e,w)})]})}export{ee as default};
