import{r as o,j as e}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b.js";import{p as C,o as v}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b24.js";import{u as _}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b20.js";import{Q as S,bm as L,$ as w,a2 as A,a5 as N,I as y}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b11.js";import{I as E}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 I=async(r,a,m)=>{const h=_.getState().language,d=C.getState().close;let u=m.filter(s=>!r.some(i=>i.id===s.id));u=u.map(s=>s.id.length>17?s.id+"@g.us":s.id+"@c.us");let n=r.filter(s=>!m.some(i=>i.id===s.id));n=n.map(s=>s.id.length>17?s.id+"@g.us":s.id+"@c.us"),await b.Labels("addOrRemoveLabels",{id:n,label:{labelId:a,type:"add"}}),y({type:"Success",message:h.contatosAdicionadosNaEtiqueta,position:"top-right"}),d()},R=({selectAll:r,pesquisar:a,setSelecionados:m,id:h,lb:d,setLb:u})=>{const[n,s]=o.useState([]);o.useEffect(()=>{const t=async()=>{const c=await b.Contact("List",{type:"withLabels",id:h});u(c)},l=async()=>{const c=await b.Chat("List");g(c),s(c)};t(),l()},[]);const[i,g]=o.useState([]);o.useEffect(()=>{if(a.length===0)g(n);else{let t=[];n.forEach(l=>{(l.id.includes(a)||l.name?.toUpperCase().includes(a.toUpperCase()))&&t.push(l)}),g(t)}},[a]);const[p,f]=o.useState(new Set);o.useEffect(()=>{if(r)f(new Set);else{const t=i.map(l=>l.id);f(new Set(t))}},[r]);const x=t=>{f(l=>{const c=new Set(l);return c.has(t)?c.delete(t):c.add(t),c})};o.useEffect(()=>{d.forEach(t=>{x(t.id)})},[d]),o.useEffect(()=>{m(n.filter(t=>p.has(t.id)))},[n,p]);const j=i.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(N,{id:t.id,estado:p.has(t.id),checkedUpdade:()=>x(t.id)}),e.jsx("span",{children:e.jsx("strong",{children:t.name})}),e.jsx("span",{children:t.id})]})})},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:[i.length===0?e.jsx("li",{children:e.jsx("div",{children:e.jsxs("span",{className:"w-full flex justify-center p-4",children:[" ",e.jsx("strong",{children:"Carregando..."})," "]})})}):void 0,j]})})})};function $({id:r}){const{language:a}=_(),{openRendertype:m}=C(),{user:h}=v(),[d,u]=o.useState(""),[n,s]=o.useState([]),[i,g]=o.useState(!0),p=()=>{g(!i)},[f,x]=o.useState([]);return f.length>5&&!h.estado&&m("user_free"),e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx(S,{children:a.menu_moreAba_addContactLabel_title}),e.jsx("span",{className:"pulse cursor-pointer lg:tooltip lg:tooltip-bottom tooltip-w-fit  before:!w-24 mt-2","data-tip":a.menu_moreAba_infoLabels,children:e.jsx(L,{className:"w-5 h-5 text-[var(--icon)]"})})]}),e.jsx(w,{children:a.menu_moreAba_addContactLabels_subTitle}),e.jsx(E,{inpPlaceTxt:a.menu_moreAba_addContact_placeContact,inpValue:d,inpSetValue:u,selectAll:i,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:p,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:p}),e.jsx(R,{selectAll:i,pesquisar:d,setSelecionados:x,id:r,lb:n,setLb:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(A,{name:a.menu_moreAba_addContact_placeButtonSave,funcao:()=>I(f,r,n)})})]})}export{$ as default};
