import{j as e}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f5.js";import{r as o}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f.js";import{u as w,b as _}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f4.js";import{u as A,m as y}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f23.js";import{o as E,p as N,r as I,u as P,I as B}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f7.js";import{I as q}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f213.js";import{W as b}from"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f2.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f3.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f9.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f10.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f8.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f20.js";import"./v_7_4_3_35_4ab187d4-286d-4a55-8ea4-8375ea3c1d1f6.js";const T=({selectAll:p,pesquisar:a,setSelectLabels:h})=>{const[c,x]=o.useState([]);o.useEffect(()=>{(async()=>{const t=await b.Labels("getAllLabels");x(t),l(t)})()},[]);const[r,l]=o.useState([]);o.useEffect(()=>{if(a.length===0)l(c);else{let s=[];c.forEach(t=>{t.name.toUpperCase().includes(a.toUpperCase())&&s.push(t)}),l(s)}},[a]);const[m,n]=o.useState(new Set);o.useEffect(()=>{if(p)n(new Set);else{const s=r.map(t=>t.id);n(new Set(s))}},[p]);const g=s=>{n(t=>{const i=new Set(t);return i.has(s)?i.delete(s):i.add(s),i})};o.useEffect(()=>{h(c.filter(s=>m.has(s.id)))},[m]);const f=r.map(s=>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:s.id,estado:m.has(s.id),checkedUpdade:()=>g(s.id)}),e.jsx("span",{children:e.jsx("strong",{children:s.name})}),e.jsxs("span",{children:[s.count," Contatos"]})]})})},s.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 Y({id:p}){const{language:a}=w(),{setCopyChats:h}=A(),{openRendertype:c,close:x}=y(),[r,l]=o.useState(""),m=_(d=>d.session),[n,g]=o.useState(!0),f=()=>{g(!n)},[s,t]=o.useState([]),i=async()=>{try{x();const d=s.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:n,btnConfirmName:a.menu_moreAba_addContact_placeButtonSelectAll,btnConfirmFuncao:f,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:f}),e.jsx(T,{selectAll:n,pesquisar:r,setSelectLabels:t}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(I,{name:a.save,funcao:L})})]})}export{Y as default};
