import{j as e,y as v,bi as S,H as L,Q as w,Y as A,I as N}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080910.js";import{a as n}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508094.js";import{o as C,n as y}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080923.js";import{u as _}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080919.js";import{I as E}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b2250809221.js";import{W as b}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080918.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508098.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b2250809.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508095.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508097.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508096.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508092.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508093.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508099.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 Y({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{Y as default};
