import{r as n,j as e}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a2777.js";import{u as w,a as _}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277720.js";import{u as A,m as y}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277723.js";import{V as E,X as N,$ as I,a1 as P,I as B}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277711.js";import{I as q}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a2777212.js";import{W as b}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277719.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27778.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27777.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27774.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27773.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27772.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277710.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27776.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27779.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 Y({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{Y as default};
