var $=Object.defineProperty,g=Object.defineProperties;var p=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var C=(e,a,t)=>a in e?$(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t,o=(e,a)=>{for(var t in a||(a={}))W.call(a,t)&&C(e,t,a[t]);if(I)for(var t of I(a))R.call(a,t)&&C(e,t,a[t]);return e},d=(e,a)=>g(e,p(a));import{_ as c,z as k,b as _}from"./main.2.9.0.js";const P=(e,a,t)=>{const s=o({},a),{name:n}=e.target;e.target.value!==""?s[n]=e.target.value:delete s[n],t(o({},s))},F=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>!t.formField||!t.zohoSheetFormField||t.formField==="custom"&&!t.customValue):[]).length>0),z=(e,a,t,s)=>{s(d(o({},t),{workbooks:!0}));const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret,dataCenter:e.dataCenter};_(n,"zohoSheet_fetch_all_work_books").then(r=>{if(r&&r.success){const l=o({},e);r.data&&(l.workbooks=r.data),a(l),s(d(o({},t),{workbooks:!1})),k.success(c("Workbooks fetched successfully","bit-integrations"));return}s(d(o({},t),{workbooks:!1})),k.error(c("Workbooks fetching failed","bit-integrations"))})},H=(e,a,t,s)=>{s(d(o({},t),{worksheets:!0}));const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret,dataCenter:e.dataCenter,workbook:e.selectedWorkbook};_(n,"zohoSheet_fetch_all_work_sheets").then(r=>{if(r&&r.success){const l=o({},e);r.data&&(l.worksheets=r.data),a(l),s(d(o({},t),{worksheets:!1})),k.success(c("Worksheets fetched successfully","bit-integrations"));return}s(d(o({},t),{worksheets:!1})),k.error(c("Worksheets fetching failed","bit-integrations"))})},U=(e,a,t,s)=>{s(d(o({},t),{header:!0,workSheetHeaders:!1}));const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret,dataCenter:e.dataCenter,workbook:e.selectedWorkbook,worksheet:e.selectedWorksheet,headerRow:e.headerRow};_(n,"zohoSheet_fetch_all_work_sheet_header").then(r=>{if(r&&r.success){const l=o({},e);r.data&&(l.workSheetHeaders=r.data),a(l),s(d(o({},t),{header:!1,workSheetHeaders:!0})),k.success(c("Worksheet headers fetched successfully","bit-integrations"));return}s(d(o({},t),{header:!1,workSheetHeaders:!1})),k.error(c(`${r.data}`,"bit-integrations"))})},q=e=>{const a={},s=window.location.href.replace(`${window.opener.location.href}/redirect`,"").split("&");s&&s.forEach(n=>{const r=n.split("=");r[1]&&(a[r[0]]=r[1])}),localStorage.setItem(`__${e}`,JSON.stringify(a)),window.close()},E=(e,a,t,s,n,r,l)=>{if(!e.dataCenter||!e.clientId||!e.clientSecret){t({dataCenter:e.dataCenter?"":c("Data center can't be empty"),clientId:e.clientId?"":c("Client ID can't be empty"),clientSecret:e.clientSecret?"":c("Secret key can't be empty")});return}r(d(o({},n),{auth:!0}));const i=`https://accounts.zoho.${e.dataCenter}/oauth/v2/auth?scope=ZohoSheet.dataAPI.READ,ZohoSheet.dataAPI.UPDATE&response_type=code&client_id=${e.clientId}&prompt=Consent&access_type=offline&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${l.api}/redirect`)}`,w=window.open(i,"__zohoSheet","width=400,height=609,toolbar=off"),y=setInterval(()=>{if(w.closed){clearInterval(y);let h={},S=!1;const b=localStorage.getItem("__zohoSheet");if(b&&(S=!0,h=JSON.parse(b),localStorage.removeItem("__zohoSheet")),!h.code||h.error||!h||!S){const f=h.error?`Cause: ${h.error}`:"";k.error(c(`${c("Authorization Failed")} ${f}. ${c("please try again")}`,"bit-integrations")),r(d(o({},n),{auth:!1}))}else{const f=o({},e);h["accounts-server"]=decodeURIComponent(h["accounts-server"]),f.accountServer=h["accounts-server"],A(h,f,a,s,n,r,l)}}},500)},A=(e,a,t,s,n,r,l)=>{const u=o({},e);u.dataCenter=a.dataCenter,u.clientId=a.clientId,u.clientSecret=a.clientSecret,u.redirectURI=`${l.api}/redirect`,_(u,"zohoSheet_generate_token").then(i=>i).then(i=>{if(i&&i.success){const w=o({},a);w.tokenDetails=i.data,t(w),s(!0),k.success(c("Authorized Successfully","bit-integrations")),z(w,t,n,r)}else i&&i.data&&i.data.data||!i.success&&typeof i.data=="string"?k.error(c(`${c("Authorization failed Cause:")}${i.data.data||i.data}. ${c("please try again")}`,"bit-integrations")):k.error(c("Authorization failed. please try again","bit-integrations"));r(d(o({},n),{auth:!1}))})};export{H as a,U as b,F as c,E as d,z as g,P as h,q as s};
