import{j as p}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{a as d}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e4.js";import{D as x,C as L,P as M}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e115.js";import{u as w,s as b}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e23.js";import{A as C}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e40.js";import{W as I}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e18.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e8.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e5.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e6.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e7.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e116.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e9.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e117.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e22.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e2.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e3.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e68.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e39.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e69.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e70.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e105.js";import"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e36.js";function g(r){const t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;r=r.replace(t,(a,n,l,i)=>n+n+l+l+i+i);const o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);return o?{r:parseInt(o[1],16),g:parseInt(o[2],16),b:parseInt(o[3],16)}:{r:0,g:0,b:0}}function h(r,t,o){return"#"+((1<<24)+(r<<16)+(t<<8)+o).toString(16).slice(1).toUpperCase()}function E(r,t){const{r:o,g:a,b:n}=g(r),l=Math.min(255,Math.floor(o+(255-o)*(t/100))),i=Math.min(255,Math.floor(a+(255-a)*(t/100))),u=Math.min(255,Math.floor(n+(255-n)*(t/100)));return h(l,i,u)}function O(r,t){const{r:o,g:a,b:n}=g(r),l=Math.max(0,Math.floor(o*(1-t/100))),i=Math.max(0,Math.floor(a*(1-t/100))),u=Math.max(0,Math.floor(n*(1-t/100)));return h(l,i,u)}function V(){const r=w(e=>e.orderLabels),[t,o]=d.useState([]),a=d.useCallback(async()=>{const e=await I.Labels("getAllLabels");o(e);const s=e.map(c=>c.id),f=[...r.filter(c=>s.includes(c)),...s.filter(c=>!r.includes(c))];JSON.stringify(f)!==JSON.stringify(r)&&b(f)},[t,r]);d.useEffect(()=>{a()},[]),d.useEffect(()=>{const e=setInterval(a,1e4);return()=>clearInterval(e)},[t]);const[n,l]=d.useState([]);d.useEffect(()=>{const e=[...t];e.sort((s,m)=>r.indexOf(s.id)-r.indexOf(m.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"&&a()},u=e=>{if(!e.destination)return;const s=Array.from(r),[m]=s.splice(e.source.index,1);s.splice(e.destination.index,0,m),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,m)=>p.jsx(M,{draggableId:s.id,index:m,children:(f,c)=>p.jsx("div",{ref:f.innerRef,...f.draggableProps,...f.dragHandleProps,children:p.jsx(C,{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{V as default};
