import{j as s,a8 as E,aL as A}from"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d610.js";import{a as u}from"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d64.js";import{A as q,z as S}from"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d623.js";import{u as _,b as k}from"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d619.js";import{W as h}from"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d618.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d68.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d6.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d65.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d67.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d66.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d69.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d62.js";import"./v_7_4_2_23_80f0be4c-2624-48ff-84de-a733d033e3d63.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.default_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};
