import{j as p}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf10.js";import{a as d}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf4.js";import{D as x,C as L,P as M,A as w}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf119.js";import{u as C,s as b}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf24.js";import{W as I}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf18.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf8.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf5.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf19.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf7.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf120.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf9.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf121.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf23.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf6.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf2.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf3.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf122.js";import"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf41.js";function g(r){const t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;r=r.replace(t,(o,n,l,i)=>n+n+l+l+i+i);const a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);return a?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:{r:0,g:0,b:0}}function h(r,t,a){return"#"+((1<<24)+(r<<16)+(t<<8)+a).toString(16).slice(1).toUpperCase()}function E(r,t){const{r:a,g:o,b:n}=g(r),l=Math.min(255,Math.floor(a+(255-a)*(t/100))),i=Math.min(255,Math.floor(o+(255-o)*(t/100))),u=Math.min(255,Math.floor(n+(255-n)*(t/100)));return h(l,i,u)}function O(r,t){const{r:a,g:o,b:n}=g(r),l=Math.max(0,Math.floor(a*(1-t/100))),i=Math.max(0,Math.floor(o*(1-t/100))),u=Math.max(0,Math.floor(n*(1-t/100)));return h(l,i,u)}function _(){const r=C(e=>e.orderLabels),[t,a]=d.useState([]),o=d.useCallback(async()=>{const e=await I.Labels("getAllLabels");a(e);const s=e.map(c=>c.id),m=[...r.filter(c=>s.includes(c)),...s.filter(c=>!r.includes(c))];JSON.stringify(m)!==JSON.stringify(r)&&b(m)},[t,r]);d.useEffect(()=>{o()},[]),d.useEffect(()=>{const e=setInterval(o,1e4);return()=>clearInterval(e)},[t]);const[n,l]=d.useState([]);d.useEffect(()=>{const e=[...t];e.sort((s,f)=>r.indexOf(s.id)-r.indexOf(f.id)),l(e)},[t,r]),d.useEffect(()=>(window.addEventListener("message",i),()=>{window.removeEventListener("message",i)}),[t]);const i=async e=>{e.data.action==="chat.update_label"&&o()},u=e=>{if(!e.destination)return;const s=Array.from(r),[f]=s.splice(e.source.index,1);s.splice(e.destination.index,0,f),b(s)};return p.jsx(x,{onDragEnd:u,children:p.jsx(L,{droppableId:"userLabels",direction:"horizontal",children:e=>p.jsxs("div",{className:"flex items-center",...e.droppableProps,ref:e.innerRef,children:[n.map((s,f)=>p.jsx(M,{draggableId:s.id,index:f,children:(m,c)=>p.jsx("div",{ref:m.innerRef,...m.draggableProps,...m.dragHandleProps,children:p.jsx(w,{nome:s.name,tam:s.count,id:s.id,type:"Labels",isMove:c.isDragging,primaria:s.hexColor,secundaria:O(s.hexColor,50),terciaria:E(s.hexColor,50)})})},s.id)),e.placeholder]})})})}export{_ as default};
