import{j as e,X as w,a1 as A,a4 as _,a7 as y,I as E}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f10.js";import{a as o}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f4.js";import{b as N,p as I,o as P}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f23.js";import{u as B}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f19.js";import{I as q}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f210.js";import{W as b}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f18.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f8.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f5.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f7.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f6.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f9.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f2.js";import"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f3.js";const T=({selectAll:u,pesquisar:a,setSelectLabels:f})=>{const[c,h]=o.useState([]);o.useEffect(()=>{(async()=>{const s=await b.Labels("getAllLabels");h(s),l(s)})()},[]);const[r,l]=o.useState([]);o.useEffect(()=>{if(a.length===0)l(c);else{let t=[];c.forEach(s=>{s.name.toUpperCase().includes(a.toUpperCase())&&t.push(s)}),l(t)}},[a]);const[m,n]=o.useState(new Set);o.useEffect(()=>{if(u)n(new Set);else{const t=r.map(s=>s.id);n(new Set(t))}},[u]);const x=t=>{n(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})};o.useEffect(()=>{f(c.filter(t=>m.has(t.id)))},[m]);const p=r.map(t=>e.jsx("li",{children:e.jsx("div",{className:"form-control animate__animated animate__fadeInDownBig",children:e.jsxs("label",{className:"cursor-pointer label gap-2 justify-start",children:[e.jsx(y,{id:t.id,estado:m.has(t.id),checkedUpdade:()=>x(t.id)}),e.jsx("span",{children:e.jsx("strong",{children:t.name})}),e.jsxs("span",{children:[t.count," Contatos"]})]})})},t.id));return e.jsx("div",{children:e.jsx("ul",{children:e.jsxs("div",{style:{maxHeight:"calc(100vh - 300px)"},className:"grid overflow-auto mt-4 gap-1",children:[r.length===0?e.jsx("li",{children:e.jsx("div",{children:e.jsxs("span",{className:"w-full text-center p-4",children:[" ",e.jsx("strong",{children:"Nenhuma etiqueta encontrada"})," "]})})}):void 0,p]})})})};function Z({id:u}){const{language:a}=B(),{setCopyChats:f}=N(),{openRendertype:c,close:h}=I(),[r,l]=o.useState(""),{user:m}=P(),[n,x]=o.useState(!0),p=()=>{x(!n)},[t,s]=o.useState([]),i=async()=>{try{h();const g=t.map(async d=>await b.Contact("List",{type:"withLabels",id:d.id})),C=(await Promise.all(g)).reduce((d,j)=>d.concat(j),[]).filter((d,j,S)=>j===S.findIndex(v=>v.id===d.id));f(C,u),E({type:"Success",message:a.sucessImportContact,position:"top-right"})}catch(g){throw new Error("Error ao salvar:",g)}},L=()=>{m.estado?i():c("user_free")};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(w,{children:a.menu_moreAba_importContactForEtiquet}),e.jsx(A,{children:a.menu_moreAba_selectEtiquet}),e.jsx(q,{inpPlaceTxt:"Pesquise por uma etiqueta",inpValue:r,inpSetValue:l,selectAll:n,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:p,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:p}),e.jsx(T,{selectAll:n,pesquisar:r,setSelectLabels:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(_,{name:a.save,funcao:L})})]})}export{Z as default};
