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_16_364f475f-21c1-4d89-bf17-70efc8c405b710.js";import{a as n}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b74.js";import{p as C,o as y}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b723.js";import{u as _}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b719.js";import{I as E}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b7210.js";import{W as b}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b718.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b78.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b7.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b75.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b77.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b76.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b79.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b72.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b73.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};
