import{j as e}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a53.js";import{a as n}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a52.js";import{V as w,z as b}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a55.js";import{a as _,q as A}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a525.js";import{u as y}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a54.js";import{D as E,E as N,H as I,K as q,I as B}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a58.js";import{I as P}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5233.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a56.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a59.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a510.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a57.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a520.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 j=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(q,{id:t.id,estado:m.has(t.id),checkedUpdade:()=>j(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}=y(),{setCopyChats:h}=_(),{openRendertype:c,close:x}=A(),[r,l]=n.useState(""),m=w(d=>d.session),[o,j]=n.useState(!0),f=()=>{j(!o)},[t,s]=n.useState([]),i=async()=>{try{x();const d=t.map(async u=>await b.Contact("List",{type:"withLabels",id:u.id})),L=(await Promise.all(d)).reduce((u,g)=>u.concat(g),[]).filter((u,g,S)=>g===S.findIndex(v=>v.id===u.id));h(L,p),B({type:"Success",message:a.sucessImportContact,position:"top-right"})}catch(d){throw new Error("Error ao salvar:",d)}},C=()=>{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(P,{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:C})})]})}export{Y as default};
