var f=Object.defineProperty,g=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var h=(e,a,t)=>a in e?f(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t,d=(e,a)=>{for(var t in a||(a={}))A.call(a,t)&&h(e,t,a[t]);if(p)for(var t of p(a))N.call(a,t)&&h(e,t,a[t]);return e},n=(e,a)=>g(e,b(a));import{_ as l,b as F,z as u}from"./main.2.9.0.js";import{u as _}from"./Note.NSUdvR3c.js";const M=(e,a,t)=>{const s=d({},a),{name:i}=e.target;e.target.value!==""?s[i]=e.target.value:delete s[i],t(d({},s))},y=e=>(Array.isArray(e==null?void 0:e.field_map)?e.field_map:[]).filter(s=>(s==null?void 0:s.formField)&&s.formField!==""||(s==null?void 0:s.fabmanFormField)&&s.fabmanFormField!==""?!s.formField||!s.fabmanFormField||s.formField==="custom"&&!s.customValue:!1).length===0,W=(e,a,t,s,i,o)=>{if(!e.apiKey){t({apiKey:e.apiKey?"":l("API key can't be empty","bit-integrations")});return}t({}),o(n(d({},i),{auth:!0}));const r={apiKey:e.apiKey};F(r,"fabman_authorization").then(c=>{if(c&&c.success){const m=_(e,w=>{c.data&&c.data.accountId&&(w.accountId=c.data.accountId)});s(!0),a(m),o(n(d({},i),{auth:!1})),u.success(l("Authorized Successfully","bit-integrations"));return}s(!1),o(n(d({},i),{auth:!1})),u.error(l("Authorization Failed","bit-integrations"))}).catch(c=>{console.error(c),o(n(d({},i),{auth:!1})),u.error(l("Authorization Failed","bit-integrations"))})},z=(e,a,t,s,i="fetch")=>{if(!e.apiKey){u.error(l("API key can't be empty","bit-integrations"));return}s(n(d({},t),{workspaces:!0}));const o={apiKey:e.apiKey};F(o,"fabman_fetch_workspaces").then(r=>{if(s(n(d({},t),{workspaces:!1})),r&&r.success){const c=_(e,m=>{r.data&&r.data.workspaces&&Array.isArray(r.data.workspaces)&&(m.workspaces=r.data.workspaces,r.data.workspaces.length===1&&(m.selectedWorkspace=r.data.workspaces[0].id))});a(c),u.success(i==="refresh"?l("Workspaces refreshed successfully","bit-integrations"):l("Workspaces fetched successfully","bit-integrations"));return}u.error(l("Failed to fetch workspaces","bit-integrations"))}).catch(r=>{console.error(r),s(n(d({},t),{workspaces:!1})),u.error(l("Failed to fetch workspaces","bit-integrations"))})},P=e=>{var a;return(a=e.field_map)==null?void 0:a.some(t=>t.fabmanFormField==="emailAddress"&&t.formField)},K=e=>(Array.isArray(e==null?void 0:e.field_map)?e.field_map:[]).find(t=>(t==null?void 0:t.fabmanFormField)==="emailAddress"),k=(e,a,t)=>{const s=K(e);if(!s)return!0;if(s.formField==="custom"){const c=(s.customValue||"").trim();return!c||!t(c)}const i=(a||[]).find(c=>c.name===s.formField);if(!i)return!1;const o=i.type&&String(i.type).toLowerCase()==="email",r=/email/i.test(i.name||"")||/email/i.test(i.label||"");return!o&&i.type&&!r},S=(e,a,t)=>{var s;return!!(!e||!e.actionName||!["delete_member","delete_spaces"].includes(e.actionName)&&!y(e)||["update_member","delete_member"].includes(e.actionName)&&k(e,a,t)||["create_member","update_member","update_spaces","delete_spaces"].includes(e.actionName)&&!e.selectedWorkspace||e.actionName==="delete_member"&&!((s=e.field_map)==null?void 0:s.some(o=>o.fabmanFormField==="emailAddress"&&o.formField)))},V=(e,a,t)=>e.actionName?!["delete_member","delete_spaces"].includes(e.actionName)&&!y(e)?l("Please map mandatory fields","bit-integrations"):["update_member","delete_member"].includes(e.actionName)&&k(e,a,t)?l("Please map a valid email address","bit-integrations"):["create_member","update_member","update_spaces","delete_spaces"].includes(e.actionName)&&!e.selectedWorkspace?l("Please select a workspace","bit-integrations"):e.actionName==="delete_member"&&!P(e)?l("Please map email field for member lookup","bit-integrations"):null:l("Please select an action","bit-integrations");export{W as a,k as b,y as c,P as d,z as f,V as g,M as h,S as i};
