import{j as a,Y as E,aH as q}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b10.js";import{a as u}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b4.js";import{D as S}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b23.js";import{u as A,b as U}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b19.js";import{W as x}from"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b18.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b8.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b5.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b7.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b6.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b9.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b2.js";import"./v_7_4_1_31_281d2484-5da9-48a8-8939-2c37d755bb5b3.js";function G({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("getContact",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.crieEtiquetaParaInserirContacts})}),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{G as default};
