import{j as e,v as w,D as A,J as _,V as y,I as E}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{a as n}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e4.js";import{a as N,n as I,m as P}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e22.js";import{u as B}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{I as q}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e173.js";import{W as b}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e18.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e8.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e5.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e7.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e6.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e2.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e3.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e9.js";const T=({selectAll:u,pesquisar:a,setSelectLabels:f})=>{const[c,h]=n.useState([]);n.useEffect(()=>{(async()=>{const s=await b.Labels("getAllLabels");h(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(u)o(new Set);else{const t=r.map(s=>s.id);o(new Set(t))}},[u]);const x=t=>{o(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})};n.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(y,{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]=n.useState(""),{user:m}=P(),[o,x]=n.useState(!0),p=()=>{x(!o)},[t,s]=n.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(A,{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:p,btnNegacaoName:a.menu_moreAba_removeAll,btnNegacaoFuncao:p}),e.jsx(T,{selectAll:o,pesquisar:r,setSelectLabels:s}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(_,{name:a.save,funcao:L})})]})}export{Z as default};
