import{r as u,j as a}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a2777.js";import{al as E,w as q}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277723.js";import{u as A,g as S}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277720.js";import{a1 as _,aL as k}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277711.js";import{W as h}from"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277719.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27778.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27777.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27774.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27773.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27772.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a277710.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27776.js";import"./v_7_4_3_5_5680d44b-ceb1-449a-bec3-8cbef70a27779.js";function K({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]=u.useState([]),[L,v]=u.useState(g);u.useEffect(()=>{b&&(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(_,{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{K as default};
