import{j as e,V as v,bc as S,$ as L,a2 as w,a5 as A,I as N}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e410.js";import{a as n}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e44.js";import{p as C,o as y}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e423.js";import{u as _}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e419.js";import{I as E}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e4211.js";import{W as b}from"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e418.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e48.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e4.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e45.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e47.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e46.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e49.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e42.js";import"./v_7_4_2_14_b047d88c-9af4-4a49-a965-946ffe7780e43.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};
