import{j as e,y as w,H as y,Q as A,Y as _,I as E}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080910.js";import{a as o}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508094.js";import{a as N,o as I,n as P}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080923.js";import{u as B}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080919.js";import{I as q}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b2250809221.js";import{W as b}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080918.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508098.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b2250809.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508095.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508097.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508096.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508092.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508093.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508099.js";const T=({selectAll:u,pesquisar:a,setSelectLabels:f})=>{const[c,h]=o.useState([]);o.useEffect(()=>{(async()=>{const s=await b.Labels("getAllLabels");h(s),l(s)})()},[]);const[r,l]=o.useState([]);o.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,n]=o.useState(new Set);o.useEffect(()=>{if(u)n(new Set);else{const t=r.map(s=>s.id);n(new Set(t))}},[u]);const x=t=>{n(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})};o.useEffect(()=>{f(c.filter(t=>m.has(t.id)))},[m]);const p=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(_,{id:t.id,estado:m.has(t.id),checkedUpdade:()=>x(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,p]})})})};function Z({id:u}){const{language:a}=B(),{setCopyChats:f}=N(),{openRendertype:c,close:h}=I(),[r,l]=o.useState(""),{user:m}=P(),[n,x]=o.useState(!0),p=()=>{x(!n)},[t,s]=o.useState([]),i=async()=>{try{h();const g=t.map(async d=>await b.Contact("List",{type:"withLabels",id:d.id})),C=(await Promise.all(g)).reduce((d,j)=>d.concat(j),[]).filter((d,j,S)=>j===S.findIndex(v=>v.id===d.id));f(C,u),E({type:"Success",message:a.sucessImportContact,position:"top-right"})}catch(g){throw new Error("Error ao salvar:",g)}},L=()=>{m.estado?i():c("user_free")};return e.jsxs("div",{className:"w-[508px] h-fit",children:[e.jsx(w,{children:a.menu_moreAba_importContactForEtiquet}),e.jsx(y,{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:p,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:p}),e.jsx(T,{selectAll:n,pesquisar:r,setSelectLabels:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(A,{name:a.save,funcao:L})})]})}export{Z as default};
