import{j as e}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a53.js";import{a as n}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a52.js";import{A as E,L as B}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a512.js";import{V as R,u as T,z as _}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a55.js";import{a as A,q as H}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a525.js";import{u as M}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a54.js";import{D as O,E as U,H as k,K as V}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a58.js";import{I as z}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5233.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a56.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a59.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a510.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a57.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a520.js";const F=({selectAll:u,pesquisar:a,setSelecionados:j,tabId:p})=>{const{userTabs:h}=A(),g=T.getState().isBusiness,[l,C]=n.useState([]);n.useEffect(()=>{(async()=>{const s=await _.Chat("List"),r=await _.Contact("List","onlyMyContacts"),i=g?await _.Contact("List","allLabels"):[],L=h.find(c=>c.id===p)?.chats.map(c=>({id:c.id,name:c.id}))??[],N=s.concat(r).concat(i).concat(L),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(l);else{let t=[];l.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 r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})};n.useEffect(()=>{h.forEach(t=>{t.id===p&&t.chats.forEach(s=>{x(s.id)})})},[h]),n.useEffect(()=>{j(l.filter(t=>d.has(t.id)))},[l,d]);const S=({index:t,key:s,style:r})=>{const i=o[t];if(i)return e.jsx("li",{style:r,children:e.jsx("div",{className:"form-control",children:e.jsxs("label",{className:"cursor-pointer label gap-2 justify-start",children:[e.jsx(V,{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)},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:`${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?b:v};function se({tabId:u}){const{language:a}=M(),{setChatsTab:j}=A(),{openRendertype:p,close:h}=H(),g=R(v=>v.session),[l,C]=n.useState(""),[o,f]=n.useState(!0),d=()=>{f(!o)},[m,x]=n.useState([]);m.length>5&&!g.is_premium&&p("user_free");const S=async()=>{h(),j(m,u)};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(O,{children:a.menu_moreAba_addContact_title}),e.jsx(U,{children:a.menu_moreAba_addContact_subTitle}),e.jsx(z,{inpPlaceTxt:a.menu_moreAba_addContact_placeContact,inpValue:l,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:l,setSelecionados:x,tabId:u}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(k,{name:a.menu_moreAba_addContact_placeButtonSave,funcao:S})})]})}export{se as default};
