import{j as e,y as B,J as R,V as T,Z as U}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9910.js";import{a as o}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c994.js";import{A as H,L as M}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c995.js";import{a as L,o as O,n as P}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9923.js";import{u as k,b as V}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9919.js";import{I as z}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c99222.js";import{W as _}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9918.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c998.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c99.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c997.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c996.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c999.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c992.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c993.js";const F=({selectAll:u,pesquisar:a,setSelecionados:g,tabId:p})=>{const{userTabs:h}=L(),j=V.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(z,{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(F,{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};
