var y=Object.defineProperty,g=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var p=(e,s,t)=>s in e?y(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,u=(e,s)=>{for(var t in s||(s={}))b.call(s,t)&&p(e,t,s[t]);if(m)for(var t of m(s))K.call(s,t)&&p(e,t,s[t]);return e},f=(e,s)=>g(e,_(s));import{_ as o,b as F,c as n,G as A,s as P}from"./bi.394.85.js";const w=(e,s,t)=>{const a=u({},s),{name:r}=e.target;e.target.value!==""?a[r]=e.target.value:delete a[r],t(u({},a))},v=(e,s,t,a,r,i)=>{if(!e.authKey){t({authKey:e.authKey?"":o("API key can't be empty","bit-integrations")});return}t({}),i(f(u({},r),{auth:!0}));const d={authKey:e.authKey};F(d,"klaviyo_handle_authorize").then(l=>{if(l&&l.success){const c=u({},e);l.data&&(c.default||(c.default={}),c.default.lists=l.data),s(c),a(!0),i(f(u({},r),{auth:!1})),n.success(o("Authorized successfully","bit-integrations"));return}i(f(u({},r),{auth:!1})),n.error(o("Authorized failed","bit-integrations"))})},x=(e,s,t,a)=>{a(f(u({},t),{list:!0}));const r={authKey:e.authKey};F(r,"klaviyo_handle_authorize").then(i=>{if(i&&i.success){const d=u({},e);i.data&&(d.default||(d.default={}),d.default.lists=i.data),s(d),a(f(u({},t),{list:!1})),n.success(o("List refresh successfully","bit-integrations"));return}a(f(u({},t),{list:!1})),n.error(o("List refresh failed","bit-integrations"))})},I=e=>{const s=e==null?void 0:e.klaviyoFields.filter(t=>t.required===!0);return s.length>0?s.map(t=>({formField:"",klaviyoFormField:t.key})):[{formField:"",klaviyoFormField:""}]},h=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>!t.formField||!t.klaviyoFormField||!t.formField==="custom"&&!t.customValue):[]).length>0),M=(e,s,t)=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!h(e)){n.error("Please map mandatory fields");return}e.field_map.length>0&&s(t)},T=(e,s,t,a,r,i)=>{i(!0),A(e,s,t,a,r,"","",i).then(l=>{var c;l.success?(n.success((c=l.data)==null?void 0:c.msg),r(t)):n.error(l.data||l)})},k=(e,s,t,a,r,i)=>{if(!h(t)){n.error("Please map mandatory fields");return}if(h(t)==="required"){n.error("You must select email or phone in klaviyo fields");return}P({flow:e,allIntegURL:s,conf:t,navigate:a,edit:r,setIsLoading:i})};export{x as a,T as b,w as e,I as g,v as h,M as n,k as s};
