import{e as S,b as f,u as L}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d64.js";import{C as D,v as x}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d623.js";import{W as b,V as v}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d62.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d65.js";import{I as n}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d67.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6.js";import{d as N}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6156.js";const w=i=>{let a=0;try{for(let s of i)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 V(i){const{perfil:a}=D.getState(),{config:s}=S.getState(),{session:c}=f.getState(),l=await b.Contact("List"),e=L.getState().language,g=x.getState().activeChat?.id?.user;let o=a;if(!i){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"});c.is_premium||(o=o.slice(0,5),n({type:"Info",message:e.exportProfileUserFreeAlert,position:"top-right"}));const m={profiles:o.map(t=>{const r=l.find(({id:h})=>h===t.userID),p=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]: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]:u,[e.exit]:d,[e.observations]:t.observacoes,[e.products]:t.produtos.toString(),[e.businessValue]:w(t.valNegocio)}}),labelName:s.primeiroNome};try{const t=await fetch(`${v.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.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{V as e};
