import{j as e}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d65.js";import{r as o}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6.js";import{u as w,b as _}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d64.js";import{u as A,m as y}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d623.js";import{o as E,p as N,r as I,u as P,I as B}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d67.js";import{I as q}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d6214.js";import{W as b}from"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d62.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d63.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d69.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d610.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d620.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d68.js";import"./v_7_4_3_26_c99b3fd5-4d99-426a-8862-d508d2f3e0d66.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};
