import{j as a,Z as E,aK as q}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9910.js";import{a as u}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c994.js";import{D as S}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9923.js";import{u as A,b as U}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9919.js";import{W as x}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9918.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c998.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c99.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c995.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c997.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c996.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c999.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c992.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c993.js";function Z({userId:r,setUserLabels:m,userLabels:b}){const{variaveisWA:n}=S(),{language:f}=A(),{isBusiness:j}=U(),[d,v]=u.useState([]),[L,g]=u.useState(b);u.useEffect(()=>{j&&(async()=>{try{const s=await x.Labels("getAllLabels"),p=await x.Utils("getContato",r),l=p.labels.map(i=>s.find(e=>e.hexColor&&e.id===i)).filter(Boolean).map(({id:i,name:e,hexColor:o})=>({id:i,name:e,color:o,hexColor:o}));let c=[];s.forEach(i=>{const e=p.labels.find(o=>o===i.id);c.push({...i,active:!!e})}),m(l),v(c)}catch(s){console.error(f.erroAoBuscarLabels,s)}})()},[r]);const y=(t,s,p)=>{v(e=>{const o=[...e],h=o.findIndex(w=>w.id===s);return h!==-1&&(o[h]={...o[h],active:t}),o});const l=L.map(e=>({...e}));if(t){const e=d.find(o=>o.id===s);l.unshift({id:e.id,name:e.name,color:e.hexColor,hexColor:e.hexColor}),g(l),m(l)}else{const e=l.filter(o=>o.id!==s);g(e),m(e)}chrome.runtime.sendMessage({action:"update-card",userId:r});const c={labelId:s,type:t?"add":"remove"},i=r.length>15?`${r}@g.us`:`${r}@c.us`;x.Labels("addOrRemoveLabels",{id:i,label:c})},N=a.jsx("div",{className:"p-4",children:a.jsx("span",{children:f.crieEtiquetaParaInserirContatos})}),C=a.jsx("div",{className:n.modalOptions.content3+"overflow-auto",style:{maxHeight:"calc(100vh - 200px)"},children:d.slice().sort((t,s)=>t.name.localeCompare(s.name)).map((t,s)=>a.jsx("div",{className:n.listagem.content1+"hoverShadown",children:a.jsx("li",{tabIndex:1,className:n.listagem.content2,"data-animate-dropdown-item":"true",style:{opacity:1},children:a.jsx("label",{htmlFor:"user_labels&"+s,children:a.jsxs("div",{className:n.listagem.content3,children:[a.jsx("div",{className:n.listagem.content4,children:a.jsx(E,{id:"user_labels&"+s,estado:t.active,checkedUpdade:()=>{y(!t.active,t.id)}})}),a.jsx("span",{className:n.listagem.content5,children:a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("div",{className:"pr-1",children:[a.jsx("span",{children:t.name}),a.jsx("span",{className:n.aba+"tam-aba ml-1 h-5",style:{backgroundColor:"var(--primaria)"},children:t.count})]}),a.jsx("span",{children:a.jsx(q,{className:"w-6 h-6",style:{color:t.hexColor}})})]})})]})})})},s))});return d.length>0?C:N}export{Z as default};
