import{a9 as f,q as D,n as b,C as x}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b23.js";import{u as v}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b19.js";import{W as w,V as E}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b18.js";import{I as n}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b10.js";import{d as N}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b141.js";const P=c=>{let a=0;try{for(let s of c)a+=parseFloat(s.valor);return a.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}catch{return a.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}};async function T(c){var i,l;const{perfil:a}=f.getState(),{label:s}=D.getState(),{user:g}=b.getState(),u=await w.Contact("List"),e=v.getState().language,p=(l=(i=x.getState().activeChat)==null?void 0:i.id)==null?void 0:l.user;let o=a;if(!c){const t=a.find(r=>r.userID===p);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 m={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(m)});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};
