import{j as e,v as _,b6 as S,D as L,J as w,V as A,I as N}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{a as n}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e4.js";import{n as v,m as y}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e22.js";import{u as C}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{I as E}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e173.js";import{W as b}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e18.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e8.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e5.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e7.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e6.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e2.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e3.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e9.js";const I=async(r,a,m)=>{const h=C.getState().language,d=v.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:"Loading..."})," "]})})}):void 0,j]})})})};function q({id:r}){const{language:a}=C(),{openRendertype:m}=v(),{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(_,{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};
