import{da as u}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,n){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,n),n)}};const d="https://api.notion.com/v1/",h=async t=>u({bodyParams:{query:""},headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}],"Content-Type":"application/json","Notion-Version":"2021-08-16"},method:"POST",url:`${d}search`}),p=async t=>u({bodyParams:{query:""},headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}],"Content-Type":"application/json","Notion-Version":"2021-08-16"},method:"POST",url:`${d}search`}),f=async(t,n)=>u({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}],"Content-Type":"application/json","Notion-Version":"2021-08-16"},method:"GET",url:`${d}databases/${n}`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,n){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,n),n)}};function g(t){for(const n in t){const o=t[n];if(o.type==="title"&&o.title&&o.title.length>0)return o.title[0].text.content}return"Untitled"}const C=async t=>{t.setComponent("page-id",e=>{e.loading=!0});const n=await t.getConnection();if(!n)return;const{data:o,status:i}=await p(n.auth_details.access_token);if(i!=="success"){t.setComponent("page-id",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status=i,e.invalidMessage=o)}),console.error("Failed to fetch list");return}t.setComponent("page-id",e=>{var s;t.util.isSelectComponent(e)&&(e.options=(s=o==null?void 0:o.results)==null?void 0:s.filter(a=>(a==null?void 0:a.object)==="page").map(a=>({label:g(a.properties),value:a.id})),e.loading=!1)})},y=async t=>{t.setComponent("database-id",e=>{e.loading=!0});const n=await t.getConnection();if(!n)return;const{data:o,status:i}=await h(n.auth_details.access_token);if(i!=="success"){t.setComponent("database-id",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status=i,e.invalidMessage=o)}),console.error("Failed to fetch list");return}t.setComponent("database-id",e=>{var s;t.util.isSelectComponent(e)&&(e.options=(s=o==null?void 0:o.results)==null?void 0:s.filter(a=>(a==null?void 0:a.object)==="database").map(a=>{var l,r;let c=(r=(l=a==null?void 0:a.title[0])==null?void 0:l.text)==null?void 0:r.content;return c||(c=a.id),{label:c,value:a.id}}),e.loading=!1)})},b=async t=>{var e;t.setComponent("field-properties",s=>{s.loading=!0});const n=await t.getConnection();if(!n)return;const{data:o,status:i}=await f(n.auth_details.access_token,(e=t.getComponent("database-id"))==null?void 0:e.value);if(i!=="success"){t.setComponent("field-properties",s=>{t.util.isSelectComponent(s)&&(s.loading=!1,s.status=i,s.invalidMessage=o)}),console.error("Failed to fetch list");return}t.setComponent("field-properties",s=>{if(!t.util.isRepeaterFieldComponent(s))return;const a=s.fieldsMetaData[0],c=[];for(const l in o==null?void 0:o.properties){const r=o==null?void 0:o.properties[l];c.push({label:r.name,value:`${r.name},${r.type}`})}a.options=c,s.loading=!1})};export{y as a,b,C as f};
