import{u as r}from"./Note.NSUdvR3c.js";import{_ as c,b as _}from"./main.2.9.0.js";const b=[{label:c("Create Documentation","bit-integrations"),name:"create_documentation",is_pro:!0},{label:c("Create Section","bit-integrations"),name:"create_section",is_pro:!0},{label:c("Create Article","bit-integrations"),name:"create_article",is_pro:!0}],m=[{key:"post_title",label:c("Title","bit-integrations"),required:!0},{key:"post_content",label:c("Content","bit-integrations"),required:!1},{key:"post_status",label:c("Status","bit-integrations"),required:!1}],l=["create_section","create_article"],y=["create_article"],f=["create_section","create_article"],g=["create_article"],A=(t,a,o)=>{const n=r(a,i=>{i[t.target.name]=t.target.value});o(n)},q=()=>{const t=m.filter(a=>a.required===!0);return t.length>0?t.map(a=>({formField:"",weDocsField:a.key})):[{formField:"",weDocsField:""}]},S=t=>{const{mainAction:a,field_map:o=[]}=t||{};if(!a||f.includes(a)&&!(t!=null&&t.selectedDocumentationId)||g.includes(a)&&!(t!=null&&t.selectedSectionId))return!1;const n=m.filter(i=>i.required);return n.length?n.every(i=>o.some(e=>(e==null?void 0:e.weDocsField)===i.key&&(e==null?void 0:e.formField)&&(e.formField!=="custom"||(e==null?void 0:e.customValue)))):!0},k=(t,a,o)=>{a(!0),_({},"wedocs_get_documentations").then(n=>{n!=null&&n.success?t(i=>r(i,e=>{var s;e.documentations=((s=n==null?void 0:n.data)==null?void 0:s.documentations)||[]})):o({show:!0,msg:(n==null?void 0:n.data)||c("Failed to fetch documentations","bit-integrations")})}).catch(()=>{o({show:!0,msg:c("Failed to fetch documentations","bit-integrations")})}).finally(()=>{a(!1)})},w=(t,a,o,n)=>{if(!t){a(i=>r(i,e=>{e.sections=[]}));return}o(!0),_({documentation_id:t},"wedocs_get_sections").then(i=>{i!=null&&i.success?a(e=>r(e,s=>{var h;s.sections=((h=i==null?void 0:i.data)==null?void 0:h.sections)||[]})):n({show:!0,msg:(i==null?void 0:i.data)||c("Failed to fetch sections","bit-integrations")})}).catch(()=>{n({show:!0,msg:c("Failed to fetch sections","bit-integrations")})}).finally(()=>{o(!1)})},z=(t,a,o,n,i)=>{if(!(t!=null&&t.name)){o({name:c("Integration name can't be empty","bit-integrations")});return}o({}),i(!0),_({name:t.name},"wedocs_authorize").then(e=>{e!=null&&e.success?(n(!0),a(s=>r(s,h=>{h.name=t.name}))):o({name:(e==null?void 0:e.data)||c("Authorization failed","bit-integrations")})}).catch(()=>{o({name:c("Authorization failed","bit-integrations")})}).finally(()=>{i(!1)})};export{w as a,f as b,S as c,l as d,g as e,z as f,q as g,A as h,b as m,k as r,y as s,m as w};
