import{G as S,s as L,o as f,z as D}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b24.js";import{u as b}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b20.js";import{W as x,V as v}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b19.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b.js";import{I as n}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b11.js";import{d as w}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b156.js";const E=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 W(c){const{perfil:a}=S.getState(),{label:s}=L.getState(),{user:i}=f.getState(),l=await x.Contact("List"),e=b.getState().language,g=D.getState().activeChat?.id?.user;let o=a;if(!c){const t=a.find(r=>r.userID===g);o=t?[t]:[]}if(a.length==0||!o||o.length===0)return n({type:"Error",message:e.perfilEmpty,position:"top-right"});i.estado||(o=o.slice(0,5),n({type:"Info",message:e.exportProfileUserFreeAlert,position:"top-right"}));const u={profiles:o.map(t=>{const r=l.find(({id:h})=>h===t.userID),p=r?r.name:"",m=t.entrada&&new Date(t.entrada.replaceAll("-","/")).toLocaleDateString(),d=t.saida&&new Date(t.saida.replaceAll("-","/")).toLocaleDateString(),y=t.dataNascimento&&new Date(t.dataNascimento.replaceAll("-","/")).toLocaleDateString();return{[e.name]:p,[e.email]:t.email,[e.whatsApp]:t.userID,[e.city]:t.cidade,[e.estado]:t.estado,[e.sex]:t.sexo,[e.birthDay]:y,[e.enterprise]:t.empresa,[e.job]:t.cargo,[e.sourceLead]:t.origemLead,[e.entry]:m,[e.exit]:d,[e.observations]:t.observacoes,[e.products]:t.produtos.toString(),[e.businessValue]:E(t.valNegocio)}}),labelName:s.name};try{const t=await fetch(`${v.backend_utils}api/XLSX/contactprofile`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!t.ok)throw new Error("Erro ao enviar dados para o servidor");const r=await t.json();w(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{W as e};
