import{j as e,X as v,bo as S,a1 as L,a4 as w,a7 as A,I as N}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f10.js";import{a as n}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f4.js";import{p as C,o as y}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f23.js";import{u as _}from"./v_7_4_2_18_ea7d0884-20ea-4e04-b6f3-cef449ac182f19.js";import{I as E}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 I=async(r,a,m)=>{const h=_.getState().language,d=C.getState().close;let u=m.filter(s=>!r.some(l=>l.id===s.id));u=u.map(s=>s.id.length>17?s.id+"@g.us":s.id+"@c.us");let i=r.filter(s=>!m.some(l=>l.id===s.id));i=i.map(s=>s.id.length>17?s.id+"@g.us":s.id+"@c.us"),await b.Labels("addOrRemoveLabels",{id:i,label:{labelId:a,type:"add"}}),N({type:"Success",message:h.contatosAdicionadosNaEtiqueta,position:"top-right"}),d()},R=({selectAll:r,pesquisar:a,setSelecionados:m,id:h,lb:d,setLb:u})=>{const[i,s]=n.useState([]);n.useEffect(()=>{const t=async()=>{const o=await b.Contact("List",{type:"withLabels",id:h});u(o)},c=async()=>{const o=await b.Chat("List");g(o),s(o)};t(),c()},[]);const[l,g]=n.useState([]);n.useEffect(()=>{if(a.length===0)g(i);else{let t=[];i.forEach(c=>{var o;(c.id.includes(a)||(o=c.name)!=null&&o.toUpperCase().includes(a.toUpperCase()))&&t.push(c)}),g(t)}},[a]);const[p,f]=n.useState(new Set);n.useEffect(()=>{if(r)f(new Set);else{const t=l.map(c=>c.id);f(new Set(t))}},[r]);const x=t=>{f(c=>{const o=new Set(c);return o.has(t)?o.delete(t):o.add(t),o})};n.useEffect(()=>{d.forEach(t=>{x(t.id)})},[d]),n.useEffect(()=>{m(i.filter(t=>p.has(t.id)))},[i,p]);const j=l.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(A,{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:[l.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 q({id:r}){const{language:a}=_(),{openRendertype:m}=C(),{user:h}=y(),[d,u]=n.useState(""),[i,s]=n.useState([]),[l,g]=n.useState(!0),p=()=>{g(!l)},[f,x]=n.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(v,{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(S,{className:"w-5 h-5 text-[var(--icon)]"})})]}),e.jsx(L,{children:a.menu_moreAba_addContactLabels_subTitle}),e.jsx(E,{inpPlaceTxt:a.menu_moreAba_addContact_placeContact,inpValue:d,inpSetValue:u,selectAll:l,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:p,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:p}),e.jsx(R,{selectAll:l,pesquisar:d,setSelecionados:x,id:r,lb:i,setLb:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(w,{name:a.menu_moreAba_addContact_placeButtonSave,funcao:()=>I(f,r,i)})})]})}export{q as default};
