import{j as e}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0286.js";import{a as n}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0282.js";import{A as E,L as B}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02812.js";import{u as R,b as T,d as k}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0285.js";import{u as L,k as H}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02821.js";import{a as M,b as O,c as P,e as U}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0288.js";import{I as z}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b028223.js";import{W as b}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0283.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b028.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0284.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02820.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0287.js";const F=({selectAll:u,pesquisar:a,setSelecionados:g,tabId:p})=>{const{userTabs:h}=L(),j=k.getState().isBusiness,[r,C]=n.useState([]);n.useEffect(()=>{(async()=>{const s=await b.Chat("List"),l=await b.Contact("List","onlyMyContacts"),i=j?await b.Contact("List","allLabels"):[],A=h.find(c=>c.id===p)?.chats.map(c=>({id:c.id,name:c.id}))??[],N=s.concat(l).concat(i).concat(A),w=[],y=new Set;N.forEach(c=>{c.id&&!y.has(c.id)&&(y.add(c.id),w.push(c))}),f(w),C(w)})()},[]);const[o,f]=n.useState([]);n.useEffect(()=>{if(a.length===0)f(r);else{let t=[];r.forEach(s=>{(s.id.includes(a)||s.name?.toUpperCase().includes(a.toUpperCase()))&&t.push(s)}),f(t)}},[a]);const[d,m]=n.useState(new Set);n.useEffect(()=>{if(u)m(new Set);else{const t=o.map(s=>s.id);m(new Set(t))}},[u]);const x=t=>{m(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})};n.useEffect(()=>{h.forEach(t=>{t.id===p&&t.chats.forEach(s=>{x(s.id)})})},[h]),n.useEffect(()=>{g(r.filter(t=>d.has(t.id)))},[r,d]);const S=({index:t,key:s,style:l})=>{const i=o[t];if(i)return e.jsx("li",{style:l,children:e.jsx("div",{className:"form-control",children:e.jsxs("label",{className:"cursor-pointer label gap-2 justify-start",children:[e.jsx(U,{id:i.id,estado:d.has(i.id),checkedUpdade:()=>x(i.id)}),e.jsx("span",{className:"flex-[inherit] overflow-hidden text-ellipsis whitespace-nowrap",children:e.jsx("strong",{children:i.name})}),e.jsx("span",{children:i.id})]})})},i.id)},_=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:`${o.length*32}px`},children:e.jsx(E,{children:({width:t,height:s})=>e.jsx(B,{width:t,height:s,rowCount:o.length,rowHeight:32,rowRenderer:S})})})}),v=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 o.length!==0?_:v};function ee({tabId:u}){const{language:a}=R(),{setChatsTab:g}=L(),{openRendertype:p,close:h}=H(),j=T(v=>v.session),[r,C]=n.useState(""),[o,f]=n.useState(!0),d=()=>{f(!o)},[m,x]=n.useState([]);m.length>5&&!j.is_premium&&p("user_free");const S=async()=>{h(),g(m,u)};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(M,{children:a.menu_moreAba_addContact_title}),e.jsx(O,{children:a.menu_moreAba_addContact_subTitle}),e.jsx(z,{inpPlaceTxt:a.menu_moreAba_addContact_placeContact,inpValue:r,inpSetValue:C,selectAll:o,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:d,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:d}),e.jsx(F,{selectAll:o,pesquisar:r,setSelecionados:x,tabId:u}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(P,{name:a.menu_moreAba_addContact_placeButtonSave,funcao:S})})]})}export{ee as default};
