import{j as e,X as B,a1 as R,a4 as T,a7 as U}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b710.js";import{a as o}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b74.js";import{A as H,L as M}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b75.js";import{b as L,p as O,o as P}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b723.js";import{u as k,b as z}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b719.js";import{I as F}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b7210.js";import{W as _}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-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=({selectAll:u,pesquisar:a,setSelecionados:g,tabId:p})=>{const{userTabs:h}=L(),j=z.getState().isBusiness,[l,C]=o.useState([]);o.useEffect(()=>{(async()=>{const s=await _.Chat("List"),n=await _.Contact("List","onlyMyContacts"),c=j?await _.Contact("List","allLabels"):[],v=h.find(r=>r.id===p),N=(v==null?void 0:v.chats.map(r=>({id:r.id,name:r.id})))??[],E=s.concat(n).concat(c).concat(N),w=[],y=new Set;E.forEach(r=>{r.id&&!y.has(r.id)&&(y.add(r.id),w.push(r))}),f(w),C(w)})()},[]);const[i,f]=o.useState([]);o.useEffect(()=>{if(a.length===0)f(l);else{let t=[];l.forEach(s=>{var n;(s.id.includes(a)||(n=s.name)!=null&&n.toUpperCase().includes(a.toUpperCase()))&&t.push(s)}),f(t)}},[a]);const[d,m]=o.useState(new Set);o.useEffect(()=>{if(u)m(new Set);else{const t=i.map(s=>s.id);m(new Set(t))}},[u]);const x=t=>{m(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})};o.useEffect(()=>{h.forEach(t=>{t.id===p&&t.chats.forEach(s=>{x(s.id)})})},[h]),o.useEffect(()=>{g(l.filter(t=>d.has(t.id)))},[l,d]);const S=({index:t,key:s,style:n})=>{const c=i[t];if(c)return e.jsx("li",{style:n,children:e.jsx("div",{className:"form-control",children:e.jsxs("label",{className:"cursor-pointer label gap-2 justify-start",children:[e.jsx(U,{id:c.id,estado:d.has(c.id),checkedUpdade:()=>x(c.id)}),e.jsx("span",{className:"flex-[inherit] overflow-hidden text-ellipsis whitespace-nowrap",children:e.jsx("strong",{children:c.name})}),e.jsx("span",{children:c.id})]})})},c.id)},b=e.jsx("div",{className:"w-full pt-2",children:e.jsx("ul",{className:"gap-2 overflow-y-auto overflow-x-hidden justify-center",style:{maxHeight:"calc(100vh - 240px)",minHeight:"60px",height:`${i.length*32}px`},children:e.jsx(H,{children:({width:t,height:s})=>e.jsx(M,{width:t,height:s,rowCount:i.length,rowHeight:32,rowRenderer:S})})})}),A=e.jsx("div",{children:e.jsx("ul",{children:e.jsx("div",{style:{maxHeight:"calc(100vh - 300px)"},className:"grid overflow-auto mt-4 gap-1",children:e.jsx("li",{children:e.jsx("div",{children:e.jsx("span",{className:"w-full flex justify-center p-4",children:e.jsxs("strong",{children:[" ",a.length!==0?"Nenhum contato encontrado":"Carregando...","  "]})})})})})})});return i.length!==0?b:A};function se({tabId:u}){const{language:a}=k(),{setChatsTab:g}=L(),{openRendertype:p,close:h}=O(),{user:j}=P(),[l,C]=o.useState(""),[i,f]=o.useState(!0),d=()=>{f(!i)},[m,x]=o.useState([]);m.length>5&&!j.estado&&p("user_free");const S=async()=>{h(),g(m,u)};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(B,{children:a.menu_moreAba_addContact_title}),e.jsx(R,{children:a.menu_moreAba_addContact_subTitle}),e.jsx(F,{inpPlaceTxt:a.menu_moreAba_addContact_placeContact,inpValue:l,inpSetValue:C,selectAll:i,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:d,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:d}),e.jsx(I,{selectAll:i,pesquisar:l,setSelecionados:x,tabId:u}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(T,{name:a.menu_moreAba_addContact_placeButtonSave,funcao:S})})]})}export{se as default};

