import{j as s}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a53.js";import{a as u}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a52.js";import{ac as w,w as E}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a525.js";import{u as A}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a54.js";import{K as q,aG as S}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a58.js";import{z as h}from"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a55.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a56.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a59.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a510.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a57.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a5.js";import"./v_7_4_3_73_d3c9bac7-c74e-47f6-ac42-499f067843a520.js";function H({setUserLabels:c,userLabels:g}){const o=w(e=>e.variaveisWA),x=A(e=>e.language),{user:b,_serialized:d}=E(e=>e.activeChat?.default_id),[m,f]=u.useState([]),[j,v]=u.useState(g);u.useEffect(()=>{(async()=>{try{const t=await h.Labels("getAllLabels"),p=await h.Chat("get",d),n=p.labels.map(a=>t.find(i=>i.hexColor&&i.id===a)).filter(Boolean).map(({id:a,name:i,hexColor:r})=>({id:a,name:i,color:r,hexColor:r}));let l=[];t.forEach(a=>{const i=p.labels.find(r=>r===a.id);l.push({...a,active:!!i})}),c(n),f(l)}catch(t){console.error(x.erroAoBuscarLabels,t)}})()},[d]);const L=(e,t,p)=>{f(a=>{const i=[...a],r=i.findIndex(y=>y.id===t);return r!==-1&&(i[r]={...i[r],active:e}),i});const n=j.map(a=>({...a}));if(e){const a=m.find(i=>i.id===t);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!==t);v(a),c(a)}chrome.runtime.sendMessage({action:"update-card",userId:b});const l={labelId:t,type:e?"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:o.modalOptions.content3+"overflow-auto",style:{maxHeight:"calc(100vh - 200px)"},children:m.slice().sort((e,t)=>e.name.localeCompare(t.name)).map((e,t)=>s.jsx("div",{className:o.listagem.content1+"hoverShadown",children:s.jsx("li",{tabIndex:1,className:o.listagem.content2,"data-animate-dropdown-item":"true",style:{opacity:1},children:s.jsx("label",{htmlFor:"user_labels&"+t,children:s.jsxs("div",{className:o.listagem.content3,children:[s.jsx("div",{className:o.listagem.content4,children:s.jsx(q,{id:"user_labels&"+t,estado:e.active,checkedUpdade:()=>{L(!e.active,e.id)}})}),s.jsx("span",{className:o.listagem.content5,children:s.jsxs("div",{className:"flex gap-4",children:[s.jsxs("div",{className:"pr-1",children:[s.jsx("span",{children:e.name}),s.jsx("span",{className:o.aba+"tam-aba ml-1 h-5 text-[var(--letra)]",style:{backgroundColor:"var(--primaria)"},children:e.count})]}),s.jsx("span",{children:s.jsx(S,{className:"w-6 h-6",style:{color:e.hexColor}})})]})})]})})})},t))});return m.length>0?N:C}export{H as default};
