import{j as a}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0286.js";import{a as u}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0282.js";import{h as E}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02833.js";import{u as q,d as A}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0285.js";import{q as S}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02821.js";import{e as _,ax as k}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0288.js";import{W as h}from"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0283.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0284.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02838.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0289.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02810.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b028.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b02820.js";import"./v_7_4_3_48_026858c9-0735-4edd-ae06-f5f59030b0287.js";function Q({setUserLabels:c,userLabels:b}){const{variaveisWA:r}=E(),{language:x}=q(),{isBusiness:g}=A(),{user:j,_serialized:d}=S(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:o})=>({id:e,name:i,color:o,hexColor:o}));let l=[];t.forEach(e=>{const i=p.labels.find(o=>o===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],o=i.findIndex(w=>w.id===t);return o!==-1&&(i[o]={...i[o],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:r.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:r.listagem.content1+"hoverShadown",children:a.jsx("li",{tabIndex:1,className:r.listagem.content2,"data-animate-dropdown-item":"true",style:{opacity:1},children:a.jsx("label",{htmlFor:"user_labels&"+t,children:a.jsxs("div",{className:r.listagem.content3,children:[a.jsx("div",{className:r.listagem.content4,children:a.jsx(_,{id:"user_labels&"+t,estado:s.active,checkedUpdade:()=>{C(!s.active,s.id)}})}),a.jsx("span",{className:r.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:r.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{Q as default};
