import{j as s,a7 as E,aL as A}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b710.js";import{a as u}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b74.js";import{A as q,z as S}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b723.js";import{u as k,b as z}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b719.js";import{W as h}from"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b718.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b78.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b7.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b75.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b77.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b76.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b79.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b72.js";import"./v_7_4_2_16_364f475f-21c1-4d89-bf17-70efc8c405b73.js";function K({setUserLabels:c,userLabels:b}){const{variaveisWA:r}=q(),{language:x}=k(),{isBusiness:g}=z(),{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 C=(t,e,p)=>{f(a=>{const i=[...a],o=i.findIndex(w=>w.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})},y=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(E,{id:"user_labels&"+e,estado:t.active,checkedUpdade:()=>{C(!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:y}export{K as default};
