var S=Object.defineProperty,v=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var k=(e,s,t)=>s in e?S(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,l=(e,s)=>{for(var t in s||(s={}))g.call(s,t)&&k(e,t,s[t]);if(F)for(var t of F(s))A.call(s,t)&&k(e,t,s[t]);return e},m=(e,s)=>v(e,z(s));var y=(e,s,t)=>new Promise((o,n)=>{var i=a=>{try{r(t.next(a))}catch(p){n(p)}},c=a=>{try{r(t.throw(a))}catch(p){n(p)}},r=a=>a.done?o(a.value):Promise.resolve(a.value).then(i,c);r((t=t.apply(e,s)).next())});import{z as f,_ as d,b as I}from"./main.2.8.10.js";import{g as R,s as q}from"./Integrations.BFhED4ck.js";const U=(e,s,t,o,n)=>{const i=l({},s),c=l({},o),{name:r,value:a}=e.target;c[r]="",i[r]=a,n(c),t(i)},x=(e,s,t,o,n,i,c,r)=>{if(!e.clientId||!e.clientSecret){o({clientId:e.clientId?"":d("Client Id can't be empty"),clientSecret:e.clientSecret?"":d("Client Secret can't be empty")});return}o({}),c(m(l({},i),{auth:!0}));const a=`https://api.notion.com/v1/oauth/authorize?client_id=${e.clientId}&response_type=code&owner=user&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${r.api}`)}/redirect`,p=window.open(a,"Notion","width=400,height=609,toolbar=off"),_=setInterval(()=>{if(p.closed){clearInterval(_);let u={},b=!1;const h=localStorage.getItem("__notion");if(h&&(b=!0,u=JSON.parse(h),localStorage.removeItem("__notion")),!u.code||u.error||!u||!b){const $=u.error?`Cause: ${u.error}`:"";f.error(`${d("Authorization failed","bit-integrations")} ${$}. ${d("please try again","bit-integrations")}`),c(m(l({},i),{auth:!1}))}else C(u,e,s,n,i,c,r)}},500)},C=(e,s,t,o,n,i,c)=>{const r=l({},e);r.clientId=s.clientId,r.clientSecret=s.clientSecret,r.redirectURI=`${c.api}/redirect`,I(r,"notion_authorization").then(a=>{if(a&&a.success){const p=l({},s);p.tokenDetails=a.data,t(p),o(!0),f.success(d("Authorized Successfully"))}else a&&a.data&&a.data.data||!a.success&&typeof a.data=="string"?f.error(`${d("Authorization failed Cause:")}${a.data.data||a.data}. ${d("please try again")}`):f.error(d("Authorization failed. please try again"));i(m(l({},n),{auth:!1}))})},N=(e,s,t,o)=>y(null,null,function*(){o&&o(m(l({},t),{list:!0}));const n={accessToken:e.tokenDetails.access_token},i=yield I(n,"notion_database_lists");if(i.success&&i.data.results){const c=i==null?void 0:i.data.results.filter(a=>a.object==="database").map(a=>({id:a.id,name:a.title[0].text.content})),r=l({},e);return c&&(r.default||(r.default={}),r.default.databaseLists=c,s(r),o&&(o(m(l({},t),{list:!1})),f.success(d("List refresh successfully")))),!0}return o&&(o(m(l({},t),{list:!1})),f.success(d("List refresh failed"))),!1}),E=(e,s,t,o)=>y(null,null,function*(){o&&o(m(l({},t),{field:!0}));const n={accessToken:e.tokenDetails.access_token,databaseId:e.databaseId},i=yield I(n,"notion_database_properties");if(i.success&&i.data.properties){const c=i==null?void 0:i.data.properties,r=[],a=["formula","people","Rollup","Relation","created_by","created_time","last_edited_by","last_edited_time"];for(const _ in c){const u={},h=c[_].type;a.includes(h)||(u.label=_,u.key=h,h=="title"?u.required=!0:u.required=!1,r.push(u))}const p=l({},e);return c&&(p.notionFields=r,s(l({},p)),o&&(o(m(l({},t),{field:!1})),f.success(d("field refresh successfully")))),r}return o&&(o(m(l({},t),{field:!1})),f.success(d("field refresh failed"))),!1}),M=e=>{const s=e==null?void 0:e.notionFields.filter(t=>t.required===!0);return s.length>0?s.map(t=>({formFields:"",notionFormFields:t.label})):[{formFields:"",notionFormFields:""}]},w=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>!t.formFields||!t.notionFormFields||!t.formFields==="custom"&&!t.customValue):[]).length>0),V=(e,s,t)=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!w(e)){f.error(d("Please map mandatory fields","bit-integrations"));return}e.field_map.length>0&&s(t)},j=(e,s,t,o,n,i)=>{i(!0),R(e,s,t,o,n,"","",i).then(r=>{var a;r.success?(f.success((a=r.data)==null?void 0:a.msg),n(t)):f.error(r.data||r)})},B=(e,s,t,o,n,i)=>{if(!w(t)){f.error(d("Please map mandatory fields","bit-integrations"));return}q({flow:e,allIntegURL:s,conf:t,navigate:o,edit:n,setIsLoading:i})};export{N as a,E as b,x as c,j as d,M as g,U as h,V as n,B as s};
