import{j as e}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d65.js";import{r as o}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6.js";import{u as _,b as v}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d64.js";import{m as C}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d623.js";import{o as S,b9 as L,p as w,r as A,u as N,I as y}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d67.js";import{I as E}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6214.js";import{W as b}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d62.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d63.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d69.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d610.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d620.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d68.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d66.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 q({id:r}){const{language:a}=_(),{openRendertype:m}=C(),h=v(t=>t.session),[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.is_premium&&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{q as default};
