import{V as S,z as f}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a55.js";import{e as D,u as L,V as x}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a54.js";import{D as w,w as N}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a525.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a53.js";import{I as n}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a58.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a52.js";import{d as b}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5174.js";const v=i=>{let a=0;try{for(let s of i)a+=parseFloat(s.valor);return a.toLocaleString("es-CO",{style:"currency",currency:"COP"})}catch{return a.toLocaleString("es-CO",{style:"currency",currency:"COP"})}};async function T(i){const{perfil:a}=w.getState(),{config:s}=D.getState(),{session:c}=S.getState(),l=await f.Contact("List"),e=L.getState().language,m=N.getState().activeChat?.id?.user;let o=a;if(!i){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"});c.is_premium||(o=o.slice(0,5),n({type:"Info",message:e.exportProfileUserFreeAlert,position:"top-right"}));const p={profiles:o.map(t=>{const r=l.find(({id:h})=>h===t.userID),g=r?r.name:"",u=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]:g,[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]:u,[e.exit]:d,[e.observations]:t.observacoes,[e.products]:t.produtos.toString(),[e.businessValue]:v(t.valNegocio)}}),labelName:s.primeiroNome};try{const t=await fetch(`${x.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();b(r.XLSXbase64,`${s.primeiroNome}_${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};
