import{r as u,j as a}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab.js";import{ac as E,v as q}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab23.js";import{u as A,h as S}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab20.js";import{X as _,aQ as k}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab11.js";import{W as h}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab19.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab8.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab7.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab4.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab3.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab2.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab10.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab6.js";import"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab9.js";function G({setUserLabels:c,userLabels:b}){const{variaveisWA:o}=E(),{language:x}=A(),{isBusiness:g}=S(),{user:j,_serialized:d}=q(s=>s.activeChat?.default_id),[m,f]=u.useState([]),[L,v]=u.useState(b);u.useEffect(()=>{g&&(async()=>{try{const t=await h.Labels("getAllLabels"),p=await h.Chat("get",d),n=p.labels.map(e=>t.find(i=>i.hexColor&&i.id===e)).filter(Boolean).map(({id:e,name:i,hexColor:r})=>({id:e,name:i,color:r,hexColor:r}));let l=[];t.forEach(e=>{const i=p.labels.find(r=>r===e.id);l.push({...e,active:!!i})}),c(n),f(l)}catch(t){console.error(x.erroAoBuscarLabels,t)}})()},[d]);const C=(s,t,p)=>{f(e=>{const i=[...e],r=i.findIndex(w=>w.id===t);return r!==-1&&(i[r]={...i[r],active:s}),i});const n=L.map(e=>({...e}));if(s){const e=m.find(i=>i.id===t);n.unshift({id:e.id,name:e.name,color:e.hexColor,hexColor:e.hexColor}),v(n),c(n)}else{const e=n.filter(i=>i.id!==t);v(e),c(e)}chrome.runtime.sendMessage({action:"update-card",userId:j});const l={labelId:t,type:s?"add":"remove"};h.Labels("addOrRemoveLabels",{id:d,label:l})},y=a.jsx("div",{className:"p-4",children:a.jsx("span",{children:x.crieEtiquetaParaInserirContatos})}),N=a.jsx("div",{className:o.modalOptions.content3+"overflow-auto",style:{maxHeight:"calc(100vh - 200px)"},children:m.slice().sort((s,t)=>s.name.localeCompare(t.name)).map((s,t)=>a.jsx("div",{className:o.listagem.content1+"hoverShadown",children:a.jsx("li",{tabIndex:1,className:o.listagem.content2,"data-animate-dropdown-item":"true",style:{opacity:1},children:a.jsx("label",{htmlFor:"user_labels&"+t,children:a.jsxs("div",{className:o.listagem.content3,children:[a.jsx("div",{className:o.listagem.content4,children:a.jsx(_,{id:"user_labels&"+t,estado:s.active,checkedUpdade:()=>{C(!s.active,s.id)}})}),a.jsx("span",{className:o.listagem.content5,children:a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("div",{className:"pr-1",children:[a.jsx("span",{children:s.name}),a.jsx("span",{className:o.aba+"tam-aba ml-1 h-5 text-[var(--letra)]",style:{backgroundColor:"var(--primaria)"},children:s.count})]}),a.jsx("span",{children:a.jsx(k,{className:"w-6 h-6",style:{color:s.hexColor}})})]})})]})})})},t))});return m.length>0?N:y}export{G as default};
