import{j as e,Q as w,Z as A,a1 as _,a4 as y,I as E}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf10.js";import{a as o}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf4.js";import{b as N,o as I,n as P}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf23.js";import{u as B}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf19.js";import{I as q}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf212.js";import{W as b}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf18.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf8.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf5.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf7.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf6.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf9.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf2.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf3.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 Y({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{Y as default};
