import{j as a,Y as E,aH as q}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080910.js";import{a as u}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508094.js";import{D as S}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080923.js";import{u as A,b as U}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080919.js";import{W as x}from"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b225080918.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508098.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b2250809.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508095.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508097.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508096.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508092.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508093.js";import"./v_7_4_1_21_73d2acb1-b7f3-47a2-a8fe-3772b22508099.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("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{G as default};
