import{r as n,j as e}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f.js";import{u as w,a as _}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f20.js";import{u as A,m as y}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f23.js";import{D as E,H as N,Q as I,X as P,I as B}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f11.js";import{I as q}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f213.js";import{W as b}from"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f19.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f8.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f7.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f4.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f3.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f2.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f10.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f6.js";import"./v_7_4_3_7_e8fda66a-fa64-447c-bcdc-42ba13285e7f9.js";const T=({selectAll:p,pesquisar:a,setSelectLabels:h})=>{const[c,x]=n.useState([]);n.useEffect(()=>{(async()=>{const s=await b.Labels("getAllLabels");x(s),l(s)})()},[]);const[r,l]=n.useState([]);n.useEffect(()=>{if(a.length===0)l(c);else{let t=[];c.forEach(s=>{s.name.toUpperCase().includes(a.toUpperCase())&&t.push(s)}),l(t)}},[a]);const[m,o]=n.useState(new Set);n.useEffect(()=>{if(p)o(new Set);else{const t=r.map(s=>s.id);o(new Set(t))}},[p]);const g=t=>{o(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})};n.useEffect(()=>{h(c.filter(t=>m.has(t.id)))},[m]);const f=r.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(P,{id:t.id,estado:m.has(t.id),checkedUpdade:()=>g(t.id)}),e.jsx("span",{children:e.jsx("strong",{children:t.name})}),e.jsxs("span",{children:[t.count," Contatos"]})]})})},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:[r.length===0?e.jsx("li",{children:e.jsx("div",{children:e.jsxs("span",{className:"w-full text-center p-4",children:[" ",e.jsx("strong",{children:"Nenhuma etiqueta encontrada"})," "]})})}):void 0,f]})})})};function Z({id:p}){const{language:a}=w(),{setCopyChats:h}=A(),{openRendertype:c,close:x}=y(),[r,l]=n.useState(""),m=_(d=>d.session),[o,g]=n.useState(!0),f=()=>{g(!o)},[t,s]=n.useState([]),i=async()=>{try{x();const d=t.map(async u=>await b.Contact("List",{type:"withLabels",id:u.id})),C=(await Promise.all(d)).reduce((u,j)=>u.concat(j),[]).filter((u,j,S)=>j===S.findIndex(v=>v.id===u.id));h(C,p),B({type:"Success",message:a.sucessImportContact,position:"top-right"})}catch(d){throw new Error("Error ao salvar:",d)}},L=()=>{m.is_premium?i():c("user_free")};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(E,{children:a.menu_moreAba_importContactForEtiquet}),e.jsx(N,{children:a.menu_moreAba_selectEtiquet}),e.jsx(q,{inpPlaceTxt:"Pesquise por uma etiqueta",inpValue:r,inpSetValue:l,selectAll:o,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:f,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:f}),e.jsx(T,{selectAll:o,pesquisar:r,setSelectLabels:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(I,{name:a.save,funcao:L})})]})}export{Z as default};
