var y=Object.defineProperty;var g=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var D=(e,t,i)=>t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,r=(e,t)=>{for(var i in t||(t={}))v.call(t,i)&&D(e,i,t[i]);if(g)for(var i of g(t))M.call(t,i)&&D(e,i,t[i]);return e};import{u as q}from"./Note.BeM7sN-p.js";import{_ as c,d as F}from"./main.2.8.1.js";const V=(e,t,i)=>{const a=r({},t),{name:s}=e.target;e.target.value!==""?a[s]=e.target.value:delete a[s],i(r({},a))},W=(e,t,i,a,s,n)=>{if(!e.numberID||!e.businessAccountID||!e.token){i({numberID:e.numberID?"":c("Phone number ID can't be empty or invalid","bit-integrations"),businessAccountID:e.businessAccountID?"":c("WhatsApp Business Account ID can't be empty or invalid","bit-integrations"),token:e.token?"":c("Access Token can't be empty or invalid","bit-integrations")});return}const o={numberID:e.numberID,businessAccountID:e.businessAccountID,token:e.token};s(!0),F(o,"whats_app_authorization").then(u=>{if(s(!1),u&&u.success){a(!0),n({show:!0,msg:c("Authorized Successfully","bit-integrations")});return}n({show:!0,msg:(u==null?void 0:u.data)||c("Authorized failed","bit-integrations")})})},h=(e,t,i,a)=>{if(!e.numberID||!e.businessAccountID||!e.token){setError({numberID:e.numberID?"":c("Phone number ID can't be empty or invalid","bit-integrations"),businessAccountID:e.businessAccountID?"":c("WhatsApp Business Account ID can't be empty or invalid","bit-integrations"),token:e.token?"":c("Access Token can't be empty or invalid","bit-integrations")});return}const s={numberID:e.numberID,businessAccountID:e.businessAccountID,token:e.token};i(!0),F(s,"whats_app_all_template").then(n=>{var o,u,l,d,m,b;if(i(!1),(u=(o=n==null?void 0:n.data)==null?void 0:o.error)!=null&&u.message)console.log((d=(l=n==null?void 0:n.data)==null?void 0:l.error)==null?void 0:d.message),a({show:!0,msg:c((b=(m=n==null?void 0:n.data)==null?void 0:m.error)==null?void 0:b.message,"bit-integrations")});else if(n&&n.success){t(_=>q(_,k=>{k.allTemplates=(n==null?void 0:n.data)||[]})),a({show:!0,msg:c("Template Fetched Successfully","bit-integrations")});return}})},x=e=>{const t=e.filter(i=>i.required===!0);return t.length>0?t.map(i=>({formField:"",whatsAppFormField:i.key})):[{formField:"",whatsAppFormField:""}]},I=e=>!((e?e.filter(i=>i.formField&&i.whatsAppFormField):[]).length>0),E=e=>{let t=!1;return((e==null?void 0:e.messageType)===""||(e==null?void 0:e.messageType)==="template"&&e.templateName===""||(e==null?void 0:e.messageType)==="text"&&e.body===""||(e==null?void 0:e.messageType)==="media"&&(e.upload_field===""||e.mediaType==="")||(e==null?void 0:e.messageType)==="contact"&&I(e.contact_field_map))&&(t=!0),I(e.field_map)||t},N=(e,t,i,a="field_map")=>{const s=r({},t);s[a].splice(e,0,{}),i(r({},s))},j=(e,t,i,a="field_map")=>{const s=r({},t);s[a].length>1&&s[a].splice(e,1),i(r({},s))},G=(e,t,i,a,s="field_map")=>{const n=r({},i);n[s][t][e.target.name]=e.target.value,e.target.value==="custom"&&(n[s][t].customValue=""),a(r({},n))},H=(e,t,i,a,s,n="field_map")=>{const o=r({},i);o[n][t].customValue=e,a(r({},o))};export{G as a,H as b,E as c,N as d,j as e,x as f,h as g,V as h,W as i};
