import{j as e}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0286.js";import{a as n}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0282.js";import{u as w,b as _}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0285.js";import{u as A,k as y}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02821.js";import{a as E,b as N,c as I,e as P,I as B}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0288.js";import{I as q}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b028223.js";import{W as j}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0283.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0284.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02820.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b028.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0287.js";const T=({selectAll:p,pesquisar:a,setSelectLabels:h})=>{const[c,x]=n.useState([]);n.useEffect(()=>{(async()=>{const t=await j.Labels("getAllLabels");x(t),l(t)})()},[]);const[r,l]=n.useState([]);n.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,o]=n.useState(new Set);n.useEffect(()=>{if(p)o(new Set);else{const s=r.map(t=>t.id);o(new Set(s))}},[p]);const b=s=>{o(t=>{const i=new Set(t);return i.has(s)?i.delete(s):i.add(s),i})};n.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:()=>b(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 Q({id:p}){const{language:a}=w(),{setCopyChats:h}=A(),{openRendertype:c,close:x}=y(),[r,l]=n.useState(""),m=_(d=>d.session),[o,b]=n.useState(!0),f=()=>{b(!o)},[s,t]=n.useState([]),i=async()=>{try{x();const d=s.map(async u=>await j.Contact("List",{type:"withLabels",id:u.id})),C=(await Promise.all(d)).reduce((u,g)=>u.concat(g),[]).filter((u,g,S)=>g===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:t}),e.jsx("div",{className:"flex justify-end p-2",children:e.jsx(I,{name:a.save,funcao:L})})]})}export{Q as default};
