import{r as u,j as a}from"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a71.js";import{A as E,z as A}from"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a7124.js";import{u as q,b as S}from"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a7120.js";import{a5 as I,aI as _}from"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a7111.js";import{W as h}from"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a7119.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a717.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a719.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a716.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a718.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a714.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a713.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a712.js";import"./v_7_4_2_28_54378c94-eda0-47d4-8f59-c666edac6a7110.js";function K({setUserLabels:c,userLabels:b}){const{variaveisWA:o}=E(),{language:x}=q(),{isBusiness:g}=S(),{user:j,_serialized:d}=A(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(I,{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(_,{className:"w-6 h-6",style:{color:s.hexColor}})})]})})]})})})},t))});return m.length>0?N:y}export{K as default};
