import{j as s,a4 as w,aE as A}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf10.js";import{a as u}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf4.js";import{A as q,y as S}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf23.js";import{u as _,b as k}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf19.js";import{W as h}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf18.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf8.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf5.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf7.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf6.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf9.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf2.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf3.js";function K({setUserLabels:c,userLabels:b}){const{variaveisWA:r}=q(),{language:x}=_(),{isBusiness:g}=k(),{user:j,_serialized:d}=S(t=>{var e;return(e=t.activeChat)==null?void 0:e.id}),[m,f]=u.useState([]),[L,v]=u.useState(b);u.useEffect(()=>{g&&(async()=>{try{const e=await h.Labels("getAllLabels"),p=await h.Chat("get",d),n=p.labels.map(a=>e.find(i=>i.hexColor&&i.id===a)).filter(Boolean).map(({id:a,name:i,hexColor:o})=>({id:a,name:i,color:o,hexColor:o}));let l=[];e.forEach(a=>{const i=p.labels.find(o=>o===a.id);l.push({...a,active:!!i})}),c(n),f(l)}catch(e){console.error(x.erroAoBuscarLabels,e)}})()},[d]);const y=(t,e,p)=>{f(a=>{const i=[...a],o=i.findIndex(E=>E.id===e);return o!==-1&&(i[o]={...i[o],active:t}),i});const n=L.map(a=>({...a}));if(t){const a=m.find(i=>i.id===e);n.unshift({id:a.id,name:a.name,color:a.hexColor,hexColor:a.hexColor}),v(n),c(n)}else{const a=n.filter(i=>i.id!==e);v(a),c(a)}chrome.runtime.sendMessage({action:"update-card",userId:j});const l={labelId:e,type:t?"add":"remove"};h.Labels("addOrRemoveLabels",{id:d,label:l})},C=s.jsx("div",{className:"p-4",children:s.jsx("span",{children:x.crieEtiquetaParaInserirContatos})}),N=s.jsx("div",{className:r.modalOptions.content3+"overflow-auto",style:{maxHeight:"calc(100vh - 200px)"},children:m.slice().sort((t,e)=>t.name.localeCompare(e.name)).map((t,e)=>s.jsx("div",{className:r.listagem.content1+"hoverShadown",children:s.jsx("li",{tabIndex:1,className:r.listagem.content2,"data-animate-dropdown-item":"true",style:{opacity:1},children:s.jsx("label",{htmlFor:"user_labels&"+e,children:s.jsxs("div",{className:r.listagem.content3,children:[s.jsx("div",{className:r.listagem.content4,children:s.jsx(w,{id:"user_labels&"+e,estado:t.active,checkedUpdade:()=>{y(!t.active,t.id)}})}),s.jsx("span",{className:r.listagem.content5,children:s.jsxs("div",{className:"flex gap-4",children:[s.jsxs("div",{className:"pr-1",children:[s.jsx("span",{children:t.name}),s.jsx("span",{className:r.aba+"tam-aba ml-1 h-5 text-[var(--letra)]",style:{backgroundColor:"var(--primaria)"},children:t.count})]}),s.jsx("span",{children:s.jsx(A,{className:"w-6 h-6",style:{color:t.hexColor}})})]})})]})})})},e))});return m.length>0?N:C}export{K as default};
