import{r as o,j as e}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b.js";import{b as w,p as A,o as _}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b24.js";import{u as y}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b20.js";import{Q as E,$ as N,a2 as I,a5 as P,I as B}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b11.js";import{I as q}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b214.js";import{W as b}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b19.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b7.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b9.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b6.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b8.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b4.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b3.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b2.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b10.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(P,{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}=y(),{setCopyChats:f}=w(),{openRendertype:c,close:h}=A(),[r,l]=o.useState(""),{user:m}=_(),[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),B({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(E,{children:a.menu_moreAba_importContactForEtiquet}),e.jsx(N,{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(I,{name:a.save,funcao:L})})]})}export{Y as default};
