import{D as v,g as M,r as c,f as A,j as t,M as T,_ as I,S as z}from"./main-634.js";import"./bf-25-81.js";import{S as O}from"./bf-54-258.js";import{C as P}from"./bf-4-87.js";import{ac as b,s as F,a7 as C}from"./bf-746-82.js";import{I as L}from"./bf-942-184.js";import{N as $}from"./bf-123-109.js";import{r as B,Z as j,h as J,c as G}from"./bf-493-93.js";import{Z as H}from"./bf-858-189.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-297-103.js";import"./bf-824-186.js";import"./bf-438-114.js";function oe({formFields:y,setIntegration:k,integrations:N,allIntegURL:u}){const x=v(),{formID:l}=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)},D=(r,d)=>{if(r.integration_type===e.type){const i=JSON.parse(r.integration_details);n(s=>A(s,p=>{p.parentAppId=r.id,p.clientId=i.clientId,p.clientSecret=i.clientSecret,p.tokenDetails=i.tokenDetails,p.dataCenter=i.dataCenter,p.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(l,e,n,h,o)},[e.parentAppId]),c.useEffect(()=>{window.opener&&F("zohoCreator")},[]);const Z=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!G(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:l,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:D,allowAddNew:!0,addNewAction:()=>g(!0)}),a===1&&w.length===0&&t.jsx(j,{formID:l,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:l,formFields:y,handleInput:r=>J(r,e,n,l,h,o),creatorConf:e,setCreatorConf:n,isLoading:f,setisLoading:h,setSnackbar:o}),t.jsx($,{nextPageHandler:()=>Z(),disabled:e.accountOwner===""||e.field_map.length<1})]}),t.jsx(L,{step:a,saveConfig:()=>C(N,k,u,e,x)})]})}export{oe as default};
