diff --git a/README.md b/README.md
index 7974c0e5d..f91e4a03e 100644
--- a/README.md
+++ b/README.md
@@ -98,8 +98,18 @@ v∆v
-
-
Interactive 3D model preview
+
+
Queueing and scheduling
+
+
+
+
+
Cloud Profiles
+
+
+
+
+
Settings
## Requirements
diff --git a/backend/app/api/routes/websocket.py b/backend/app/api/routes/websocket.py
index f67e744b4..868f436f7 100644
--- a/backend/app/api/routes/websocket.py
+++ b/backend/app/api/routes/websocket.py
@@ -1,16 +1,19 @@
+import logging
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from backend.app.core.websocket import ws_manager
from backend.app.services.printer_manager import printer_manager, printer_state_to_dict
-
+logger = logging.getLogger(__name__)
router = APIRouter()
@router.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
"""WebSocket endpoint for real-time updates."""
+ logger.info("WebSocket client connecting...")
await ws_manager.connect(websocket)
+ logger.info("WebSocket client connected")
try:
# Send initial status of all printers
@@ -21,6 +24,7 @@ async def websocket_endpoint(websocket: WebSocket):
"printer_id": printer_id,
"data": printer_state_to_dict(state),
})
+ logger.info(f"Sent initial status for {len(statuses)} printers")
# Keep connection alive and handle incoming messages
while True:
@@ -43,6 +47,8 @@ async def websocket_endpoint(websocket: WebSocket):
})
except WebSocketDisconnect:
+ logger.info("WebSocket client disconnected normally")
await ws_manager.disconnect(websocket)
- except Exception:
+ except Exception as e:
+ logger.error(f"WebSocket error: {e}", exc_info=True)
await ws_manager.disconnect(websocket)
diff --git a/backend/app/main.py b/backend/app/main.py
index 5e273464a..f9565369a 100644
--- a/backend/app/main.py
+++ b/backend/app/main.py
@@ -81,8 +81,16 @@ def register_expected_print(printer_id: int, filename: str, archive_id: int):
)
+_last_status_broadcast: dict[int, str] = {}
+
async def on_printer_status_change(printer_id: int, state: PrinterState):
"""Handle printer status changes - broadcast via WebSocket."""
+ # Only broadcast if something meaningful changed (reduce WebSocket spam)
+ status_key = f"{state.connected}:{state.state}:{state.progress}:{state.layer_num}"
+ if _last_status_broadcast.get(printer_id) == status_key:
+ return # No change, skip broadcast
+ _last_status_broadcast[printer_id] = status_key
+
await ws_manager.send_printer_status(
printer_id,
printer_state_to_dict(state, printer_id),
diff --git a/frontend/src/hooks/useWebSocket.ts b/frontend/src/hooks/useWebSocket.ts
index 7f3bbce4a..003a6b3ec 100644
--- a/frontend/src/hooks/useWebSocket.ts
+++ b/frontend/src/hooks/useWebSocket.ts
@@ -23,18 +23,17 @@ export function useWebSocket() {
const ws = new WebSocket(wsUrl);
+ let pingInterval: number | null = null;
+
ws.onopen = () => {
+ console.log('[WebSocket] Connected');
setIsConnected(true);
// Start ping interval
- const pingInterval = setInterval(() => {
+ pingInterval = window.setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'ping' }));
}
}, 30000);
-
- ws.onclose = () => {
- clearInterval(pingInterval);
- };
};
ws.onmessage = (event) => {
@@ -46,7 +45,12 @@ export function useWebSocket() {
}
};
- ws.onclose = () => {
+ ws.onclose = (event) => {
+ console.log('[WebSocket] Closed', event.code, event.reason);
+ if (pingInterval) {
+ clearInterval(pingInterval);
+ pingInterval = null;
+ }
setIsConnected(false);
wsRef.current = null;
@@ -56,7 +60,8 @@ export function useWebSocket() {
}, 3000);
};
- ws.onerror = () => {
+ ws.onerror = (error) => {
+ console.error('[WebSocket] Error', error);
ws.close();
};
diff --git a/static/assets/index-C7e8XOql.js b/static/assets/index-BS0vyekL.js
similarity index 99%
rename from static/assets/index-C7e8XOql.js
rename to static/assets/index-BS0vyekL.js
index 73a196d6a..8a82b7a6c 100644
--- a/static/assets/index-C7e8XOql.js
+++ b/static/assets/index-BS0vyekL.js
@@ -8591,4 +8591,4 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Ag(t.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
- `},Fje={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function zje(t){let{announcements:e=Fje,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=Uje}=t;const{announce:a,announcement:s}=kje(),o=Vv("DndLiveRegion"),[l,c]=C.useState(!1);if(C.useEffect(()=>{c(!0)},[]),Lje(C.useMemo(()=>({onDragStart(f){let{active:p}=f;a(e.onDragStart({active:p}))},onDragMove(f){let{active:p,over:m}=f;e.onDragMove&&a(e.onDragMove({active:p,over:m}))},onDragOver(f){let{active:p,over:m}=f;a(e.onDragOver({active:p,over:m}))},onDragEnd(f){let{active:p,over:m}=f;a(e.onDragEnd({active:p,over:m}))},onDragCancel(f){let{active:p,over:m}=f;a(e.onDragCancel({active:p,over:m}))}}),[a,e])),!l)return null;const d=_i.createElement(_i.Fragment,null,_i.createElement(Dje,{id:i,value:r.draggable}),_i.createElement(Oje,{id:o,announcement:s}));return n?Bl.createPortal(d,n):d}var Ji;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(Ji||(Ji={}));function iS(){}function SV(t,e){return C.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Bje(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const vo=Object.freeze({x:0,y:0});function BZ(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function jZ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function jje(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function wV(t){let{left:e,top:n,height:i,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+i},{x:e+r,y:n+i}]}function HZ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function MV(t,e,n){return e===void 0&&(e=t.left),n===void 0&&(n=t.top),{x:e+t.width*.5,y:n+t.height*.5}}const Hje=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=MV(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=BZ(MV(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(jZ)},Vje=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=wV(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=wV(l),d=r.reduce((p,m,y)=>p+BZ(c[y],m),0),f=Number((d/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(jZ)};function Gje(t,e){const n=Math.max(e.top,t.top),i=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),a=Math.min(e.top+e.height,t.top+t.height),s=r-i,o=a-n;if(i{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=[];for(const a of i){const{id:s}=a,o=n.get(s);if(o){const l=Gje(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(jje)};function Wje(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function VZ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:vo}function qje(t){return function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),a=1;a({...s,top:s.top+t*o.y,bottom:s.bottom+t*o.y,left:s.left+t*o.x,right:s.right+t*o.x}),{...n})}}const Xje=qje(1);function Kje(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function Yje(t,e,n){const i=Kje(e);if(!i)return t;const{scaleX:r,scaleY:a,x:s,y:o}=i,l=t.left-s-(1-r)*parseFloat(n),c=t.top-o-(1-a)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const Zje={ignoreTransform:!1};function ym(t,e){e===void 0&&(e=Zje);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=za(t).getComputedStyle(t);c&&(n=Yje(n,c,d))}const{top:i,left:r,width:a,height:s,bottom:o,right:l}=n;return{top:i,left:r,width:a,height:s,bottom:o,right:l}}function EV(t){return ym(t,{ignoreTransform:!0})}function Qje(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function Jje(t,e){return e===void 0&&(e=za(t).getComputedStyle(t)),e.position==="fixed"}function e5e(t,e){e===void 0&&(e=za(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const a=e[r];return typeof a=="string"?n.test(a):!1})}function Nw(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(tk(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!jv(r)||UZ(r)||n.includes(r))return n;const a=za(t).getComputedStyle(r);return r!==t&&e5e(r,a)&&n.push(r),Jje(r,a)?n:i(r.parentNode)}return t?i(t):n}function GZ(t){const[e]=Nw(t,1);return e??null}function S2(t){return!Rw||!t?null:vm(t)?t:ek(t)?tk(t)||t===xm(t).scrollingElement?window:jv(t)?t:null:null}function $Z(t){return vm(t)?t.scrollX:t.scrollLeft}function WZ(t){return vm(t)?t.scrollY:t.scrollTop}function MN(t){return{x:$Z(t),y:WZ(t)}}var _r;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(_r||(_r={}));function qZ(t){return!Rw||!t?!1:t===document.scrollingElement}function XZ(t){const e={x:0,y:0},n=qZ(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,a=t.scrollLeft<=e.x,s=t.scrollTop>=i.y,o=t.scrollLeft>=i.x;return{isTop:r,isLeft:a,isBottom:s,isRight:o,maxScroll:i,minScroll:e}}const t5e={x:.2,y:.2};function n5e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=t5e);const{isTop:c,isBottom:d,isLeft:f,isRight:p}=XZ(t),m={x:0,y:0},y={x:0,y:0},b={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+b.height?(m.y=_r.Backward,y.y=i*Math.abs((e.top+b.height-a)/b.height)):!d&&l>=e.bottom-b.height&&(m.y=_r.Forward,y.y=i*Math.abs((e.bottom-b.height-l)/b.height)),!p&&o>=e.right-b.width?(m.x=_r.Forward,y.x=i*Math.abs((e.right-b.width-o)/b.width)):!f&&s<=e.left+b.width&&(m.x=_r.Backward,y.x=i*Math.abs((e.left+b.width-s)/b.width)),{direction:m,speed:y}}function i5e(t){if(t===document.scrollingElement){const{innerWidth:a,innerHeight:s}=window;return{top:0,left:0,right:a,bottom:s,width:a,height:s}}const{top:e,left:n,right:i,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:i,bottom:r,width:t.clientWidth,height:t.clientHeight}}function KZ(t){return t.reduce((e,n)=>_p(e,MN(n)),vo)}function r5e(t){return t.reduce((e,n)=>e+$Z(n),0)}function a5e(t){return t.reduce((e,n)=>e+WZ(n),0)}function s5e(t,e){if(e===void 0&&(e=ym),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);GZ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const o5e=[["x",["left","right"],r5e],["y",["top","bottom"],a5e]];class rk{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=Nw(n),r=KZ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of o5e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),d=r[a]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class c0{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...n)})},this.target=e}add(e,n,i){var r;(r=this.target)==null||r.addEventListener(e,n,i),this.listeners.push([e,n,i])}}function l5e(t){const{EventTarget:e}=za(t);return t instanceof e?t:xm(t)}function w2(t,e){const n=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+i**2)>e:"x"in e&&"y"in e?n>e.x&&i>e.y:"x"in e?n>e.x:"y"in e?i>e.y:!1}var Rs;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Rs||(Rs={}));function AV(t){t.preventDefault()}function c5e(t){t.stopPropagation()}var pn;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(pn||(pn={}));const YZ={start:[pn.Space,pn.Enter],cancel:[pn.Esc],end:[pn.Space,pn.Enter,pn.Tab]},u5e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case pn.Right:return{...n,x:n.x+25};case pn.Left:return{...n,x:n.x-25};case pn.Down:return{...n,y:n.y+25};case pn.Up:return{...n,y:n.y-25}}};class ak{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new c0(xm(n)),this.windowListeners=new c0(za(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Rs.Resize,this.handleCancel),this.windowListeners.add(Rs.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Rs.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&s5e(i),n(vo)}handleKeyDown(e){if(ik(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=YZ,coordinateGetter:s=u5e,scrollBehavior:o="smooth"}=r,{code:l}=e;if(a.end.includes(l)){this.handleEnd(e);return}if(a.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=i.current,d=c?{x:c.left,y:c.top}:vo;this.referenceCoordinates||(this.referenceCoordinates=d);const f=s(e,{active:n,context:i.current,currentCoordinates:d});if(f){const p=tv(f,d),m={x:0,y:0},{scrollableAncestors:y}=i.current;for(const b of y){const x=e.code,{isTop:g,isRight:M,isLeft:w,isBottom:E,maxScroll:A,minScroll:N}=XZ(b),R=i5e(b),F={x:Math.min(x===pn.Right?R.right-R.width/2:R.right,Math.max(x===pn.Right?R.left:R.left+R.width/2,f.x)),y:Math.min(x===pn.Down?R.bottom-R.height/2:R.bottom,Math.max(x===pn.Down?R.top:R.top+R.height/2,f.y))},P=x===pn.Right&&!M||x===pn.Left&&!w,O=x===pn.Down&&!E||x===pn.Up&&!g;if(P&&F.x!==f.x){const B=b.scrollLeft+p.x,U=x===pn.Right&&B<=A.x||x===pn.Left&&B>=N.x;if(U&&!p.y){b.scrollTo({left:B,behavior:o});return}U?m.x=b.scrollLeft-B:m.x=x===pn.Right?b.scrollLeft-A.x:b.scrollLeft-N.x,m.x&&b.scrollBy({left:-m.x,behavior:o});break}else if(O&&F.y!==f.y){const B=b.scrollTop+p.y,U=x===pn.Down&&B<=A.y||x===pn.Up&&B>=N.y;if(U&&!p.x){b.scrollTo({top:B,behavior:o});return}U?m.y=b.scrollTop-B:m.y=x===pn.Down?b.scrollTop-A.y:b.scrollTop-N.y,m.y&&b.scrollBy({top:-m.y,behavior:o});break}}this.handleMove(e,_p(tv(f,this.referenceCoordinates),m))}}}handleMove(e,n){const{onMove:i}=this.props;e.preventDefault(),i(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}ak.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=YZ,onActivation:r}=e,{active:a}=n;const{code:s}=t.nativeEvent;if(i.start.includes(s)){const o=a.activatorNode.current;return o&&t.target!==o?!1:(t.preventDefault(),r?.({event:t.nativeEvent}),!0)}return!1}}];function TV(t){return!!(t&&"distance"in t)}function CV(t){return!!(t&&"delay"in t)}class sk{constructor(e,n,i){var r;i===void 0&&(i=l5e(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:a}=e,{target:s}=a;this.props=e,this.events=n,this.document=xm(s),this.documentListeners=new c0(this.document),this.listeners=new c0(i),this.windowListeners=new c0(za(s)),this.initialCoordinates=(r=wN(a))!=null?r:vo,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Rs.Resize,this.handleCancel),this.windowListeners.add(Rs.DragStart,AV),this.windowListeners.add(Rs.VisibilityChange,this.handleCancel),this.windowListeners.add(Rs.ContextMenu,AV),this.documentListeners.add(Rs.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(CV(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(TV(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:i,onPending:r}=this.props;r(i,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Rs.Click,c5e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Rs.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:i,initialCoordinates:r,props:a}=this,{onMove:s,options:{activationConstraint:o}}=a;if(!r)return;const l=(n=wN(e))!=null?n:vo,c=tv(r,l);if(!i&&o){if(TV(o)){if(o.tolerance!=null&&w2(c,o.tolerance))return this.handleCancel();if(w2(c,o.distance))return this.handleStart()}if(CV(o)&&w2(c,o.tolerance))return this.handleCancel();this.handlePending(o,c);return}e.cancelable&&e.preventDefault(),s(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===pn.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const d5e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ok extends sk{constructor(e){const{event:n}=e,i=xm(n.target);super(e,d5e,i)}}ok.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return!n.isPrimary||n.button!==0?!1:(i?.({event:n}),!0)}}];const f5e={move:{name:"mousemove"},end:{name:"mouseup"}};var EN;(function(t){t[t.RightClick=2]="RightClick"})(EN||(EN={}));class h5e extends sk{constructor(e){super(e,f5e,xm(e.event.target))}}h5e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===EN.RightClick?!1:(i?.({event:n}),!0)}}];const M2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class p5e extends sk{constructor(e){super(e,M2)}static setup(){return window.addEventListener(M2.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(M2.move.name,e)};function e(){}}}p5e.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;const{touches:r}=n;return r.length>1?!1:(i?.({event:n}),!0)}}];var u0;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(u0||(u0={}));var rS;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(rS||(rS={}));function m5e(t){let{acceleration:e,activator:n=u0.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=rS.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:p}=t;const m=v5e({delta:f,disabled:!a}),[y,b]=Tje(),x=C.useRef({x:0,y:0}),g=C.useRef({x:0,y:0}),M=C.useMemo(()=>{switch(n){case u0.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case u0.DraggableRect:return r}},[n,r,l]),w=C.useRef(null),E=C.useCallback(()=>{const N=w.current;if(!N)return;const R=x.current.x*g.current.x,F=x.current.y*g.current.y;N.scrollBy(R,F)},[]),A=C.useMemo(()=>o===rS.TreeOrder?[...c].reverse():c,[o,c]);C.useEffect(()=>{if(!a||!c.length||!M){b();return}for(const N of A){if(i?.(N)===!1)continue;const R=c.indexOf(N),F=d[R];if(!F)continue;const{direction:P,speed:O}=n5e(N,F,M,e,p);for(const B of["x","y"])m[B][P[B]]||(O[B]=0,P[B]=0);if(O.x>0||O.y>0){b(),w.current=N,y(E,s),x.current=O,g.current=P;return}}x.current={x:0,y:0},g.current={x:0,y:0},b()},[e,E,i,b,a,s,JSON.stringify(M),JSON.stringify(m),y,c,A,d,JSON.stringify(p)])}const g5e={x:{[_r.Backward]:!1,[_r.Forward]:!1},y:{[_r.Backward]:!1,[_r.Forward]:!1}};function v5e(t){let{delta:e,disabled:n}=t;const i=SN(e);return Hv(r=>{if(n||!i||!r)return g5e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[_r.Backward]:r.x[_r.Backward]||a.x===-1,[_r.Forward]:r.x[_r.Forward]||a.x===1},y:{[_r.Backward]:r.y[_r.Backward]||a.y===-1,[_r.Forward]:r.y[_r.Forward]||a.y===1}}},[n,e,i])}function x5e(t,e){const n=e!=null?t.get(e):void 0,i=n?n.node.current:null;return Hv(r=>{var a;return e==null?null:(a=i??r)!=null?a:null},[i,e])}function y5e(t,e){return C.useMemo(()=>t.reduce((n,i)=>{const{sensor:r}=i,a=r.activators.map(s=>({eventName:s.eventName,handler:e(s.handler,i)}));return[...n,...a]},[]),[t,e])}var iv;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(iv||(iv={}));var AN;(function(t){t.Optimized="optimized"})(AN||(AN={}));const RV=new Map;function b5e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=C.useState(null),{frequency:o,measure:l,strategy:c}=r,d=C.useRef(t),f=x(),p=ev(f),m=C.useCallback(function(g){g===void 0&&(g=[]),!p.current&&s(M=>M===null?g:M.concat(g.filter(w=>!M.includes(w))))},[p]),y=C.useRef(null),b=Hv(g=>{if(f&&!n)return RV;if(!g||g===RV||d.current!==t||a!=null){const M=new Map;for(let w of t){if(!w)continue;if(a&&a.length>0&&!a.includes(w.id)&&w.rect.current){M.set(w.id,w.rect.current);continue}const E=w.node.current,A=E?new rk(l(E),E):null;w.rect.current=A,A&&M.set(w.id,A)}return M}return g},[t,a,n,f,l]);return C.useEffect(()=>{d.current=t},[t]),C.useEffect(()=>{f||m()},[n,f]),C.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),C.useEffect(()=>{f||typeof o!="number"||y.current!==null||(y.current=setTimeout(()=>{m(),y.current=null},o))},[o,f,m,...i]),{droppableRects:b,measureDroppableContainers:m,measuringScheduled:a!=null};function x(){switch(c){case iv.Always:return!1;case iv.BeforeDragging:return n;default:return!n}}}function ZZ(t,e){return Hv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function _5e(t,e){return ZZ(t,e)}function S5e(t){let{callback:e,disabled:n}=t;const i=nk(e),r=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return C.useEffect(()=>()=>r?.disconnect(),[r]),r}function Pw(t){let{callback:e,disabled:n}=t;const i=nk(e),r=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return C.useEffect(()=>()=>r?.disconnect(),[r]),r}function w5e(t){return new rk(ym(t),t)}function NV(t,e,n){e===void 0&&(e=w5e);const[i,r]=C.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const s=S5e({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=Pw({callback:a});return Ko(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function M5e(t){const e=ZZ(t);return VZ(t,e)}const PV=[];function E5e(t){const e=C.useRef(t),n=Hv(i=>t?i&&i!==PV&&t&&e.current&&t.parentNode===e.current.parentNode?i:Nw(t):PV,[t]);return C.useEffect(()=>{e.current=t},[t]),n}function A5e(t){const[e,n]=C.useState(null),i=C.useRef(t),r=C.useCallback(a=>{const s=S2(a.target);s&&n(o=>o?(o.set(s,MN(s)),new Map(o)):null)},[]);return C.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=S2(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,MN(c)]):null}).filter(l=>l!=null);n(o.length?new Map(o):null),i.current=t}return()=>{s(t),s(a)};function s(o){o.forEach(l=>{const c=S2(l);c?.removeEventListener("scroll",r)})}},[r,t]),C.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>_p(a,s),vo):KZ(t):vo,[t,e])}function DV(t,e){e===void 0&&(e=[]);const n=C.useRef(null);return C.useEffect(()=>{n.current=null},e),C.useEffect(()=>{const i=t!==vo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?tv(t,n.current):vo}function T5e(t){C.useEffect(()=>{if(!Rw)return;const e=t.map(n=>{let{sensor:i}=n;return i.setup==null?void 0:i.setup()});return()=>{for(const n of e)n?.()}},t.map(e=>{let{sensor:n}=e;return n}))}function C5e(t,e){return C.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function QZ(t){return C.useMemo(()=>t?Qje(t):null,[t])}const OV=[];function R5e(t,e){e===void 0&&(e=ym);const[n]=t,i=QZ(n?za(n):null),[r,a]=C.useState(OV);function s(){a(()=>t.length?t.map(l=>qZ(l)?i:new rk(e(l),l)):OV)}const o=Pw({callback:s});return Ko(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function N5e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return jv(e)?e:t}function P5e(t){let{measure:e}=t;const[n,i]=C.useState(null),r=C.useCallback(c=>{for(const{target:d}of c)if(jv(d)){i(f=>{const p=e(d);return f?{...f,width:p.width,height:p.height}:p});break}},[e]),a=Pw({callback:r}),s=C.useCallback(c=>{const d=N5e(c);a?.disconnect(),d&&a?.observe(d),i(d?e(d):null)},[e,a]),[o,l]=nS(s);return C.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const D5e=[{sensor:ok,options:{}},{sensor:ak,options:{}}],O5e={current:{}},e_={draggable:{measure:EV},droppable:{measure:EV,strategy:iv.WhileDragging,frequency:AN.Optimized},dragOverlay:{measure:ym}};class d0 extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,i;return(n=(i=this.get(e))==null?void 0:i.node.current)!=null?n:void 0}}const k5e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new d0,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:iS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:e_,measureDroppableContainers:iS,windowRect:null,measuringScheduled:!1},L5e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:iS,draggableNodes:new Map,over:null,measureDroppableContainers:iS},Dw=C.createContext(L5e),JZ=C.createContext(k5e);function I5e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new d0}}}function U5e(t,e){switch(e.type){case Ji.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case Ji.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case Ji.DragEnd:case Ji.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Ji.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new d0(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case Ji.SetDroppableDisabled:{const{id:n,key:i,disabled:r}=e,a=t.droppable.containers.get(n);if(!a||i!==a.key)return t;const s=new d0(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case Ji.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new d0(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function F5e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=C.useContext(Dw),a=SN(i),s=SN(n?.id);return C.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!ik(a)||document.activeElement===a.target)return;const o=r.get(s);if(!o)return;const{activatorNode:l,node:c}=o;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=Nje(d);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function z5e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function B5e(t){return C.useMemo(()=>({draggable:{...e_.draggable,...t?.draggable},droppable:{...e_.droppable,...t?.droppable},dragOverlay:{...e_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function j5e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=C.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;Ko(()=>{if(!s&&!o||!e){a.current=!1;return}if(a.current||!i)return;const c=e?.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=VZ(d,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=GZ(c);p&&p.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const eQ=C.createContext({...vo,scaleX:1,scaleY:1});var hu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(hu||(hu={}));const H5e=C.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:d=D5e,collisionDetection:f=$je,measuring:p,modifiers:m,...y}=e;const b=C.useReducer(U5e,void 0,I5e),[x,g]=b,[M,w]=Ije(),[E,A]=C.useState(hu.Uninitialized),N=E===hu.Initialized,{draggable:{active:R,nodes:F,translate:P},droppable:{containers:O}}=x,B=R!=null?F.get(R):null,U=C.useRef({initial:null,translated:null}),q=C.useMemo(()=>{var ke;return R!=null?{id:R,data:(ke=B?.data)!=null?ke:O5e,rect:U}:null},[R,B]),L=C.useRef(null),[W,G]=C.useState(null),[$,Y]=C.useState(null),J=ev(y,Object.values(y)),se=Vv("DndDescribedBy",s),H=C.useMemo(()=>O.getEnabled(),[O]),K=B5e(p),{droppableRects:re,measureDroppableContainers:ce,measuringScheduled:xe}=b5e(H,{dragging:N,dependencies:[P.x,P.y],config:K.droppable}),me=x5e(F,R),ye=C.useMemo(()=>$?wN($):null,[$]),De=de(),he=_5e(me,K.draggable.measure);j5e({activeNode:R!=null?F.get(R):null,config:De.layoutShiftCompensation,initialRect:he,measure:K.draggable.measure});const we=NV(me,K.draggable.measure,he),Be=NV(me?me.parentElement:null),le=C.useRef({activatorEvent:null,active:null,activeNode:me,collisionRect:null,collisions:null,droppableRects:re,draggableNodes:F,draggingNode:null,draggingNodeRect:null,droppableContainers:O,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ut=O.getNodeFor((n=le.current.over)==null?void 0:n.id),z=P5e({measure:K.dragOverlay.measure}),V=(i=z.nodeRef.current)!=null?i:me,ie=N?(r=z.rect)!=null?r:we:null,Q=!!(z.nodeRef.current&&z.rect),ee=M5e(Q?null:we),ae=QZ(V?za(V):null),Pe=E5e(N?ut??me:null),Re=R5e(Pe),te=z5e(m,{transform:{x:P.x-ee.x,y:P.y-ee.y,scaleX:1,scaleY:1},activatorEvent:$,active:q,activeNodeRect:we,containerNodeRect:Be,draggingNodeRect:ie,over:le.current.over,overlayNodeRect:z.rect,scrollableAncestors:Pe,scrollableAncestorRects:Re,windowRect:ae}),I=ye?_p(ye,P):null,k=A5e(Pe),X=DV(k),pe=DV(k,[we]),ve=_p(te,X),fe=ie?Xje(ie,te):null,Ye=q&&fe?f({active:q,collisionRect:fe,droppableRects:re,droppableContainers:H,pointerCoordinates:I}):null,Le=HZ(Ye,"id"),[qe,it]=C.useState(null),Ie=Q?te:_p(te,pe),Ne=Wje(Ie,(a=qe?.rect)!=null?a:null,we),dt=C.useRef(null),et=C.useCallback((ke,Me)=>{let{sensor:ge,options:je}=Me;if(L.current==null)return;const at=F.get(L.current);if(!at)return;const yt=ke.nativeEvent,Ct=new ge({active:L.current,activeNode:at,event:yt,options:je,context:le,onAbort(Pt){if(!F.get(Pt))return;const{onDragAbort:jn}=J.current,dr={id:Pt};jn?.(dr),M({type:"onDragAbort",event:dr})},onPending(Pt,En,jn,dr){if(!F.get(Pt))return;const{onDragPending:fr}=J.current,Tr={id:Pt,constraint:En,initialCoordinates:jn,offset:dr};fr?.(Tr),M({type:"onDragPending",event:Tr})},onStart(Pt){const En=L.current;if(En==null)return;const jn=F.get(En);if(!jn)return;const{onDragStart:dr}=J.current,Xi={activatorEvent:yt,active:{id:En,data:jn.data,rect:U}};Bl.unstable_batchedUpdates(()=>{dr?.(Xi),A(hu.Initializing),g({type:Ji.DragStart,initialCoordinates:Pt,active:En}),M({type:"onDragStart",event:Xi}),G(dt.current),Y(yt)})},onMove(Pt){g({type:Ji.DragMove,coordinates:Pt})},onEnd:tn(Ji.DragEnd),onCancel:tn(Ji.DragCancel)});dt.current=Ct;function tn(Pt){return async function(){const{active:jn,collisions:dr,over:Xi,scrollAdjustedTranslate:fr}=le.current;let Tr=null;if(jn&&fr){const{cancelDrop:Vr}=J.current;Tr={activatorEvent:yt,active:jn,collisions:dr,delta:fr,over:Xi},Pt===Ji.DragEnd&&typeof Vr=="function"&&await Promise.resolve(Vr(Tr))&&(Pt=Ji.DragCancel)}L.current=null,Bl.unstable_batchedUpdates(()=>{g({type:Pt}),A(hu.Uninitialized),it(null),G(null),Y(null),dt.current=null;const Vr=Pt===Ji.DragEnd?"onDragEnd":"onDragCancel";if(Tr){const Di=J.current[Vr];Di?.(Tr),M({type:Vr,event:Tr})}})}}},[F]),Je=C.useCallback((ke,Me)=>(ge,je)=>{const at=ge.nativeEvent,yt=F.get(je);if(L.current!==null||!yt||at.dndKit||at.defaultPrevented)return;const Ct={active:yt};ke(ge,Me.options,Ct)===!0&&(at.dndKit={capturedBy:Me.sensor},L.current=je,et(ge,Me))},[F,et]),st=y5e(d,Je);T5e(d),Ko(()=>{we&&E===hu.Initializing&&A(hu.Initialized)},[we,E]),C.useEffect(()=>{const{onDragMove:ke}=J.current,{active:Me,activatorEvent:ge,collisions:je,over:at}=le.current;if(!Me||!ge)return;const yt={active:Me,activatorEvent:ge,collisions:je,delta:{x:ve.x,y:ve.y},over:at};Bl.unstable_batchedUpdates(()=>{ke?.(yt),M({type:"onDragMove",event:yt})})},[ve.x,ve.y]),C.useEffect(()=>{const{active:ke,activatorEvent:Me,collisions:ge,droppableContainers:je,scrollAdjustedTranslate:at}=le.current;if(!ke||L.current==null||!Me||!at)return;const{onDragOver:yt}=J.current,Ct=je.get(Le),tn=Ct&&Ct.rect.current?{id:Ct.id,rect:Ct.rect.current,data:Ct.data,disabled:Ct.disabled}:null,Pt={active:ke,activatorEvent:Me,collisions:ge,delta:{x:at.x,y:at.y},over:tn};Bl.unstable_batchedUpdates(()=>{it(tn),yt?.(Pt),M({type:"onDragOver",event:Pt})})},[Le]),Ko(()=>{le.current={activatorEvent:$,active:q,activeNode:me,collisionRect:fe,collisions:Ye,droppableRects:re,draggableNodes:F,draggingNode:V,draggingNodeRect:ie,droppableContainers:O,over:qe,scrollableAncestors:Pe,scrollAdjustedTranslate:ve},U.current={initial:ie,translated:fe}},[q,me,Ye,fe,F,V,ie,re,O,qe,Pe,ve]),m5e({...De,delta:P,draggingRect:fe,pointerCoordinates:I,scrollableAncestors:Pe,scrollableAncestorRects:Re});const ue=C.useMemo(()=>({active:q,activeNode:me,activeNodeRect:we,activatorEvent:$,collisions:Ye,containerNodeRect:Be,dragOverlay:z,draggableNodes:F,droppableContainers:O,droppableRects:re,over:qe,measureDroppableContainers:ce,scrollableAncestors:Pe,scrollableAncestorRects:Re,measuringConfiguration:K,measuringScheduled:xe,windowRect:ae}),[q,me,we,$,Ye,Be,z,F,O,re,qe,ce,Pe,Re,K,xe,ae]),tt=C.useMemo(()=>({activatorEvent:$,activators:st,active:q,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:g,draggableNodes:F,over:qe,measureDroppableContainers:ce}),[$,st,q,we,g,se,F,qe,ce]);return _i.createElement(zZ.Provider,{value:w},_i.createElement(Dw.Provider,{value:tt},_i.createElement(JZ.Provider,{value:ue},_i.createElement(eQ.Provider,{value:Ne},c)),_i.createElement(F5e,{disabled:o?.restoreFocus===!1})),_i.createElement(zje,{...o,hiddenTextDescribedById:se}));function de(){const ke=W?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=N&&!ke&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),V5e=C.createContext(null),kV="button",G5e="Draggable";function $5e(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=Vv(G5e),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:p}=C.useContext(Dw),{role:m=kV,roleDescription:y="draggable",tabIndex:b=0}=r??{},x=l?.id===e,g=C.useContext(x?eQ:V5e),[M,w]=nS(),[E,A]=nS(),N=C5e(s,e),R=ev(n);Ko(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:E,data:R}),()=>{const P=f.get(e);P&&P.key===a&&f.delete(e)}),[f,e]);const F=C.useMemo(()=>({role:m,tabIndex:b,"aria-disabled":i,"aria-pressed":x&&m===kV?!0:void 0,"aria-roledescription":y,"aria-describedby":d.draggable}),[i,m,b,x,y,d.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:F,isDragging:x,listeners:i?void 0:N,node:M,over:p,setNodeRef:w,setActivatorNodeRef:A,transform:g}}function W5e(){return C.useContext(JZ)}const q5e="Droppable",X5e={timeout:25};function K5e(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=Vv(q5e),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=C.useContext(Dw),d=C.useRef({disabled:n}),f=C.useRef(!1),p=C.useRef(null),m=C.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:x}={...X5e,...r},g=ev(b??i),M=C.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{c(Array.isArray(g.current)?g.current:[g.current]),m.current=null},x)},[x]),w=Pw({callback:M,disabled:y||!s}),E=C.useCallback((F,P)=>{w&&(P&&(w.unobserve(P),f.current=!1),F&&w.observe(F))},[w]),[A,N]=nS(E),R=ev(e);return C.useEffect(()=>{!w||!A.current||(w.disconnect(),f.current=!1,w.observe(A.current))},[A,w]),C.useEffect(()=>(o({type:Ji.RegisterDroppable,element:{id:i,key:a,disabled:n,node:A,rect:p,data:R}}),()=>o({type:Ji.UnregisterDroppable,key:a,id:i})),[i]),C.useEffect(()=>{n!==d.current.disabled&&(o({type:Ji.SetDroppableDisabled,id:i,key:a,disabled:n}),d.current.disabled=n)},[i,a,n,o]),{active:s,rect:p,isOver:l?.id===i,node:A,over:l,setNodeRef:N}}function lk(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function Y5e(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function Pb(t){return t!==null&&t>=0}function Z5e(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n{let{rects:e,activeIndex:n,overIndex:i,index:r}=t;const a=lk(e,i,n),s=e[r],o=a[r];return!o||!s?null:{x:o.left-s.left,y:o.top-s.top,scaleX:o.width/s.width,scaleY:o.height/s.height}},tQ="Sortable",nQ=_i.createContext({activeIndex:-1,containerId:tQ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:ck,disabled:{draggable:!1,droppable:!1}});function J5e(t){let{children:e,id:n,items:i,strategy:r=ck,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:d}=W5e(),f=Vv(tQ,n),p=o.rect!==null,m=C.useMemo(()=>i.map(N=>typeof N=="object"&&"id"in N?N.id:N),[i]),y=s!=null,b=s?m.indexOf(s.id):-1,x=c?m.indexOf(c.id):-1,g=C.useRef(m),M=!Z5e(m,g.current),w=x!==-1&&b===-1||M,E=Q5e(a);Ko(()=>{M&&y&&d(m)},[M,m,y,d]),C.useEffect(()=>{g.current=m},[m]);const A=C.useMemo(()=>({activeIndex:b,containerId:f,disabled:E,disableTransforms:w,items:m,overIndex:x,useDragOverlay:p,sortedRects:Y5e(m,l),strategy:r}),[b,f,E.draggable,E.droppable,w,m,x,l,p,r]);return _i.createElement(nQ.Provider,{value:A},e)}const eHe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return lk(n,i,r).indexOf(e)},tHe=t=>{let{containerId:e,isSorting:n,wasDragging:i,index:r,items:a,newIndex:s,previousItems:o,previousContainerId:l,transition:c}=t;return!c||!i||o!==a&&r===s?!1:n?!0:s!==r&&e===l},nHe={duration:200,easing:"ease"},iQ="transform",iHe=nv.Transition.toString({property:iQ,duration:0,easing:"linear"}),rHe={roleDescription:"sortable"};function aHe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=C.useState(null),o=C.useRef(n);return Ko(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=ym(i.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&s(d)}}n!==o.current&&(o.current=n)},[e,n,i,r]),C.useEffect(()=>{a&&s(null)},[a]),a}function sHe(t){let{animateLayoutChanges:e=tHe,attributes:n,disabled:i,data:r,getNewIndex:a=eHe,id:s,strategy:o,resizeObserverConfig:l,transition:c=nHe}=t;const{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:y,sortedRects:b,overIndex:x,useDragOverlay:g,strategy:M}=C.useContext(nQ),w=oHe(i,m),E=d.indexOf(s),A=C.useMemo(()=>({sortable:{containerId:f,index:E,items:d},...r}),[f,r,E,d]),N=C.useMemo(()=>d.slice(d.indexOf(s)),[d,s]),{rect:R,node:F,isOver:P,setNodeRef:O}=K5e({id:s,data:A,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:N,...l}}),{active:B,activatorEvent:U,activeNodeRect:q,attributes:L,setNodeRef:W,listeners:G,isDragging:$,over:Y,setActivatorNodeRef:J,transform:se}=$5e({id:s,data:A,attributes:{...rHe,...n},disabled:w.draggable}),H=Aje(O,W),K=!!B,re=K&&!y&&Pb(p)&&Pb(x),ce=!g&&$,xe=ce&&re?se:null,ye=re?xe??(o??M)({rects:b,activeNodeRect:q,activeIndex:p,overIndex:x,index:E}):null,De=Pb(p)&&Pb(x)?a({id:s,items:d,activeIndex:p,overIndex:x}):E,he=B?.id,we=C.useRef({activeId:he,items:d,newIndex:De,containerId:f}),Be=d!==we.current.items,le=e({active:B,containerId:f,isDragging:$,isSorting:K,id:s,index:E,items:d,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ut=aHe({disabled:!le,index:E,node:F,rect:R});return C.useEffect(()=>{K&&we.current.newIndex!==De&&(we.current.newIndex=De),f!==we.current.containerId&&(we.current.containerId=f),d!==we.current.items&&(we.current.items=d)},[K,De,f,d]),C.useEffect(()=>{if(he===we.current.activeId)return;if(he!=null&&we.current.activeId==null){we.current.activeId=he;return}const V=setTimeout(()=>{we.current.activeId=he},50);return()=>clearTimeout(V)},[he]),{active:B,activeIndex:p,attributes:L,data:A,rect:R,index:E,newIndex:De,items:d,isOver:P,isSorting:K,isDragging:$,listeners:G,node:F,overIndex:x,over:Y,setNodeRef:H,setActivatorNodeRef:J,setDroppableNodeRef:O,setDraggableNodeRef:W,transform:ut??ye,transition:z()};function z(){if(ut||Be&&we.current.newIndex===E)return iHe;if(!(ce&&!ik(U)||!c)&&(K||le))return nv.Transition.toString({...c,property:iQ})}}function oHe(t,e){var n,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t?.draggable)!=null?n:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function aS(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const lHe=[pn.Down,pn.Right,pn.Up,pn.Left],cHe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(lHe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=r.get(f.id);if(p)switch(t.code){case pn.Down:i.topp.top&&l.push(f);break;case pn.Left:i.left>p.left&&l.push(f);break;case pn.Right:i.left1&&(d=c[1].id),d!=null){const f=a.get(n.id),p=a.get(d),m=p?r.get(p.id):null,y=p?.node.current;if(y&&m&&f&&p){const x=Nw(y).some((N,R)=>o[R]!==N),g=rQ(f,p),M=uHe(f,p),w=x||!g?{x:0,y:0}:{x:M?i.width-m.width:0,y:M?i.height-m.height:0},E={x:m.left,y:m.top};return w.x&&w.y?E:tv(E,w)}}}};function rQ(t,e){return!aS(t)||!aS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function uHe(t,e){return!aS(t)||!aS(e)||!rQ(t,e)?!1:t.data.current.sortable.index{const x={};return t.forEach(g=>{x[g.id]=g.defaultSize||4}),x},[r,a]=C.useState(()=>{const x=localStorage.getItem(e);if(x)try{const g=JSON.parse(x);return g.sizes||(g.sizes=i()),g}catch{}return{order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()}}),[s,o]=C.useState(!1);C.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),C.useEffect(()=>{const g=t.map(M=>M.id).filter(M=>!r.order.includes(M));g.length>0&&a(M=>({...M,order:[...M.order,...g]}))},[t,r.order]);const l=Bje(SV(ok,{activationConstraint:{distance:8}}),SV(ak,{coordinateGetter:cHe})),c=x=>{const{active:g,over:M}=x;M&&g.id!==M.id&&a(w=>{const E=w.order.indexOf(g.id),A=w.order.indexOf(M.id);return{...w,order:lk(w.order,E,A)}})},d=x=>{a(g=>({...g,hidden:g.hidden.includes(x)?g.hidden.filter(M=>M!==x):[...g.hidden,x]}))},f=x=>{a(g=>{const M=g.sizes[x]||4,w=M===1?2:M===2?4:1;return{...g,sizes:{...g.sizes,[x]:w}}})},p=()=>{const x={order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()};a(x)},m=r.order.map(x=>t.find(g=>g.id===x)).filter(Boolean),y=m.filter(x=>!r.hidden.includes(x.id)),b=m.filter(x=>r.hidden.includes(x.id));return _.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&_.jsxs(vt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[_.jsx(y4,{className:"w-4 h-4"}),b.length," Hidden"]}),_.jsxs(vt,{variant:"secondary",size:"sm",onClick:p,children:[_.jsx(yG,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&b.length>0&&_.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(x=>_.jsxs("button",{onClick:()=>d(x.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[_.jsx(y4,{className:"w-3 h-3"}),x.title]},x.id))})]}),_.jsx(H5e,{sensors:l,collisionDetection:Hje,onDragEnd:c,children:_.jsx(J5e,{items:y.map(x=>x.id),strategy:ck,children:_.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(x=>_.jsx(dHe,{id:x.id,title:x.title,isHidden:r.hidden.includes(x.id),size:r.sizes[x.id]||2,onToggleVisibility:()=>d(x.id),onToggleSize:()=>f(x.id),children:x.component},x.id))})})}),y.length===0&&_.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[_.jsx("p",{children:"All widgets are hidden."}),_.jsx(vt,{className:"mt-4",onClick:p,children:"Reset Layout"})]})]})}function hHe({stats:t,currency:e}){return _.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:_.jsx(r_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),_.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:_.jsx(Qo,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:_.jsx(r_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:_.jsx(x4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:_.jsx(wG,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:_.jsx(x4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function pHe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),_.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:_.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Qp,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(IN,{className:"w-4 h-4 text-red-400"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function mHe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return _.jsx("div",{className:"flex items-center justify-center h-full",children:_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const r=(Math.min(150,Math.max(50,n))-50)/100*100,s=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),_.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[_.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),_.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),_.jsxs("div",{className:"space-y-2 flex-1",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[_.jsx(Gre,{className:"w-3 h-3"}),_.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&_.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>_.jsxs("div",{className:"flex items-center justify-between text-xs",children:[_.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),_.jsxs("span",{className:`font-medium ${c>=95&&c<=105?"text-bambu-green":c>105?"text-blue-400":"text-orange-400"}`,children:[c.toFixed(0),"%"]})]},l))})]})]})}function gHe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return _.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,i])=>i-n);return _.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[_.jsx("span",{className:"text-white",children:n}),_.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),_.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:_.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function vHe({printDates:t}){return _.jsx(xEe,{printDates:t,months:4})}function xHe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>_.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[_.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:_.jsx(Lu,{className:"w-4 h-4 text-bambu-green"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),_.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function yHe({archives:t,currency:e}){return!t||t.length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):_.jsx(Eje,{archives:t,currency:e})}function bHe(){const{data:t,isLoading:e}=bn({queryKey:["archiveStats"],queryFn:pt.getArchiveStats}),{data:n}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),{data:i}=bn({queryKey:["archives"],queryFn:()=>pt.getArchives(void 0,1e3,0)}),{data:r}=bn({queryKey:["settings"],queryFn:pt.getSettings}),a=r?.currency||"$",s=new Map(n?.map(c=>[String(c.id),c.name])||[]),o=i?.map(c=>c.created_at)||[];if(e)return _.jsx("div",{className:"p-8",children:_.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:_.jsx(hHe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:_.jsx(pHe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:_.jsx(mHe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:_.jsx(gHe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:_.jsx(vHe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:_.jsx(xHe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:_.jsx(yHe,{archives:i||[],currency:a}),defaultSize:4}];return _.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),_.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),_.jsx(fHe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function _He({plug:t,onEdit:e}){const n=ar(),[i,r]=C.useState(!1),[a,s]=C.useState(!1),[o,l]=C.useState(!1),[c,d]=C.useState(!1),{data:f,isLoading:p,refetch:m}=bn({queryKey:["smart-plug-status",t.id],queryFn:()=>pt.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:y}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),b=y?.find(N=>N.id===t.printer_id),x=gn({mutationFn:N=>pt.controlSmartPlug(t.id,N),onSuccess:()=>{m()}}),g=gn({mutationFn:N=>pt.updateSmartPlug(t.id,N),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),M=gn({mutationFn:()=>pt.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",E=f?.reachable??!1,A=x.isPending;return _.jsxs(_.Fragment,{children:[_.jsx(ai,{className:"relative",children:_.jsxs(Si,{className:"p-4",children:[_.jsxs("div",{className:"flex items-start justify-between mb-3",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx("div",{className:`p-2 rounded-lg ${E?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:_.jsx(U2,{className:`w-5 h-5 ${E?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),_.jsxs("div",{children:[_.jsx("h3",{className:"font-medium text-white",children:t.name}),_.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),_.jsx("div",{className:"flex items-center gap-2",children:p?_.jsx(di,{className:"w-4 h-4 text-bambu-gray animate-spin"}):E?_.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[_.jsx(zN,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):_.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[_.jsx(FN,{className:"w-4 h-4"}),_.jsx("span",{children:"Offline"})]})})]}),b&&_.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[_.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),_.jsx("span",{className:"text-sm text-white",children:b.name})]}),_.jsxs("div",{className:"flex gap-2 mb-3",children:[_.jsxs(vt,{size:"sm",variant:w?"primary":"secondary",disabled:!E||A,onClick:()=>s(!0),className:"flex-1",children:[A?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(dS,{className:"w-4 h-4"}),"On"]}),_.jsxs(vt,{size:"sm",variant:w?"secondary":"primary",disabled:!E||A,onClick:()=>l(!0),className:"flex-1",children:[A?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(xG,{className:"w-4 h-4"}),"Off"]})]}),_.jsxs("button",{onClick:()=>d(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[_.jsxs("span",{className:"flex items-center gap-2",children:[_.jsx(_G,{className:"w-4 h-4"}),"Automation Settings"]}),_.jsx("span",{children:c?"-":"+"})]}),c&&_.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Enabled"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.enabled,onChange:N=>g.mutate({enabled:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto On"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:N=>g.mutate({auto_on:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:N=>g.mutate({auto_off:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&_.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Qo,{className:"w-4 h-4"}),"Time"]}),_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(kb,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),_.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:N=>g.mutate({off_delay_minutes:parseInt(N.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),_.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:N=>g.mutate({off_temp_threshold:parseInt(N.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-2",children:[_.jsxs(vt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[_.jsx(pre,{className:"w-4 h-4"}),"Edit"]}),_.jsx(vt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:_.jsx(jo,{className:"w-4 h-4"})})]})]})]})}),i&&_.jsx(ns,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),r(!1)},onCancel:()=>r(!1)}),a&&_.jsx(ns,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&_.jsx(ns,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function SHe({plug:t,onClose:e}){const n=ar(),i=!!t,[r,a]=C.useState(t?.name||""),[s,o]=C.useState(t?.ip_address||""),[l,c]=C.useState(t?.username||""),[d,f]=C.useState(t?.password||""),[p,m]=C.useState(t?.printer_id||null),[y,b]=C.useState(null),[x,g]=C.useState(null),{data:M}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),{data:w}=bn({queryKey:["smart-plugs"],queryFn:pt.getSmartPlugs});C.useEffect(()=>{const O=B=>{B.key==="Escape"&&e()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e]);const E=gn({mutationFn:()=>pt.testSmartPlugConnection(s,l||null,d||null),onSuccess:O=>{b(O),g(null),!r&&O.device_name&&a(O.device_name)},onError:O=>{b(null),g(O.message)}}),A=gn({mutationFn:O=>pt.createSmartPlug(O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),N=gn({mutationFn:O=>pt.updateSmartPlug(t.id,O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),R=M?.filter(O=>!w?.some(U=>U.printer_id===O.id&&U.id!==t?.id)),F=O=>{if(O.preventDefault(),g(null),!r.trim()){g("Name is required");return}if(!s.trim()){g("IP address is required");return}const B={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:p};i?N.mutate(B):A.mutate(B)},P=A.isPending||N.isPending;return _.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:_.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:O=>O.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(qn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:F,className:"p-6 space-y-4",children:[x&&_.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:x}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx("input",{type:"text",value:s,onChange:O=>{o(O.target.value),b(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsxs(vt,{type:"button",variant:"secondary",onClick:()=>E.mutate(),disabled:!s.trim()||E.isPending,children:[E.isPending?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(zN,{className:"w-4 h-4"}),"Test"]})]})]}),y&&_.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${y.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:y.success?_.jsxs(_.Fragment,{children:[_.jsx(Qp,{className:"w-5 h-5"}),_.jsxs("div",{children:[_.jsx("p",{className:"font-medium",children:"Connected!"}),_.jsxs("p",{className:"text-sm opacity-80",children:[y.device_name&&`Device: ${y.device_name} - `,"State: ",y.state]})]})]}):_.jsxs(_.Fragment,{children:[_.jsx(FN,{className:"w-5 h-5"}),_.jsx("span",{children:"Connection failed"})]})}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),_.jsx("input",{type:"text",value:r,onChange:O=>a(O.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),_.jsx("input",{type:"text",value:l,onChange:O=>c(O.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:d,onChange:O=>f(O.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),_.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),_.jsxs("select",{value:p??"",onChange:O=>m(O.target.value?Number(O.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"",children:"No printer (manual control only)"}),R?.map(O=>_.jsx("option",{value:O.id,children:O.name},O.id))]}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),_.jsxs("div",{className:"flex gap-3 pt-2",children:[_.jsx(vt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),_.jsxs(vt,{type:"submit",disabled:P,className:"flex-1",children:[P?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(hS,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function wHe(){const t=ar(),[e,n]=C.useState(null),[i,r]=C.useState(!1),[a,s]=C.useState(!1),[o,l]=C.useState(!1),[c,d]=C.useState(null),{data:f,isLoading:p}=bn({queryKey:["settings"],queryFn:pt.getSettings}),{data:m,isLoading:y}=bn({queryKey:["smart-plugs"],queryFn:pt.getSmartPlugs}),{data:b}=bn({queryKey:["ffmpeg-status"],queryFn:pt.checkFfmpeg});C.useEffect(()=>{f&&!e&&n(f)},[f,e]),C.useEffect(()=>{if(f&&e){const w=f.auto_archive!==e.auto_archive||f.save_thumbnails!==e.save_thumbnails||f.capture_finish_photo!==e.capture_finish_photo||f.default_filament_cost!==e.default_filament_cost||f.currency!==e.currency||f.energy_cost_per_kwh!==e.energy_cost_per_kwh;r(w)}},[f,e]);const x=gn({mutationFn:pt.updateSettings,onSuccess:w=>{t.setQueryData(["settings"],w),n(w),r(!1),s(!0),setTimeout(()=>s(!1),2e3)}}),g=()=>{e&&x.mutate(e)},M=(w,E)=>{e&&n({...e,[w]:E})};return p||!e?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),_.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),_.jsxs(vt,{onClick:g,disabled:!i||x.isPending,children:[x.isPending?_.jsx(di,{className:"w-4 h-4 animate-spin"}):a?_.jsx(Yne,{className:"w-4 h-4"}):_.jsx(hS,{className:"w-4 h-4"}),a?"Saved!":"Save"]})]}),x.isError&&_.jsxs("div",{className:"mb-6 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to save settings: ",x.error.message]}),_.jsxs("div",{className:"flex gap-8",children:[_.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),_.jsxs(Si,{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Auto-archive prints"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.auto_archive,onChange:w=>M("auto_archive",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Save thumbnails"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.save_thumbnails,onChange:w=>M("save_thumbnails",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Capture finish photo"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.capture_finish_photo,onChange:w=>M("capture_finish_photo",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),e.capture_finish_photo&&b&&!b.installed&&_.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[_.jsx(Sp,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),_.jsxs("div",{className:"text-sm",children:[_.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),_.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),_.jsxs(Si,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.default_filament_cost,onChange:w=>M("default_filament_cost",parseFloat(w.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),_.jsxs("select",{value:e.currency,onChange:w=>M("currency",w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"USD",children:"USD ($)"}),_.jsx("option",{value:"EUR",children:"EUR (€)"}),_.jsx("option",{value:"GBP",children:"GBP (£)"}),_.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),_.jsx("option",{value:"JPY",children:"JPY (¥)"}),_.jsx("option",{value:"CNY",children:"CNY (¥)"}),_.jsx("option",{value:"CAD",children:"CAD ($)"}),_.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.energy_cost_per_kwh,onChange:w=>M("energy_cost_per_kwh",parseFloat(w.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Used for tracking energy costs per print via smart plugs"})]})]})]}),_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"About"})}),_.jsx(Si,{children:_.jsxs("div",{className:"space-y-2 text-sm",children:[_.jsx("p",{className:"text-white",children:"Bambusy v0.1.2"}),_.jsx("p",{className:"text-bambu-gray",children:"Archive and manage your Bambu Lab 3MF files"}),_.jsx("p",{className:"text-bambu-gray",children:"Connect to printers via LAN mode (developer mode required)"})]})})]})]}),_.jsx("div",{className:"w-96 flex-shrink-0",children:_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(U2,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),_.jsxs(vt,{size:"sm",onClick:()=>{d(null),l(!0)},children:[_.jsx(g0,{className:"w-4 h-4"}),"Add"]})]})}),_.jsxs(Si,{children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),y?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(di,{className:"w-6 h-6 text-bambu-green animate-spin"})}):m&&m.length>0?_.jsx("div",{className:"space-y-4",children:m.map(w=>_.jsx(_He,{plug:w,onEdit:E=>{d(E),l(!0)}},w.id))}):_.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[_.jsx(U2,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),_.jsx("p",{children:"No smart plugs configured"}),_.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})})]}),o&&_.jsx(SHe,{plug:c,onClose:()=>{l(!1),d(null)}})]})}function MHe({onSuccess:t}){const{showToast:e}=dc(),[n,i]=C.useState("email"),[r,a]=C.useState(""),[s,o]=C.useState(""),[l,c]=C.useState(""),[d,f]=C.useState(""),[p,m]=C.useState("global"),y=gn({mutationFn:()=>pt.cloudLogin(r,s,p),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):w.needs_verification?(e("Verification code sent to your email"),i("code")):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),b=gn({mutationFn:()=>pt.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),x=gn({mutationFn:()=>pt.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),g=w=>{w.preventDefault(),n==="email"?y.mutate():n==="code"?b.mutate():n==="token"&&x.mutate()},M=y.isPending||b.isPending||x.isPending;return _.jsxs(ai,{className:"max-w-md mx-auto",children:[_.jsx(Lg,{children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(UN,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),_.jsx(Si,{children:_.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n==="email"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),_.jsx("input",{type:"email",value:r,onChange:w=>a(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:s,onChange:w=>o(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),_.jsxs("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"global",children:"Global"}),_.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),_.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),_.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),_.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),_.jsx("textarea",{value:d,onChange:w=>f(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:3,required:!0})]}),_.jsxs("div",{className:"flex gap-2",children:[n==="code"&&_.jsx(vt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),_.jsxs(vt,{type:"submit",disabled:M,className:"flex-1",children:[M?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(_4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(Vie,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(_4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function EHe({setting:t,onClick:e}){return _.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&_.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function AHe({setting:t,onClose:e}){const{data:n,isLoading:i}=bn({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>pt.getCloudSettingDetail(t.setting_id)});return _.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:_.jsx(ai,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:_.jsxs(Si,{className:"p-0 flex flex-col h-full",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),_.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(qn,{className:"w-5 h-5"})})]}),_.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?_.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap overflow-x-auto bg-bambu-dark p-4 rounded-lg",children:JSON.stringify(n,null,2)}):_.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),_.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:_.jsx(vt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function THe({settings:t}){const[e,n]=C.useState(new Set),[i,r]=C.useState(null),a=l=>[...l].sort((c,d)=>c.name.localeCompare(d.name)),s=l=>{n(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})},o=[{key:"filament",label:"Filament Presets",icon:pie,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:Lu,items:a(t.printer)},{key:"process",label:"Process Presets",icon:_G,items:a(t.process)}];return _.jsxs(_.Fragment,{children:[_.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:d,items:f})=>_.jsxs(ai,{children:[_.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx(d,{className:"w-5 h-5 text-bambu-green"}),_.jsx("span",{className:"text-lg font-semibold text-white",children:c}),_.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?_.jsx(Qne,{className:"w-5 h-5 text-bambu-gray"}):_.jsx(Rf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&_.jsx(Si,{className:"pt-0",children:_.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(p=>_.jsx(EHe,{setting:p,onClick:()=>r(p)},p.setting_id))})}),e.has(l)&&f.length===0&&_.jsx(Si,{className:"pt-0",children:_.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&_.jsx(AHe,{setting:i,onClose:()=>r(null)})]})}function CHe(){const t=ar(),{showToast:e}=dc(),{data:n,isLoading:i}=bn({queryKey:["cloudStatus"],queryFn:pt.getCloudStatus}),{data:r,isLoading:a,refetch:s}=bn({queryKey:["cloudSettings"],queryFn:()=>pt.getCloudSettings(),enabled:!!n?.is_authenticated,retry:!1,staleTime:1e3*60*5}),o=gn({mutationFn:pt.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),l=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return i?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-2",children:[_.jsx(UN,{className:"w-6 h-6 text-bambu-green"}),"Cloud Profiles"]}),_.jsx("p",{className:"text-bambu-gray",children:n?.is_authenticated?`Connected as ${n.email}`:"Manage your Bambu Cloud slicer presets"})]}),n?.is_authenticated&&_.jsxs("div",{className:"flex gap-2",children:[_.jsxs(vt,{variant:"secondary",onClick:()=>s(),disabled:a,children:[_.jsx(fS,{className:`w-4 h-4 ${a?"animate-spin":""}`}),"Refresh"]}),_.jsxs(vt,{variant:"secondary",onClick:()=>o.mutate(),disabled:o.isPending,children:[_.jsx(nre,{className:"w-4 h-4"}),"Logout"]})]})]}),n?.is_authenticated?a?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):r?_.jsx(THe,{settings:r}):_.jsx(ai,{children:_.jsxs(Si,{className:"py-8 text-center",children:[_.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),_.jsx(vt,{className:"mt-4",onClick:()=>s(),children:"Retry"})]})}):_.jsx(MHe,{onSuccess:l})]})}function RHe(){const t=C.useRef(null),e=C.useRef(null),n=ar(),[i,r]=C.useState(!1),a=C.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(c);d.onopen=()=>{r(!0);const f=setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4);d.onclose=()=>{clearInterval(f)}},d.onmessage=f=>{try{const p=JSON.parse(f.data);s(p)}catch{}},d.onclose=()=>{r(!1),t.current=null,e.current=window.setTimeout(()=>{a()},3e3)},d.onerror=()=>{d.close()},t.current=d},[]),s=C.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],c=>({...c,...l.data}));break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);C.useEffect(()=>(a(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[a]);const o=C.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:i,sendMessage:o}}const NHe=new pne({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function PHe({children:t}){return RHe(),_.jsx(_.Fragment,{children:t})}function DHe(){return _.jsx(gae,{children:_.jsx(Mae,{children:_.jsx(mne,{client:NHe,children:_.jsx(PHe,{children:_.jsx(Ite,{children:_.jsx(hte,{children:_.jsxs(ru,{path:"/",element:_.jsx(_ae,{}),children:[_.jsx(ru,{index:!0,element:_.jsx(Bae,{})}),_.jsx(ru,{path:"archives",element:_.jsx(pEe,{})}),_.jsx(ru,{path:"queue",element:_.jsx(vEe,{})}),_.jsx(ru,{path:"stats",element:_.jsx(bHe,{})}),_.jsx(ru,{path:"cloud",element:_.jsx(CHe,{})}),_.jsx(ru,{path:"settings",element:_.jsx(wHe,{})})]})})})})})})})}yee.createRoot(document.getElementById("root")).render(_.jsx(C.StrictMode,{children:_.jsx(DHe,{})}));
+ `},Fje={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function zje(t){let{announcements:e=Fje,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=Uje}=t;const{announce:a,announcement:s}=kje(),o=Vv("DndLiveRegion"),[l,c]=C.useState(!1);if(C.useEffect(()=>{c(!0)},[]),Lje(C.useMemo(()=>({onDragStart(f){let{active:p}=f;a(e.onDragStart({active:p}))},onDragMove(f){let{active:p,over:m}=f;e.onDragMove&&a(e.onDragMove({active:p,over:m}))},onDragOver(f){let{active:p,over:m}=f;a(e.onDragOver({active:p,over:m}))},onDragEnd(f){let{active:p,over:m}=f;a(e.onDragEnd({active:p,over:m}))},onDragCancel(f){let{active:p,over:m}=f;a(e.onDragCancel({active:p,over:m}))}}),[a,e])),!l)return null;const d=_i.createElement(_i.Fragment,null,_i.createElement(Dje,{id:i,value:r.draggable}),_i.createElement(Oje,{id:o,announcement:s}));return n?Bl.createPortal(d,n):d}var Ji;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(Ji||(Ji={}));function iS(){}function SV(t,e){return C.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Bje(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const vo=Object.freeze({x:0,y:0});function BZ(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function jZ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function jje(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function wV(t){let{left:e,top:n,height:i,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+i},{x:e+r,y:n+i}]}function HZ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function MV(t,e,n){return e===void 0&&(e=t.left),n===void 0&&(n=t.top),{x:e+t.width*.5,y:n+t.height*.5}}const Hje=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=MV(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=BZ(MV(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(jZ)},Vje=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=wV(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=wV(l),d=r.reduce((p,m,y)=>p+BZ(c[y],m),0),f=Number((d/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(jZ)};function Gje(t,e){const n=Math.max(e.top,t.top),i=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),a=Math.min(e.top+e.height,t.top+t.height),s=r-i,o=a-n;if(i{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=[];for(const a of i){const{id:s}=a,o=n.get(s);if(o){const l=Gje(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(jje)};function Wje(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function VZ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:vo}function qje(t){return function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),a=1;a({...s,top:s.top+t*o.y,bottom:s.bottom+t*o.y,left:s.left+t*o.x,right:s.right+t*o.x}),{...n})}}const Xje=qje(1);function Kje(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function Yje(t,e,n){const i=Kje(e);if(!i)return t;const{scaleX:r,scaleY:a,x:s,y:o}=i,l=t.left-s-(1-r)*parseFloat(n),c=t.top-o-(1-a)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const Zje={ignoreTransform:!1};function ym(t,e){e===void 0&&(e=Zje);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=za(t).getComputedStyle(t);c&&(n=Yje(n,c,d))}const{top:i,left:r,width:a,height:s,bottom:o,right:l}=n;return{top:i,left:r,width:a,height:s,bottom:o,right:l}}function EV(t){return ym(t,{ignoreTransform:!0})}function Qje(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function Jje(t,e){return e===void 0&&(e=za(t).getComputedStyle(t)),e.position==="fixed"}function e5e(t,e){e===void 0&&(e=za(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const a=e[r];return typeof a=="string"?n.test(a):!1})}function Nw(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(tk(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!jv(r)||UZ(r)||n.includes(r))return n;const a=za(t).getComputedStyle(r);return r!==t&&e5e(r,a)&&n.push(r),Jje(r,a)?n:i(r.parentNode)}return t?i(t):n}function GZ(t){const[e]=Nw(t,1);return e??null}function S2(t){return!Rw||!t?null:vm(t)?t:ek(t)?tk(t)||t===xm(t).scrollingElement?window:jv(t)?t:null:null}function $Z(t){return vm(t)?t.scrollX:t.scrollLeft}function WZ(t){return vm(t)?t.scrollY:t.scrollTop}function MN(t){return{x:$Z(t),y:WZ(t)}}var _r;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(_r||(_r={}));function qZ(t){return!Rw||!t?!1:t===document.scrollingElement}function XZ(t){const e={x:0,y:0},n=qZ(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,a=t.scrollLeft<=e.x,s=t.scrollTop>=i.y,o=t.scrollLeft>=i.x;return{isTop:r,isLeft:a,isBottom:s,isRight:o,maxScroll:i,minScroll:e}}const t5e={x:.2,y:.2};function n5e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=t5e);const{isTop:c,isBottom:d,isLeft:f,isRight:p}=XZ(t),m={x:0,y:0},y={x:0,y:0},b={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+b.height?(m.y=_r.Backward,y.y=i*Math.abs((e.top+b.height-a)/b.height)):!d&&l>=e.bottom-b.height&&(m.y=_r.Forward,y.y=i*Math.abs((e.bottom-b.height-l)/b.height)),!p&&o>=e.right-b.width?(m.x=_r.Forward,y.x=i*Math.abs((e.right-b.width-o)/b.width)):!f&&s<=e.left+b.width&&(m.x=_r.Backward,y.x=i*Math.abs((e.left+b.width-s)/b.width)),{direction:m,speed:y}}function i5e(t){if(t===document.scrollingElement){const{innerWidth:a,innerHeight:s}=window;return{top:0,left:0,right:a,bottom:s,width:a,height:s}}const{top:e,left:n,right:i,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:i,bottom:r,width:t.clientWidth,height:t.clientHeight}}function KZ(t){return t.reduce((e,n)=>_p(e,MN(n)),vo)}function r5e(t){return t.reduce((e,n)=>e+$Z(n),0)}function a5e(t){return t.reduce((e,n)=>e+WZ(n),0)}function s5e(t,e){if(e===void 0&&(e=ym),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);GZ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const o5e=[["x",["left","right"],r5e],["y",["top","bottom"],a5e]];class rk{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=Nw(n),r=KZ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of o5e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),d=r[a]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class c0{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...n)})},this.target=e}add(e,n,i){var r;(r=this.target)==null||r.addEventListener(e,n,i),this.listeners.push([e,n,i])}}function l5e(t){const{EventTarget:e}=za(t);return t instanceof e?t:xm(t)}function w2(t,e){const n=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+i**2)>e:"x"in e&&"y"in e?n>e.x&&i>e.y:"x"in e?n>e.x:"y"in e?i>e.y:!1}var Rs;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Rs||(Rs={}));function AV(t){t.preventDefault()}function c5e(t){t.stopPropagation()}var pn;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(pn||(pn={}));const YZ={start:[pn.Space,pn.Enter],cancel:[pn.Esc],end:[pn.Space,pn.Enter,pn.Tab]},u5e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case pn.Right:return{...n,x:n.x+25};case pn.Left:return{...n,x:n.x-25};case pn.Down:return{...n,y:n.y+25};case pn.Up:return{...n,y:n.y-25}}};class ak{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new c0(xm(n)),this.windowListeners=new c0(za(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Rs.Resize,this.handleCancel),this.windowListeners.add(Rs.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Rs.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&s5e(i),n(vo)}handleKeyDown(e){if(ik(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=YZ,coordinateGetter:s=u5e,scrollBehavior:o="smooth"}=r,{code:l}=e;if(a.end.includes(l)){this.handleEnd(e);return}if(a.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=i.current,d=c?{x:c.left,y:c.top}:vo;this.referenceCoordinates||(this.referenceCoordinates=d);const f=s(e,{active:n,context:i.current,currentCoordinates:d});if(f){const p=tv(f,d),m={x:0,y:0},{scrollableAncestors:y}=i.current;for(const b of y){const x=e.code,{isTop:g,isRight:M,isLeft:w,isBottom:E,maxScroll:A,minScroll:N}=XZ(b),R=i5e(b),F={x:Math.min(x===pn.Right?R.right-R.width/2:R.right,Math.max(x===pn.Right?R.left:R.left+R.width/2,f.x)),y:Math.min(x===pn.Down?R.bottom-R.height/2:R.bottom,Math.max(x===pn.Down?R.top:R.top+R.height/2,f.y))},P=x===pn.Right&&!M||x===pn.Left&&!w,O=x===pn.Down&&!E||x===pn.Up&&!g;if(P&&F.x!==f.x){const B=b.scrollLeft+p.x,U=x===pn.Right&&B<=A.x||x===pn.Left&&B>=N.x;if(U&&!p.y){b.scrollTo({left:B,behavior:o});return}U?m.x=b.scrollLeft-B:m.x=x===pn.Right?b.scrollLeft-A.x:b.scrollLeft-N.x,m.x&&b.scrollBy({left:-m.x,behavior:o});break}else if(O&&F.y!==f.y){const B=b.scrollTop+p.y,U=x===pn.Down&&B<=A.y||x===pn.Up&&B>=N.y;if(U&&!p.x){b.scrollTo({top:B,behavior:o});return}U?m.y=b.scrollTop-B:m.y=x===pn.Down?b.scrollTop-A.y:b.scrollTop-N.y,m.y&&b.scrollBy({top:-m.y,behavior:o});break}}this.handleMove(e,_p(tv(f,this.referenceCoordinates),m))}}}handleMove(e,n){const{onMove:i}=this.props;e.preventDefault(),i(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}ak.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=YZ,onActivation:r}=e,{active:a}=n;const{code:s}=t.nativeEvent;if(i.start.includes(s)){const o=a.activatorNode.current;return o&&t.target!==o?!1:(t.preventDefault(),r?.({event:t.nativeEvent}),!0)}return!1}}];function TV(t){return!!(t&&"distance"in t)}function CV(t){return!!(t&&"delay"in t)}class sk{constructor(e,n,i){var r;i===void 0&&(i=l5e(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:a}=e,{target:s}=a;this.props=e,this.events=n,this.document=xm(s),this.documentListeners=new c0(this.document),this.listeners=new c0(i),this.windowListeners=new c0(za(s)),this.initialCoordinates=(r=wN(a))!=null?r:vo,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Rs.Resize,this.handleCancel),this.windowListeners.add(Rs.DragStart,AV),this.windowListeners.add(Rs.VisibilityChange,this.handleCancel),this.windowListeners.add(Rs.ContextMenu,AV),this.documentListeners.add(Rs.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(CV(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(TV(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:i,onPending:r}=this.props;r(i,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Rs.Click,c5e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Rs.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:i,initialCoordinates:r,props:a}=this,{onMove:s,options:{activationConstraint:o}}=a;if(!r)return;const l=(n=wN(e))!=null?n:vo,c=tv(r,l);if(!i&&o){if(TV(o)){if(o.tolerance!=null&&w2(c,o.tolerance))return this.handleCancel();if(w2(c,o.distance))return this.handleStart()}if(CV(o)&&w2(c,o.tolerance))return this.handleCancel();this.handlePending(o,c);return}e.cancelable&&e.preventDefault(),s(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===pn.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const d5e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ok extends sk{constructor(e){const{event:n}=e,i=xm(n.target);super(e,d5e,i)}}ok.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return!n.isPrimary||n.button!==0?!1:(i?.({event:n}),!0)}}];const f5e={move:{name:"mousemove"},end:{name:"mouseup"}};var EN;(function(t){t[t.RightClick=2]="RightClick"})(EN||(EN={}));class h5e extends sk{constructor(e){super(e,f5e,xm(e.event.target))}}h5e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===EN.RightClick?!1:(i?.({event:n}),!0)}}];const M2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class p5e extends sk{constructor(e){super(e,M2)}static setup(){return window.addEventListener(M2.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(M2.move.name,e)};function e(){}}}p5e.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;const{touches:r}=n;return r.length>1?!1:(i?.({event:n}),!0)}}];var u0;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(u0||(u0={}));var rS;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(rS||(rS={}));function m5e(t){let{acceleration:e,activator:n=u0.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=rS.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:p}=t;const m=v5e({delta:f,disabled:!a}),[y,b]=Tje(),x=C.useRef({x:0,y:0}),g=C.useRef({x:0,y:0}),M=C.useMemo(()=>{switch(n){case u0.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case u0.DraggableRect:return r}},[n,r,l]),w=C.useRef(null),E=C.useCallback(()=>{const N=w.current;if(!N)return;const R=x.current.x*g.current.x,F=x.current.y*g.current.y;N.scrollBy(R,F)},[]),A=C.useMemo(()=>o===rS.TreeOrder?[...c].reverse():c,[o,c]);C.useEffect(()=>{if(!a||!c.length||!M){b();return}for(const N of A){if(i?.(N)===!1)continue;const R=c.indexOf(N),F=d[R];if(!F)continue;const{direction:P,speed:O}=n5e(N,F,M,e,p);for(const B of["x","y"])m[B][P[B]]||(O[B]=0,P[B]=0);if(O.x>0||O.y>0){b(),w.current=N,y(E,s),x.current=O,g.current=P;return}}x.current={x:0,y:0},g.current={x:0,y:0},b()},[e,E,i,b,a,s,JSON.stringify(M),JSON.stringify(m),y,c,A,d,JSON.stringify(p)])}const g5e={x:{[_r.Backward]:!1,[_r.Forward]:!1},y:{[_r.Backward]:!1,[_r.Forward]:!1}};function v5e(t){let{delta:e,disabled:n}=t;const i=SN(e);return Hv(r=>{if(n||!i||!r)return g5e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[_r.Backward]:r.x[_r.Backward]||a.x===-1,[_r.Forward]:r.x[_r.Forward]||a.x===1},y:{[_r.Backward]:r.y[_r.Backward]||a.y===-1,[_r.Forward]:r.y[_r.Forward]||a.y===1}}},[n,e,i])}function x5e(t,e){const n=e!=null?t.get(e):void 0,i=n?n.node.current:null;return Hv(r=>{var a;return e==null?null:(a=i??r)!=null?a:null},[i,e])}function y5e(t,e){return C.useMemo(()=>t.reduce((n,i)=>{const{sensor:r}=i,a=r.activators.map(s=>({eventName:s.eventName,handler:e(s.handler,i)}));return[...n,...a]},[]),[t,e])}var iv;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(iv||(iv={}));var AN;(function(t){t.Optimized="optimized"})(AN||(AN={}));const RV=new Map;function b5e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=C.useState(null),{frequency:o,measure:l,strategy:c}=r,d=C.useRef(t),f=x(),p=ev(f),m=C.useCallback(function(g){g===void 0&&(g=[]),!p.current&&s(M=>M===null?g:M.concat(g.filter(w=>!M.includes(w))))},[p]),y=C.useRef(null),b=Hv(g=>{if(f&&!n)return RV;if(!g||g===RV||d.current!==t||a!=null){const M=new Map;for(let w of t){if(!w)continue;if(a&&a.length>0&&!a.includes(w.id)&&w.rect.current){M.set(w.id,w.rect.current);continue}const E=w.node.current,A=E?new rk(l(E),E):null;w.rect.current=A,A&&M.set(w.id,A)}return M}return g},[t,a,n,f,l]);return C.useEffect(()=>{d.current=t},[t]),C.useEffect(()=>{f||m()},[n,f]),C.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),C.useEffect(()=>{f||typeof o!="number"||y.current!==null||(y.current=setTimeout(()=>{m(),y.current=null},o))},[o,f,m,...i]),{droppableRects:b,measureDroppableContainers:m,measuringScheduled:a!=null};function x(){switch(c){case iv.Always:return!1;case iv.BeforeDragging:return n;default:return!n}}}function ZZ(t,e){return Hv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function _5e(t,e){return ZZ(t,e)}function S5e(t){let{callback:e,disabled:n}=t;const i=nk(e),r=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return C.useEffect(()=>()=>r?.disconnect(),[r]),r}function Pw(t){let{callback:e,disabled:n}=t;const i=nk(e),r=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return C.useEffect(()=>()=>r?.disconnect(),[r]),r}function w5e(t){return new rk(ym(t),t)}function NV(t,e,n){e===void 0&&(e=w5e);const[i,r]=C.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const s=S5e({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=Pw({callback:a});return Ko(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function M5e(t){const e=ZZ(t);return VZ(t,e)}const PV=[];function E5e(t){const e=C.useRef(t),n=Hv(i=>t?i&&i!==PV&&t&&e.current&&t.parentNode===e.current.parentNode?i:Nw(t):PV,[t]);return C.useEffect(()=>{e.current=t},[t]),n}function A5e(t){const[e,n]=C.useState(null),i=C.useRef(t),r=C.useCallback(a=>{const s=S2(a.target);s&&n(o=>o?(o.set(s,MN(s)),new Map(o)):null)},[]);return C.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=S2(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,MN(c)]):null}).filter(l=>l!=null);n(o.length?new Map(o):null),i.current=t}return()=>{s(t),s(a)};function s(o){o.forEach(l=>{const c=S2(l);c?.removeEventListener("scroll",r)})}},[r,t]),C.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>_p(a,s),vo):KZ(t):vo,[t,e])}function DV(t,e){e===void 0&&(e=[]);const n=C.useRef(null);return C.useEffect(()=>{n.current=null},e),C.useEffect(()=>{const i=t!==vo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?tv(t,n.current):vo}function T5e(t){C.useEffect(()=>{if(!Rw)return;const e=t.map(n=>{let{sensor:i}=n;return i.setup==null?void 0:i.setup()});return()=>{for(const n of e)n?.()}},t.map(e=>{let{sensor:n}=e;return n}))}function C5e(t,e){return C.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function QZ(t){return C.useMemo(()=>t?Qje(t):null,[t])}const OV=[];function R5e(t,e){e===void 0&&(e=ym);const[n]=t,i=QZ(n?za(n):null),[r,a]=C.useState(OV);function s(){a(()=>t.length?t.map(l=>qZ(l)?i:new rk(e(l),l)):OV)}const o=Pw({callback:s});return Ko(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function N5e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return jv(e)?e:t}function P5e(t){let{measure:e}=t;const[n,i]=C.useState(null),r=C.useCallback(c=>{for(const{target:d}of c)if(jv(d)){i(f=>{const p=e(d);return f?{...f,width:p.width,height:p.height}:p});break}},[e]),a=Pw({callback:r}),s=C.useCallback(c=>{const d=N5e(c);a?.disconnect(),d&&a?.observe(d),i(d?e(d):null)},[e,a]),[o,l]=nS(s);return C.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const D5e=[{sensor:ok,options:{}},{sensor:ak,options:{}}],O5e={current:{}},e_={draggable:{measure:EV},droppable:{measure:EV,strategy:iv.WhileDragging,frequency:AN.Optimized},dragOverlay:{measure:ym}};class d0 extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,i;return(n=(i=this.get(e))==null?void 0:i.node.current)!=null?n:void 0}}const k5e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new d0,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:iS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:e_,measureDroppableContainers:iS,windowRect:null,measuringScheduled:!1},L5e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:iS,draggableNodes:new Map,over:null,measureDroppableContainers:iS},Dw=C.createContext(L5e),JZ=C.createContext(k5e);function I5e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new d0}}}function U5e(t,e){switch(e.type){case Ji.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case Ji.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case Ji.DragEnd:case Ji.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Ji.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new d0(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case Ji.SetDroppableDisabled:{const{id:n,key:i,disabled:r}=e,a=t.droppable.containers.get(n);if(!a||i!==a.key)return t;const s=new d0(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case Ji.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new d0(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function F5e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=C.useContext(Dw),a=SN(i),s=SN(n?.id);return C.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!ik(a)||document.activeElement===a.target)return;const o=r.get(s);if(!o)return;const{activatorNode:l,node:c}=o;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=Nje(d);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function z5e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function B5e(t){return C.useMemo(()=>({draggable:{...e_.draggable,...t?.draggable},droppable:{...e_.droppable,...t?.droppable},dragOverlay:{...e_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function j5e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=C.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;Ko(()=>{if(!s&&!o||!e){a.current=!1;return}if(a.current||!i)return;const c=e?.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=VZ(d,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=GZ(c);p&&p.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const eQ=C.createContext({...vo,scaleX:1,scaleY:1});var hu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(hu||(hu={}));const H5e=C.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:d=D5e,collisionDetection:f=$je,measuring:p,modifiers:m,...y}=e;const b=C.useReducer(U5e,void 0,I5e),[x,g]=b,[M,w]=Ije(),[E,A]=C.useState(hu.Uninitialized),N=E===hu.Initialized,{draggable:{active:R,nodes:F,translate:P},droppable:{containers:O}}=x,B=R!=null?F.get(R):null,U=C.useRef({initial:null,translated:null}),q=C.useMemo(()=>{var ke;return R!=null?{id:R,data:(ke=B?.data)!=null?ke:O5e,rect:U}:null},[R,B]),L=C.useRef(null),[W,G]=C.useState(null),[$,Y]=C.useState(null),J=ev(y,Object.values(y)),se=Vv("DndDescribedBy",s),H=C.useMemo(()=>O.getEnabled(),[O]),K=B5e(p),{droppableRects:re,measureDroppableContainers:ce,measuringScheduled:xe}=b5e(H,{dragging:N,dependencies:[P.x,P.y],config:K.droppable}),me=x5e(F,R),ye=C.useMemo(()=>$?wN($):null,[$]),De=de(),he=_5e(me,K.draggable.measure);j5e({activeNode:R!=null?F.get(R):null,config:De.layoutShiftCompensation,initialRect:he,measure:K.draggable.measure});const we=NV(me,K.draggable.measure,he),Be=NV(me?me.parentElement:null),le=C.useRef({activatorEvent:null,active:null,activeNode:me,collisionRect:null,collisions:null,droppableRects:re,draggableNodes:F,draggingNode:null,draggingNodeRect:null,droppableContainers:O,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ut=O.getNodeFor((n=le.current.over)==null?void 0:n.id),z=P5e({measure:K.dragOverlay.measure}),V=(i=z.nodeRef.current)!=null?i:me,ie=N?(r=z.rect)!=null?r:we:null,Q=!!(z.nodeRef.current&&z.rect),ee=M5e(Q?null:we),ae=QZ(V?za(V):null),Pe=E5e(N?ut??me:null),Re=R5e(Pe),te=z5e(m,{transform:{x:P.x-ee.x,y:P.y-ee.y,scaleX:1,scaleY:1},activatorEvent:$,active:q,activeNodeRect:we,containerNodeRect:Be,draggingNodeRect:ie,over:le.current.over,overlayNodeRect:z.rect,scrollableAncestors:Pe,scrollableAncestorRects:Re,windowRect:ae}),I=ye?_p(ye,P):null,k=A5e(Pe),X=DV(k),pe=DV(k,[we]),ve=_p(te,X),fe=ie?Xje(ie,te):null,Ye=q&&fe?f({active:q,collisionRect:fe,droppableRects:re,droppableContainers:H,pointerCoordinates:I}):null,Le=HZ(Ye,"id"),[qe,it]=C.useState(null),Ie=Q?te:_p(te,pe),Ne=Wje(Ie,(a=qe?.rect)!=null?a:null,we),dt=C.useRef(null),et=C.useCallback((ke,Me)=>{let{sensor:ge,options:je}=Me;if(L.current==null)return;const at=F.get(L.current);if(!at)return;const yt=ke.nativeEvent,Ct=new ge({active:L.current,activeNode:at,event:yt,options:je,context:le,onAbort(Pt){if(!F.get(Pt))return;const{onDragAbort:jn}=J.current,dr={id:Pt};jn?.(dr),M({type:"onDragAbort",event:dr})},onPending(Pt,En,jn,dr){if(!F.get(Pt))return;const{onDragPending:fr}=J.current,Tr={id:Pt,constraint:En,initialCoordinates:jn,offset:dr};fr?.(Tr),M({type:"onDragPending",event:Tr})},onStart(Pt){const En=L.current;if(En==null)return;const jn=F.get(En);if(!jn)return;const{onDragStart:dr}=J.current,Xi={activatorEvent:yt,active:{id:En,data:jn.data,rect:U}};Bl.unstable_batchedUpdates(()=>{dr?.(Xi),A(hu.Initializing),g({type:Ji.DragStart,initialCoordinates:Pt,active:En}),M({type:"onDragStart",event:Xi}),G(dt.current),Y(yt)})},onMove(Pt){g({type:Ji.DragMove,coordinates:Pt})},onEnd:tn(Ji.DragEnd),onCancel:tn(Ji.DragCancel)});dt.current=Ct;function tn(Pt){return async function(){const{active:jn,collisions:dr,over:Xi,scrollAdjustedTranslate:fr}=le.current;let Tr=null;if(jn&&fr){const{cancelDrop:Vr}=J.current;Tr={activatorEvent:yt,active:jn,collisions:dr,delta:fr,over:Xi},Pt===Ji.DragEnd&&typeof Vr=="function"&&await Promise.resolve(Vr(Tr))&&(Pt=Ji.DragCancel)}L.current=null,Bl.unstable_batchedUpdates(()=>{g({type:Pt}),A(hu.Uninitialized),it(null),G(null),Y(null),dt.current=null;const Vr=Pt===Ji.DragEnd?"onDragEnd":"onDragCancel";if(Tr){const Di=J.current[Vr];Di?.(Tr),M({type:Vr,event:Tr})}})}}},[F]),Je=C.useCallback((ke,Me)=>(ge,je)=>{const at=ge.nativeEvent,yt=F.get(je);if(L.current!==null||!yt||at.dndKit||at.defaultPrevented)return;const Ct={active:yt};ke(ge,Me.options,Ct)===!0&&(at.dndKit={capturedBy:Me.sensor},L.current=je,et(ge,Me))},[F,et]),st=y5e(d,Je);T5e(d),Ko(()=>{we&&E===hu.Initializing&&A(hu.Initialized)},[we,E]),C.useEffect(()=>{const{onDragMove:ke}=J.current,{active:Me,activatorEvent:ge,collisions:je,over:at}=le.current;if(!Me||!ge)return;const yt={active:Me,activatorEvent:ge,collisions:je,delta:{x:ve.x,y:ve.y},over:at};Bl.unstable_batchedUpdates(()=>{ke?.(yt),M({type:"onDragMove",event:yt})})},[ve.x,ve.y]),C.useEffect(()=>{const{active:ke,activatorEvent:Me,collisions:ge,droppableContainers:je,scrollAdjustedTranslate:at}=le.current;if(!ke||L.current==null||!Me||!at)return;const{onDragOver:yt}=J.current,Ct=je.get(Le),tn=Ct&&Ct.rect.current?{id:Ct.id,rect:Ct.rect.current,data:Ct.data,disabled:Ct.disabled}:null,Pt={active:ke,activatorEvent:Me,collisions:ge,delta:{x:at.x,y:at.y},over:tn};Bl.unstable_batchedUpdates(()=>{it(tn),yt?.(Pt),M({type:"onDragOver",event:Pt})})},[Le]),Ko(()=>{le.current={activatorEvent:$,active:q,activeNode:me,collisionRect:fe,collisions:Ye,droppableRects:re,draggableNodes:F,draggingNode:V,draggingNodeRect:ie,droppableContainers:O,over:qe,scrollableAncestors:Pe,scrollAdjustedTranslate:ve},U.current={initial:ie,translated:fe}},[q,me,Ye,fe,F,V,ie,re,O,qe,Pe,ve]),m5e({...De,delta:P,draggingRect:fe,pointerCoordinates:I,scrollableAncestors:Pe,scrollableAncestorRects:Re});const ue=C.useMemo(()=>({active:q,activeNode:me,activeNodeRect:we,activatorEvent:$,collisions:Ye,containerNodeRect:Be,dragOverlay:z,draggableNodes:F,droppableContainers:O,droppableRects:re,over:qe,measureDroppableContainers:ce,scrollableAncestors:Pe,scrollableAncestorRects:Re,measuringConfiguration:K,measuringScheduled:xe,windowRect:ae}),[q,me,we,$,Ye,Be,z,F,O,re,qe,ce,Pe,Re,K,xe,ae]),tt=C.useMemo(()=>({activatorEvent:$,activators:st,active:q,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:g,draggableNodes:F,over:qe,measureDroppableContainers:ce}),[$,st,q,we,g,se,F,qe,ce]);return _i.createElement(zZ.Provider,{value:w},_i.createElement(Dw.Provider,{value:tt},_i.createElement(JZ.Provider,{value:ue},_i.createElement(eQ.Provider,{value:Ne},c)),_i.createElement(F5e,{disabled:o?.restoreFocus===!1})),_i.createElement(zje,{...o,hiddenTextDescribedById:se}));function de(){const ke=W?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=N&&!ke&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),V5e=C.createContext(null),kV="button",G5e="Draggable";function $5e(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=Vv(G5e),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:p}=C.useContext(Dw),{role:m=kV,roleDescription:y="draggable",tabIndex:b=0}=r??{},x=l?.id===e,g=C.useContext(x?eQ:V5e),[M,w]=nS(),[E,A]=nS(),N=C5e(s,e),R=ev(n);Ko(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:E,data:R}),()=>{const P=f.get(e);P&&P.key===a&&f.delete(e)}),[f,e]);const F=C.useMemo(()=>({role:m,tabIndex:b,"aria-disabled":i,"aria-pressed":x&&m===kV?!0:void 0,"aria-roledescription":y,"aria-describedby":d.draggable}),[i,m,b,x,y,d.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:F,isDragging:x,listeners:i?void 0:N,node:M,over:p,setNodeRef:w,setActivatorNodeRef:A,transform:g}}function W5e(){return C.useContext(JZ)}const q5e="Droppable",X5e={timeout:25};function K5e(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=Vv(q5e),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=C.useContext(Dw),d=C.useRef({disabled:n}),f=C.useRef(!1),p=C.useRef(null),m=C.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:x}={...X5e,...r},g=ev(b??i),M=C.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{c(Array.isArray(g.current)?g.current:[g.current]),m.current=null},x)},[x]),w=Pw({callback:M,disabled:y||!s}),E=C.useCallback((F,P)=>{w&&(P&&(w.unobserve(P),f.current=!1),F&&w.observe(F))},[w]),[A,N]=nS(E),R=ev(e);return C.useEffect(()=>{!w||!A.current||(w.disconnect(),f.current=!1,w.observe(A.current))},[A,w]),C.useEffect(()=>(o({type:Ji.RegisterDroppable,element:{id:i,key:a,disabled:n,node:A,rect:p,data:R}}),()=>o({type:Ji.UnregisterDroppable,key:a,id:i})),[i]),C.useEffect(()=>{n!==d.current.disabled&&(o({type:Ji.SetDroppableDisabled,id:i,key:a,disabled:n}),d.current.disabled=n)},[i,a,n,o]),{active:s,rect:p,isOver:l?.id===i,node:A,over:l,setNodeRef:N}}function lk(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function Y5e(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function Pb(t){return t!==null&&t>=0}function Z5e(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n{let{rects:e,activeIndex:n,overIndex:i,index:r}=t;const a=lk(e,i,n),s=e[r],o=a[r];return!o||!s?null:{x:o.left-s.left,y:o.top-s.top,scaleX:o.width/s.width,scaleY:o.height/s.height}},tQ="Sortable",nQ=_i.createContext({activeIndex:-1,containerId:tQ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:ck,disabled:{draggable:!1,droppable:!1}});function J5e(t){let{children:e,id:n,items:i,strategy:r=ck,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:d}=W5e(),f=Vv(tQ,n),p=o.rect!==null,m=C.useMemo(()=>i.map(N=>typeof N=="object"&&"id"in N?N.id:N),[i]),y=s!=null,b=s?m.indexOf(s.id):-1,x=c?m.indexOf(c.id):-1,g=C.useRef(m),M=!Z5e(m,g.current),w=x!==-1&&b===-1||M,E=Q5e(a);Ko(()=>{M&&y&&d(m)},[M,m,y,d]),C.useEffect(()=>{g.current=m},[m]);const A=C.useMemo(()=>({activeIndex:b,containerId:f,disabled:E,disableTransforms:w,items:m,overIndex:x,useDragOverlay:p,sortedRects:Y5e(m,l),strategy:r}),[b,f,E.draggable,E.droppable,w,m,x,l,p,r]);return _i.createElement(nQ.Provider,{value:A},e)}const eHe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return lk(n,i,r).indexOf(e)},tHe=t=>{let{containerId:e,isSorting:n,wasDragging:i,index:r,items:a,newIndex:s,previousItems:o,previousContainerId:l,transition:c}=t;return!c||!i||o!==a&&r===s?!1:n?!0:s!==r&&e===l},nHe={duration:200,easing:"ease"},iQ="transform",iHe=nv.Transition.toString({property:iQ,duration:0,easing:"linear"}),rHe={roleDescription:"sortable"};function aHe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=C.useState(null),o=C.useRef(n);return Ko(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=ym(i.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&s(d)}}n!==o.current&&(o.current=n)},[e,n,i,r]),C.useEffect(()=>{a&&s(null)},[a]),a}function sHe(t){let{animateLayoutChanges:e=tHe,attributes:n,disabled:i,data:r,getNewIndex:a=eHe,id:s,strategy:o,resizeObserverConfig:l,transition:c=nHe}=t;const{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:y,sortedRects:b,overIndex:x,useDragOverlay:g,strategy:M}=C.useContext(nQ),w=oHe(i,m),E=d.indexOf(s),A=C.useMemo(()=>({sortable:{containerId:f,index:E,items:d},...r}),[f,r,E,d]),N=C.useMemo(()=>d.slice(d.indexOf(s)),[d,s]),{rect:R,node:F,isOver:P,setNodeRef:O}=K5e({id:s,data:A,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:N,...l}}),{active:B,activatorEvent:U,activeNodeRect:q,attributes:L,setNodeRef:W,listeners:G,isDragging:$,over:Y,setActivatorNodeRef:J,transform:se}=$5e({id:s,data:A,attributes:{...rHe,...n},disabled:w.draggable}),H=Aje(O,W),K=!!B,re=K&&!y&&Pb(p)&&Pb(x),ce=!g&&$,xe=ce&&re?se:null,ye=re?xe??(o??M)({rects:b,activeNodeRect:q,activeIndex:p,overIndex:x,index:E}):null,De=Pb(p)&&Pb(x)?a({id:s,items:d,activeIndex:p,overIndex:x}):E,he=B?.id,we=C.useRef({activeId:he,items:d,newIndex:De,containerId:f}),Be=d!==we.current.items,le=e({active:B,containerId:f,isDragging:$,isSorting:K,id:s,index:E,items:d,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ut=aHe({disabled:!le,index:E,node:F,rect:R});return C.useEffect(()=>{K&&we.current.newIndex!==De&&(we.current.newIndex=De),f!==we.current.containerId&&(we.current.containerId=f),d!==we.current.items&&(we.current.items=d)},[K,De,f,d]),C.useEffect(()=>{if(he===we.current.activeId)return;if(he!=null&&we.current.activeId==null){we.current.activeId=he;return}const V=setTimeout(()=>{we.current.activeId=he},50);return()=>clearTimeout(V)},[he]),{active:B,activeIndex:p,attributes:L,data:A,rect:R,index:E,newIndex:De,items:d,isOver:P,isSorting:K,isDragging:$,listeners:G,node:F,overIndex:x,over:Y,setNodeRef:H,setActivatorNodeRef:J,setDroppableNodeRef:O,setDraggableNodeRef:W,transform:ut??ye,transition:z()};function z(){if(ut||Be&&we.current.newIndex===E)return iHe;if(!(ce&&!ik(U)||!c)&&(K||le))return nv.Transition.toString({...c,property:iQ})}}function oHe(t,e){var n,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t?.draggable)!=null?n:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function aS(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const lHe=[pn.Down,pn.Right,pn.Up,pn.Left],cHe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(lHe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=r.get(f.id);if(p)switch(t.code){case pn.Down:i.topp.top&&l.push(f);break;case pn.Left:i.left>p.left&&l.push(f);break;case pn.Right:i.left1&&(d=c[1].id),d!=null){const f=a.get(n.id),p=a.get(d),m=p?r.get(p.id):null,y=p?.node.current;if(y&&m&&f&&p){const x=Nw(y).some((N,R)=>o[R]!==N),g=rQ(f,p),M=uHe(f,p),w=x||!g?{x:0,y:0}:{x:M?i.width-m.width:0,y:M?i.height-m.height:0},E={x:m.left,y:m.top};return w.x&&w.y?E:tv(E,w)}}}};function rQ(t,e){return!aS(t)||!aS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function uHe(t,e){return!aS(t)||!aS(e)||!rQ(t,e)?!1:t.data.current.sortable.index{const x={};return t.forEach(g=>{x[g.id]=g.defaultSize||4}),x},[r,a]=C.useState(()=>{const x=localStorage.getItem(e);if(x)try{const g=JSON.parse(x);return g.sizes||(g.sizes=i()),g}catch{}return{order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()}}),[s,o]=C.useState(!1);C.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),C.useEffect(()=>{const g=t.map(M=>M.id).filter(M=>!r.order.includes(M));g.length>0&&a(M=>({...M,order:[...M.order,...g]}))},[t,r.order]);const l=Bje(SV(ok,{activationConstraint:{distance:8}}),SV(ak,{coordinateGetter:cHe})),c=x=>{const{active:g,over:M}=x;M&&g.id!==M.id&&a(w=>{const E=w.order.indexOf(g.id),A=w.order.indexOf(M.id);return{...w,order:lk(w.order,E,A)}})},d=x=>{a(g=>({...g,hidden:g.hidden.includes(x)?g.hidden.filter(M=>M!==x):[...g.hidden,x]}))},f=x=>{a(g=>{const M=g.sizes[x]||4,w=M===1?2:M===2?4:1;return{...g,sizes:{...g.sizes,[x]:w}}})},p=()=>{const x={order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()};a(x)},m=r.order.map(x=>t.find(g=>g.id===x)).filter(Boolean),y=m.filter(x=>!r.hidden.includes(x.id)),b=m.filter(x=>r.hidden.includes(x.id));return _.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&_.jsxs(vt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[_.jsx(y4,{className:"w-4 h-4"}),b.length," Hidden"]}),_.jsxs(vt,{variant:"secondary",size:"sm",onClick:p,children:[_.jsx(yG,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&b.length>0&&_.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(x=>_.jsxs("button",{onClick:()=>d(x.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[_.jsx(y4,{className:"w-3 h-3"}),x.title]},x.id))})]}),_.jsx(H5e,{sensors:l,collisionDetection:Hje,onDragEnd:c,children:_.jsx(J5e,{items:y.map(x=>x.id),strategy:ck,children:_.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(x=>_.jsx(dHe,{id:x.id,title:x.title,isHidden:r.hidden.includes(x.id),size:r.sizes[x.id]||2,onToggleVisibility:()=>d(x.id),onToggleSize:()=>f(x.id),children:x.component},x.id))})})}),y.length===0&&_.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[_.jsx("p",{children:"All widgets are hidden."}),_.jsx(vt,{className:"mt-4",onClick:p,children:"Reset Layout"})]})]})}function hHe({stats:t,currency:e}){return _.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:_.jsx(r_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),_.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:_.jsx(Qo,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:_.jsx(r_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:_.jsx(x4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:_.jsx(wG,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:_.jsx(x4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function pHe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),_.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:_.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Qp,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(IN,{className:"w-4 h-4 text-red-400"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function mHe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return _.jsx("div",{className:"flex items-center justify-center h-full",children:_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const r=(Math.min(150,Math.max(50,n))-50)/100*100,s=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),_.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[_.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),_.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),_.jsxs("div",{className:"space-y-2 flex-1",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[_.jsx(Gre,{className:"w-3 h-3"}),_.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&_.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>_.jsxs("div",{className:"flex items-center justify-between text-xs",children:[_.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),_.jsxs("span",{className:`font-medium ${c>=95&&c<=105?"text-bambu-green":c>105?"text-blue-400":"text-orange-400"}`,children:[c.toFixed(0),"%"]})]},l))})]})]})}function gHe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return _.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,i])=>i-n);return _.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[_.jsx("span",{className:"text-white",children:n}),_.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),_.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:_.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function vHe({printDates:t}){return _.jsx(xEe,{printDates:t,months:4})}function xHe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>_.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[_.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:_.jsx(Lu,{className:"w-4 h-4 text-bambu-green"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),_.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function yHe({archives:t,currency:e}){return!t||t.length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):_.jsx(Eje,{archives:t,currency:e})}function bHe(){const{data:t,isLoading:e}=bn({queryKey:["archiveStats"],queryFn:pt.getArchiveStats}),{data:n}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),{data:i}=bn({queryKey:["archives"],queryFn:()=>pt.getArchives(void 0,1e3,0)}),{data:r}=bn({queryKey:["settings"],queryFn:pt.getSettings}),a=r?.currency||"$",s=new Map(n?.map(c=>[String(c.id),c.name])||[]),o=i?.map(c=>c.created_at)||[];if(e)return _.jsx("div",{className:"p-8",children:_.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:_.jsx(hHe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:_.jsx(pHe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:_.jsx(mHe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:_.jsx(gHe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:_.jsx(vHe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:_.jsx(xHe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:_.jsx(yHe,{archives:i||[],currency:a}),defaultSize:4}];return _.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),_.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),_.jsx(fHe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function _He({plug:t,onEdit:e}){const n=ar(),[i,r]=C.useState(!1),[a,s]=C.useState(!1),[o,l]=C.useState(!1),[c,d]=C.useState(!1),{data:f,isLoading:p,refetch:m}=bn({queryKey:["smart-plug-status",t.id],queryFn:()=>pt.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:y}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),b=y?.find(N=>N.id===t.printer_id),x=gn({mutationFn:N=>pt.controlSmartPlug(t.id,N),onSuccess:()=>{m()}}),g=gn({mutationFn:N=>pt.updateSmartPlug(t.id,N),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),M=gn({mutationFn:()=>pt.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",E=f?.reachable??!1,A=x.isPending;return _.jsxs(_.Fragment,{children:[_.jsx(ai,{className:"relative",children:_.jsxs(Si,{className:"p-4",children:[_.jsxs("div",{className:"flex items-start justify-between mb-3",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx("div",{className:`p-2 rounded-lg ${E?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:_.jsx(U2,{className:`w-5 h-5 ${E?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),_.jsxs("div",{children:[_.jsx("h3",{className:"font-medium text-white",children:t.name}),_.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),_.jsx("div",{className:"flex items-center gap-2",children:p?_.jsx(di,{className:"w-4 h-4 text-bambu-gray animate-spin"}):E?_.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[_.jsx(zN,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):_.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[_.jsx(FN,{className:"w-4 h-4"}),_.jsx("span",{children:"Offline"})]})})]}),b&&_.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[_.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),_.jsx("span",{className:"text-sm text-white",children:b.name})]}),_.jsxs("div",{className:"flex gap-2 mb-3",children:[_.jsxs(vt,{size:"sm",variant:w?"primary":"secondary",disabled:!E||A,onClick:()=>s(!0),className:"flex-1",children:[A?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(dS,{className:"w-4 h-4"}),"On"]}),_.jsxs(vt,{size:"sm",variant:w?"secondary":"primary",disabled:!E||A,onClick:()=>l(!0),className:"flex-1",children:[A?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(xG,{className:"w-4 h-4"}),"Off"]})]}),_.jsxs("button",{onClick:()=>d(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[_.jsxs("span",{className:"flex items-center gap-2",children:[_.jsx(_G,{className:"w-4 h-4"}),"Automation Settings"]}),_.jsx("span",{children:c?"-":"+"})]}),c&&_.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Enabled"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.enabled,onChange:N=>g.mutate({enabled:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto On"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:N=>g.mutate({auto_on:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:N=>g.mutate({auto_off:N.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&_.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Qo,{className:"w-4 h-4"}),"Time"]}),_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(kb,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),_.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:N=>g.mutate({off_delay_minutes:parseInt(N.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),_.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:N=>g.mutate({off_temp_threshold:parseInt(N.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-2",children:[_.jsxs(vt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[_.jsx(pre,{className:"w-4 h-4"}),"Edit"]}),_.jsx(vt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:_.jsx(jo,{className:"w-4 h-4"})})]})]})]})}),i&&_.jsx(ns,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),r(!1)},onCancel:()=>r(!1)}),a&&_.jsx(ns,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&_.jsx(ns,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function SHe({plug:t,onClose:e}){const n=ar(),i=!!t,[r,a]=C.useState(t?.name||""),[s,o]=C.useState(t?.ip_address||""),[l,c]=C.useState(t?.username||""),[d,f]=C.useState(t?.password||""),[p,m]=C.useState(t?.printer_id||null),[y,b]=C.useState(null),[x,g]=C.useState(null),{data:M}=bn({queryKey:["printers"],queryFn:pt.getPrinters}),{data:w}=bn({queryKey:["smart-plugs"],queryFn:pt.getSmartPlugs});C.useEffect(()=>{const O=B=>{B.key==="Escape"&&e()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e]);const E=gn({mutationFn:()=>pt.testSmartPlugConnection(s,l||null,d||null),onSuccess:O=>{b(O),g(null),!r&&O.device_name&&a(O.device_name)},onError:O=>{b(null),g(O.message)}}),A=gn({mutationFn:O=>pt.createSmartPlug(O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),N=gn({mutationFn:O=>pt.updateSmartPlug(t.id,O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),R=M?.filter(O=>!w?.some(U=>U.printer_id===O.id&&U.id!==t?.id)),F=O=>{if(O.preventDefault(),g(null),!r.trim()){g("Name is required");return}if(!s.trim()){g("IP address is required");return}const B={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:p};i?N.mutate(B):A.mutate(B)},P=A.isPending||N.isPending;return _.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:_.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:O=>O.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(qn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:F,className:"p-6 space-y-4",children:[x&&_.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:x}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx("input",{type:"text",value:s,onChange:O=>{o(O.target.value),b(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsxs(vt,{type:"button",variant:"secondary",onClick:()=>E.mutate(),disabled:!s.trim()||E.isPending,children:[E.isPending?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(zN,{className:"w-4 h-4"}),"Test"]})]})]}),y&&_.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${y.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:y.success?_.jsxs(_.Fragment,{children:[_.jsx(Qp,{className:"w-5 h-5"}),_.jsxs("div",{children:[_.jsx("p",{className:"font-medium",children:"Connected!"}),_.jsxs("p",{className:"text-sm opacity-80",children:[y.device_name&&`Device: ${y.device_name} - `,"State: ",y.state]})]})]}):_.jsxs(_.Fragment,{children:[_.jsx(FN,{className:"w-5 h-5"}),_.jsx("span",{children:"Connection failed"})]})}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),_.jsx("input",{type:"text",value:r,onChange:O=>a(O.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),_.jsx("input",{type:"text",value:l,onChange:O=>c(O.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:d,onChange:O=>f(O.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),_.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),_.jsxs("select",{value:p??"",onChange:O=>m(O.target.value?Number(O.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"",children:"No printer (manual control only)"}),R?.map(O=>_.jsx("option",{value:O.id,children:O.name},O.id))]}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),_.jsxs("div",{className:"flex gap-3 pt-2",children:[_.jsx(vt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),_.jsxs(vt,{type:"submit",disabled:P,className:"flex-1",children:[P?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(hS,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function wHe(){const t=ar(),[e,n]=C.useState(null),[i,r]=C.useState(!1),[a,s]=C.useState(!1),[o,l]=C.useState(!1),[c,d]=C.useState(null),{data:f,isLoading:p}=bn({queryKey:["settings"],queryFn:pt.getSettings}),{data:m,isLoading:y}=bn({queryKey:["smart-plugs"],queryFn:pt.getSmartPlugs}),{data:b}=bn({queryKey:["ffmpeg-status"],queryFn:pt.checkFfmpeg});C.useEffect(()=>{f&&!e&&n(f)},[f,e]),C.useEffect(()=>{if(f&&e){const w=f.auto_archive!==e.auto_archive||f.save_thumbnails!==e.save_thumbnails||f.capture_finish_photo!==e.capture_finish_photo||f.default_filament_cost!==e.default_filament_cost||f.currency!==e.currency||f.energy_cost_per_kwh!==e.energy_cost_per_kwh;r(w)}},[f,e]);const x=gn({mutationFn:pt.updateSettings,onSuccess:w=>{t.setQueryData(["settings"],w),n(w),r(!1),s(!0),setTimeout(()=>s(!1),2e3)}}),g=()=>{e&&x.mutate(e)},M=(w,E)=>{e&&n({...e,[w]:E})};return p||!e?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),_.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),_.jsxs(vt,{onClick:g,disabled:!i||x.isPending,children:[x.isPending?_.jsx(di,{className:"w-4 h-4 animate-spin"}):a?_.jsx(Yne,{className:"w-4 h-4"}):_.jsx(hS,{className:"w-4 h-4"}),a?"Saved!":"Save"]})]}),x.isError&&_.jsxs("div",{className:"mb-6 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to save settings: ",x.error.message]}),_.jsxs("div",{className:"flex gap-8",children:[_.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),_.jsxs(Si,{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Auto-archive prints"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.auto_archive,onChange:w=>M("auto_archive",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Save thumbnails"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.save_thumbnails,onChange:w=>M("save_thumbnails",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Capture finish photo"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.capture_finish_photo,onChange:w=>M("capture_finish_photo",w.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),e.capture_finish_photo&&b&&!b.installed&&_.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[_.jsx(Sp,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),_.jsxs("div",{className:"text-sm",children:[_.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),_.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),_.jsxs(Si,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.default_filament_cost,onChange:w=>M("default_filament_cost",parseFloat(w.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),_.jsxs("select",{value:e.currency,onChange:w=>M("currency",w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"USD",children:"USD ($)"}),_.jsx("option",{value:"EUR",children:"EUR (€)"}),_.jsx("option",{value:"GBP",children:"GBP (£)"}),_.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),_.jsx("option",{value:"JPY",children:"JPY (¥)"}),_.jsx("option",{value:"CNY",children:"CNY (¥)"}),_.jsx("option",{value:"CAD",children:"CAD ($)"}),_.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.energy_cost_per_kwh,onChange:w=>M("energy_cost_per_kwh",parseFloat(w.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Used for tracking energy costs per print via smart plugs"})]})]})]}),_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"About"})}),_.jsx(Si,{children:_.jsxs("div",{className:"space-y-2 text-sm",children:[_.jsx("p",{className:"text-white",children:"Bambusy v0.1.2"}),_.jsx("p",{className:"text-bambu-gray",children:"Archive and manage your Bambu Lab 3MF files"}),_.jsx("p",{className:"text-bambu-gray",children:"Connect to printers via LAN mode (developer mode required)"})]})})]})]}),_.jsx("div",{className:"w-96 flex-shrink-0",children:_.jsxs(ai,{children:[_.jsx(Lg,{children:_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(U2,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),_.jsxs(vt,{size:"sm",onClick:()=>{d(null),l(!0)},children:[_.jsx(g0,{className:"w-4 h-4"}),"Add"]})]})}),_.jsxs(Si,{children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),y?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(di,{className:"w-6 h-6 text-bambu-green animate-spin"})}):m&&m.length>0?_.jsx("div",{className:"space-y-4",children:m.map(w=>_.jsx(_He,{plug:w,onEdit:E=>{d(E),l(!0)}},w.id))}):_.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[_.jsx(U2,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),_.jsx("p",{children:"No smart plugs configured"}),_.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})})]}),o&&_.jsx(SHe,{plug:c,onClose:()=>{l(!1),d(null)}})]})}function MHe({onSuccess:t}){const{showToast:e}=dc(),[n,i]=C.useState("email"),[r,a]=C.useState(""),[s,o]=C.useState(""),[l,c]=C.useState(""),[d,f]=C.useState(""),[p,m]=C.useState("global"),y=gn({mutationFn:()=>pt.cloudLogin(r,s,p),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):w.needs_verification?(e("Verification code sent to your email"),i("code")):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),b=gn({mutationFn:()=>pt.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),x=gn({mutationFn:()=>pt.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),g=w=>{w.preventDefault(),n==="email"?y.mutate():n==="code"?b.mutate():n==="token"&&x.mutate()},M=y.isPending||b.isPending||x.isPending;return _.jsxs(ai,{className:"max-w-md mx-auto",children:[_.jsx(Lg,{children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(UN,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),_.jsx(Si,{children:_.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n==="email"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),_.jsx("input",{type:"email",value:r,onChange:w=>a(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:s,onChange:w=>o(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),_.jsxs("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"global",children:"Global"}),_.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),_.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),_.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),_.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),_.jsx("textarea",{value:d,onChange:w=>f(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:3,required:!0})]}),_.jsxs("div",{className:"flex gap-2",children:[n==="code"&&_.jsx(vt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),_.jsxs(vt,{type:"submit",disabled:M,className:"flex-1",children:[M?_.jsx(di,{className:"w-4 h-4 animate-spin"}):_.jsx(_4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(Vie,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(_4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function EHe({setting:t,onClick:e}){return _.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&_.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function AHe({setting:t,onClose:e}){const{data:n,isLoading:i}=bn({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>pt.getCloudSettingDetail(t.setting_id)});return _.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:_.jsx(ai,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:_.jsxs(Si,{className:"p-0 flex flex-col h-full",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),_.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(qn,{className:"w-5 h-5"})})]}),_.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?_.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap overflow-x-auto bg-bambu-dark p-4 rounded-lg",children:JSON.stringify(n,null,2)}):_.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),_.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:_.jsx(vt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function THe({settings:t}){const[e,n]=C.useState(new Set),[i,r]=C.useState(null),a=l=>[...l].sort((c,d)=>c.name.localeCompare(d.name)),s=l=>{n(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})},o=[{key:"filament",label:"Filament Presets",icon:pie,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:Lu,items:a(t.printer)},{key:"process",label:"Process Presets",icon:_G,items:a(t.process)}];return _.jsxs(_.Fragment,{children:[_.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:d,items:f})=>_.jsxs(ai,{children:[_.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx(d,{className:"w-5 h-5 text-bambu-green"}),_.jsx("span",{className:"text-lg font-semibold text-white",children:c}),_.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?_.jsx(Qne,{className:"w-5 h-5 text-bambu-gray"}):_.jsx(Rf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&_.jsx(Si,{className:"pt-0",children:_.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(p=>_.jsx(EHe,{setting:p,onClick:()=>r(p)},p.setting_id))})}),e.has(l)&&f.length===0&&_.jsx(Si,{className:"pt-0",children:_.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&_.jsx(AHe,{setting:i,onClose:()=>r(null)})]})}function CHe(){const t=ar(),{showToast:e}=dc(),{data:n,isLoading:i}=bn({queryKey:["cloudStatus"],queryFn:pt.getCloudStatus}),{data:r,isLoading:a,refetch:s}=bn({queryKey:["cloudSettings"],queryFn:()=>pt.getCloudSettings(),enabled:!!n?.is_authenticated,retry:!1,staleTime:1e3*60*5}),o=gn({mutationFn:pt.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),l=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return i?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-2",children:[_.jsx(UN,{className:"w-6 h-6 text-bambu-green"}),"Cloud Profiles"]}),_.jsx("p",{className:"text-bambu-gray",children:n?.is_authenticated?`Connected as ${n.email}`:"Manage your Bambu Cloud slicer presets"})]}),n?.is_authenticated&&_.jsxs("div",{className:"flex gap-2",children:[_.jsxs(vt,{variant:"secondary",onClick:()=>s(),disabled:a,children:[_.jsx(fS,{className:`w-4 h-4 ${a?"animate-spin":""}`}),"Refresh"]}),_.jsxs(vt,{variant:"secondary",onClick:()=>o.mutate(),disabled:o.isPending,children:[_.jsx(nre,{className:"w-4 h-4"}),"Logout"]})]})]}),n?.is_authenticated?a?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(di,{className:"w-8 h-8 text-bambu-green animate-spin"})}):r?_.jsx(THe,{settings:r}):_.jsx(ai,{children:_.jsxs(Si,{className:"py-8 text-center",children:[_.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),_.jsx(vt,{className:"mt-4",onClick:()=>s(),children:"Retry"})]})}):_.jsx(MHe,{onSuccess:l})]})}function RHe(){const t=C.useRef(null),e=C.useRef(null),n=ar(),[i,r]=C.useState(!1),a=C.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(c);let f=null;d.onopen=()=>{console.log("[WebSocket] Connected"),r(!0),f=window.setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4)},d.onmessage=p=>{try{const m=JSON.parse(p.data);s(m)}catch{}},d.onclose=p=>{console.log("[WebSocket] Closed",p.code,p.reason),f&&(clearInterval(f),f=null),r(!1),t.current=null,e.current=window.setTimeout(()=>{a()},3e3)},d.onerror=p=>{console.error("[WebSocket] Error",p),d.close()},t.current=d},[]),s=C.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],c=>({...c,...l.data}));break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);C.useEffect(()=>(a(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[a]);const o=C.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:i,sendMessage:o}}const NHe=new pne({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function PHe({children:t}){return RHe(),_.jsx(_.Fragment,{children:t})}function DHe(){return _.jsx(gae,{children:_.jsx(Mae,{children:_.jsx(mne,{client:NHe,children:_.jsx(PHe,{children:_.jsx(Ite,{children:_.jsx(hte,{children:_.jsxs(ru,{path:"/",element:_.jsx(_ae,{}),children:[_.jsx(ru,{index:!0,element:_.jsx(Bae,{})}),_.jsx(ru,{path:"archives",element:_.jsx(pEe,{})}),_.jsx(ru,{path:"queue",element:_.jsx(vEe,{})}),_.jsx(ru,{path:"stats",element:_.jsx(bHe,{})}),_.jsx(ru,{path:"cloud",element:_.jsx(CHe,{})}),_.jsx(ru,{path:"settings",element:_.jsx(wHe,{})})]})})})})})})})}yee.createRoot(document.getElementById("root")).render(_.jsx(C.StrictMode,{children:_.jsx(DHe,{})}));
diff --git a/static/index.html b/static/index.html
index c6578b658..427f1e679 100644
--- a/static/index.html
+++ b/static/index.html
@@ -7,7 +7,7 @@
-
+