import{a5 as f,m as D,z as b}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e22.js";import{a as x,u as v}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{W as w,V as E}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e18.js";import{I as n}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{d as N}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e124.js";const P=c=>{let a=0;try{for(let s of c)a+=parseFloat(s.valor);return a.toLocaleString("en-IN",{style:"currency",currency:"INR"})}catch{return a.toLocaleString("en-IN",{style:"currency",currency:"INR"})}};async function T(c){var i,l;const{perfil:a}=f.getState(),{label:s}=x.getState(),{user:g}=D.getState(),u=await w.Contact("List"),e=v.getState().language,m=(l=(i=b.getState().activeChat)==null?void 0:i.id)==null?void 0:l.user;let o=a;if(!c){const t=a.find(r=>r.userID===m);o=t?[t]:[]}if(a.length==0||!o||o.length===0)return n({type:"Error",message:e.perfilEmpty,position:"top-right"});g.estado||(o=o.slice(0,5),n({type:"Info",message:e.exportProfileUserFreeAlert,position:"top-right"}));const p={profiles:o.map(t=>{const r=u.find(({id:L})=>L===t.userID),d=r?r.name:"",y=t.entrada&&new Date(t.entrada.replaceAll("-","/")).toLocaleDateString(),h=t.saida&&new Date(t.saida.replaceAll("-","/")).toLocaleDateString(),S=t.dataNascimento&&new Date(t.dataNascimento.replaceAll("-","/")).toLocaleDateString();return{[e.name]:d,[e.email]:t.email,[e.whatsApp]:t.userID,[e.city]:t.cidade,[e.estado]:t.estado,[e.sex]:t.sexo,[e.birthDay]:S,[e.enterprise]:t.empresa,[e.job]:t.cargo,[e.sourceLead]:t.origemLead,[e.entry]:y,[e.exit]:h,[e.observations]:t.observacoes,[e.products]:t.produtos.toString(),[e.businessValue]:P(t.valNegocio)}}),labelName:s.name};try{const t=await fetch(`${E.backend_utils}api/XLSX/contactprofile`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!t.ok)throw new Error("Erro ao enviar dados para o servidor");const r=await t.json();N(r.XLSXbase64,`${s.name}_${e.contactProfile}.xlsx`),n({type:"Success",message:e.exportSuccess,position:"top-right"})}catch(t){console.error("Erro ao exportar perfis:",t),n({type:"Error",message:e.erroEnvio,position:"top-right"})}}export{T as e};
