import{_ as m,b as r,z as b}from"./main.2.8.10.js";import{u as s}from"./Note.DalStCGz.js";const z=(e,a,t,u,c,i,d,l,_)=>{const o=e.target.name,n=e.target.value;switch(t(w=>s(w,p=>{if(n===""){delete p.moduleData[o];return}o!=="module"?p.moduleData[o]=parseInt(n):(p.moduleData={},p.moduleData[o]=n)})),o){case"module":D(n,a,t,c,i);break;case"contact_view_id":k(n,a,t,c,i);break;case"account_view_id":F(n,a,t,c,i);break}},D=(e,a,t,u,c)=>{t(i=>s(i,d=>{d.actions={},d.field_map=[{formField:"",freshSalesFormField:""}],["Contact"].includes(e)&&g(a,t,u,c),["Deal"].includes(e)&&v(a,t,u,c),e&&y(e,a,t,u,c)}))},F=(e,a,t,u,c)=>{var d;const i=a.moduleData.module;["Deal","Contact"].includes(i)&&A(e,a,t,u,c),["Deal","Contact"].includes(i)&&!((d=a.default.modules[i])!=null&&d.fields)&&y(i,a,t,u,c)},k=(e,a,t,u,c)=>{var d;const i=a.moduleData.module;["Deal"].includes(i)&&q(e,a,t,u,c),["Deal"].includes(i)&&!((d=a.default.modules[i])!=null&&d.fields)&&y(i,a,t,u,c)},y=(e,a,t,u,c)=>{const i={api_key:a.api_key,bundle_alias:a.bundle_alias,module:e};u(!0),r(i,"FreshSales_refresh_fields").then(d=>{if(u(!1),!d||!d.success){c({show:!1,msg:m("Fields refresh failed. please try again","bit-integrations")});return}t(l=>s(l,_=>{_.default.modules[e].fields||(_.default.modules[e].fields=[]),_.default.modules[e].fields=(d==null?void 0:d.data)||[],_.field_map=h(_),c({show:!0,msg:m("Fields refreshed","bit-integrations")})}))})},g=(e,a,t,u)=>{const c={api_key:e.api_key,bundle_alias:e.bundle_alias,module:"filters",type:"sales_accounts"};t(!0),r(c,"FreshSales_fetch_meta_data").then(i=>{if(t(!1),!i||!i.success){u({show:!1,msg:m("Account views refresh failed. please try again","bit-integrations")});return}a(d=>s(d,l=>{l.default.accountViews=i.data||[]}))}).catch(()=>t(!1))},v=(e,a,t,u)=>{const c={api_key:e.api_key,bundle_alias:e.bundle_alias,module:"filters",type:"contacts"};t(!0),r(c,"FreshSales_fetch_meta_data").then(i=>{if(t(!1),!i||!i.success){u({show:!1,msg:m("Contact views refresh failed. please try again","bit-integrations")});return}a(d=>s(d,l=>{l.default.contactViews=i.data||[]}))}).catch(()=>t(!1))},A=(e,a,t,u,c)=>{const i={api_key:a.api_key,bundle_alias:a.bundle_alias,account_view_id:e,contact_view_id:a.moduleData.contact_view_id,module:"sales_accounts"};u(!0),r(i,"FreshSales_fetch_meta_data").then(d=>{if(u(!1),!d||!d.success){c({show:!1,msg:m("Accounts refresh failed. please try again","bit-integrations")});return}t(l=>s(l,_=>{_.default.accounts=d.data||[]}))}).catch(()=>u(!1))},q=(e,a,t,u,c)=>{const i={api_key:a.api_key,bundle_alias:a.bundle_alias,contact_view_id:e,account_view_id:a.moduleData.account_view_id,module:"contacts"};u(!0),r(i,"FreshSales_fetch_meta_data").then(d=>{if(u(!1),!d||!d.success){c({show:!1,msg:m("Contacts refresh failed. please try again","bit-integrations")});return}t(l=>s(l,_=>{_.default.contacts=d.data||[]}))}).catch(()=>u(!1))},h=e=>{var u,c,i,d;const a=e.moduleData.module,t=(d=(i=(c=(u=e==null?void 0:e.default)==null?void 0:u.modules)==null?void 0:c[a])==null?void 0:i.fields)==null?void 0:d.filter(l=>l.required===!0);return(t==null?void 0:t.length)>0?t.map(l=>({formField:"",freshSalesFormField:l.key})):[{formField:"",freshSalesFormField:""}]},R=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>{var u,c,i,d;return!t.formField&&t.freshSalesFormField&&((d=(i=(c=(u=e==null?void 0:e.default)==null?void 0:u.modules)==null?void 0:c[e.moduleData.module])==null?void 0:i.requiredFields)==null?void 0:d.indexOf(t.freshSalesFormField))!==-1}):[]).length>0),N=e=>{var a,t,u,c,i;return!(((a=e.moduleData)==null?void 0:a.module)!==""&&((c=(u=e.default.modules)==null?void 0:u[(t=e==null?void 0:e.moduleData)==null?void 0:t.module])!=null&&c.required)&&(["Leads","Deal","Activities","Notes"].includes(e.moduleData.module)&&e.moduleData.account_id===void 0&&((i=e.moduleData)==null?void 0:i.contact_id)===void 0||e.moduleData.module==="Contacts"&&e.moduleData.account_id===void 0))},x=(e,a,t,u)=>{if(!e.bundle_alias||!e.api_key){a({bundle_alias:e.bundle_alias?"":m("Bundle Alias (Account URL) can't be empty","bit-integrations"),api_key:e.api_key?"":m("API Key can't be empty","bit-integrations")});return}a({}),u(!0);const c={api_key:e.api_key,bundle_alias:e.bundle_alias,module:"filters"};r(c,"FreshSales_authorization").then(i=>{if(i&&i.success){t(!0),u(!1),b.success(m("Authorized Successfully","bit-integrations"));return}u(!1),b.error(m("Authorized failed","bit-integrations"))})};export{N as a,g as b,R as c,v as d,q as e,x as f,z as h,A as r};
