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