import{j as a}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1165.js";import{r as p}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb116.js";import{ac as E,v as q}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11623.js";import{u as A,g as S}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1164.js";import{u as _,ax as k}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1167.js";import{W as h}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1162.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1163.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1169.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11610.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11620.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1168.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1166.js";function J({setUserLabels:c,userLabels:g}){const{variaveisWA:o}=E(),{language:x}=A(),{isBusiness:b}=S(),{user:j,_serialized:d}=q(s=>s.activeChat?.default_id),[m,f]=p.useState([]),[L,v]=p.useState(g);p.useEffect(()=>{b&&(async()=>{try{const t=await h.Labels("getAllLabels"),u=await h.Chat("get",d),n=u.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=u.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,u)=>{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{J as default};
