var p=Object.defineProperty,b=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var h=(e,i,s)=>i in e?p(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s,c=(e,i)=>{for(var s in i||(i={}))f.call(i,s)&&h(e,s,i[s]);if(_)for(var s of _(i))y.call(i,s)&&h(e,s,i[s]);return e},u=(e,i)=>b(e,k(i));import{_ as m,b as d,c as n,B as F}from"./bi.394.85.js";const g=(e,i,s)=>{const r=c({},i),{name:l}=e.target;e.target.value!==""?r[l]=e.target.value:delete r[l],s(c({},r))},q=(e,i,s,r)=>{s(!0);const l={api_token:e.api_token,domain:e.domain,action_name:e.actionName};d(l,"perfexcrm_custom_fields").then(a=>{a&&a.success?(i(o=>F(o,t=>(t.perfexCRMFields="",t.field_map=[{formField:"",perfexCRMFormField:""}],a.data&&(t.actionName==="customer"?t.perfexCRMFields=t.customerFields:t.actionName==="contact"?t.perfexCRMFields=t.contactFields:t.actionName==="lead"?t.perfexCRMFields=t.leadFields:t.actionName==="project"&&(t.perfexCRMFields=t.projectFields),t.perfexCRMFields=[...t.perfexCRMFields,...a.data],t.field_map=A(t)),t))),r({show:!0,msg:m("Custom fields refreshed","bit-integrations")})):r({show:!0,msg:m("Custom fields refresh failed. please try again","bit-integrations")}),s(!1)}).catch(()=>s(!1))},A=e=>{const i=(e==null?void 0:e.perfexCRMFields)&&(e==null?void 0:e.perfexCRMFields.filter(s=>s.required===!0&&s.key!=="owner"&&s.key!=="pipeline"));return i.length>0?i.map(s=>({formField:"",perfexCRMFormField:s.key})):[{formField:"",perfexCRMFormField:""}]},x=e=>!((e!=null&&e.field_map?e.field_map.filter(s=>!s.formField||!s.perfexCRMFormField||s.formField==="custom"&&!s.customValue||s.perfexCRMFormField==="customFieldKey"&&!s.customFieldKey):[]).length>0),j=(e,i,s,r,l,a)=>{if(!e.api_token||!e.domain){s({api_token:e.api_token?"":m("Api Token can't be empty","bit-integrations"),domain:e.domain?"":m("Access API URL can't be empty","bit-integrations")});return}s({}),a(u(c({},l),{auth:!0}));const o={api_token:e.api_token,domain:e.domain};d(o,"perfexcrm_authentication").then(t=>{if(t&&t.success){r(!0),a(u(c({},l),{auth:!1})),n.success(m("Authorized successfully","bit-integrations"));return}a(u(c({},l),{auth:!1})),n.error(m("Authorized failed, Please enter valid API Token or Access API URL","bit-integrations"))})},w=(e,i,s,r)=>{r(u(c({},s),{customers:!0}));const l={api_token:e.api_token,domain:e.domain};d(l,"perfexcrm_fetch_all_customers").then(a=>{if(a&&a.success){i(o=>F(o,t=>{a.data&&(t.customers=a.data)})),r(u(c({},s),{customers:!1})),n.success(m("Customer fetched successfully","bit-integrations"));return}r(u(c({},s),{customers:!1})),n.error(m("Customer Not Found!","bit-integrations"))})},v=(e,i,s,r)=>{r(u(c({},s),{leads:!0}));const l={api_token:e.api_token,domain:e.domain};d(l,"perfexcrm_fetch_all_leads").then(a=>{if(a&&a.success){i(o=>F(o,t=>{a.data&&(t.leads=a.data)})),r(u(c({},s),{leads:!1})),n.success(m("Lead fetched successfully","bit-integrations"));return}r(u(c({},s),{leads:!1})),n.error(m("Lead Not Found!","bit-integrations"))})},M=(e,i,s,r)=>{r(u(c({},s),{staffs:!0}));const l={api_token:e.api_token,domain:e.domain};d(l,"perfexcrm_fetch_all_staffs").then(a=>{if(a&&a.success){i(o=>F(o,t=>{a.data&&(t.staffs=a.data)})),r(u(c({},s),{staffs:!1})),n.success(m("Project Member fetched successfully","bit-integrations"));return}r(u(c({},s),{staffs:!1})),n.error(m("Project Member Not Found!","bit-integrations"))})};export{w as a,v as b,x as c,M as g,g as h,j as p,q as r};
