import{j as a,V as E,ag as q}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{a as h}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e4.js";import{B as S}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e22.js";import{u as A,c as B}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{W as x}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";function G({userId:r,setUserLabels:m,userLabels:b}){const{variaveisWA:n}=S(),{language:f}=A(),{isBusiness:j}=B(),[d,g]=h.useState([]),[L,v]=h.useState(b);h.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),g(c)}catch(s){console.error(f.erroAoBuscarLabels,s)}})()},[r]);const y=(t,s,p)=>{g(e=>{const o=[...e],u=o.findIndex(w=>w.id===s);return u!==-1&&(o[u]={...o[u],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}),v(l),m(l)}else{const e=l.filter(o=>o.id!==s);v(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",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};
