From e8a11d273af66d9abe7c851a75e1346310b7813d Mon Sep 17 00:00:00 2001 From: Martin Ziegler Date: Wed, 3 Dec 2025 17:29:46 +0100 Subject: [PATCH] Wired air condition, speed and light buttons --- backend/app/services/bambu_mqtt.py | 148 ++++++++++++++++-- .../components/control/TemperatureColumn.tsx | 17 +- .../{index-DzdPY90c.js => index-BGXbFbC2.js} | 2 +- static/index.html | 2 +- 4 files changed, 149 insertions(+), 20 deletions(-) rename static/assets/{index-DzdPY90c.js => index-BGXbFbC2.js} (99%) diff --git a/backend/app/services/bambu_mqtt.py b/backend/app/services/bambu_mqtt.py index dbcb6b9d5..3a90b5bed 100644 --- a/backend/app/services/bambu_mqtt.py +++ b/backend/app/services/bambu_mqtt.py @@ -705,16 +705,65 @@ class BambuMQTTClient: if "left_nozzle_target_temper" in data and "nozzle_target" not in temps: temps["nozzle_target"] = float(data["left_nozzle_target_temper"]) if "chamber_temper" in data: - temps["chamber"] = float(data["chamber_temper"]) + chamber_val = float(data["chamber_temper"]) + logger.debug(f"[{self.serial_number}] chamber_temper raw value: {chamber_val}") + # Check if we recently set the target locally (within 5 seconds) + local_set_time = self.state.temperatures.get("_chamber_target_set_time", 0) + respect_local = (time.time() - local_set_time) < 5.0 + # H2D protocol: chamber_temper encoding indicates heater state + # - When > 500: encoded as (target * 65536 + current) - heater is ON + # - When < 500: direct Celsius current temp only - heater is OFF + if -50 < chamber_val < 100: + # Direct value = heater is OFF + temps["chamber"] = chamber_val + if not respect_local: + temps["chamber_target"] = 0.0 # Heater off means target = 0 + logger.debug(f"[{self.serial_number}] chamber_temper direct value: {chamber_val}°C (heater OFF)") + else: + logger.debug(f"[{self.serial_number}] chamber_temper {chamber_val} out of direct range") + # Try to decode if it looks like an encoded value + if chamber_val > 500: + mqtt_target = int(chamber_val) // 65536 + current = int(chamber_val) % 65536 + logger.debug(f"[{self.serial_number}] chamber_temper decoded: mqtt_target={mqtt_target}, current={current}, respect_local={respect_local}") + if -50 < current < 100: + temps["chamber"] = float(current) + # Store decoded target for later use, but DON'T set chamber_heating here! + # Heating state will be calculated later after parsing ctc.info.target (explicit target) + # which is the authoritative source the slicer uses. + if not respect_local: + if 0 <= mqtt_target <= 60: + # Store as "decoded" target - may be overridden by explicit target fields + temps["_chamber_decoded_target"] = float(mqtt_target) # Chamber target temperature (set by print file or display) if "mc_target_cham" in data: - temps["chamber_target"] = float(data["mc_target_cham"]) - # H2D series: Chamber temp is in info.temp (directly in °C) + mc_target = float(data["mc_target_cham"]) + logger.debug(f"[{self.serial_number}] mc_target_cham raw value: {mc_target}") + # Filter out encoded/invalid values - valid chamber target is 0-60°C + if 0 <= mc_target <= 60: + temps["chamber_target"] = mc_target + # H2D series: Chamber temp is in info.temp (may be encoded or direct °C) + # NOTE: Don't set chamber_heating here - let ctc.info.target or fallback logic handle it + # The encoded target in info.temp may be stale (slicer uses ctc.info.target as source of truth) try: if "info" in data and isinstance(data["info"], dict): info_temp = data["info"].get("temp") if info_temp is not None and "chamber" not in temps: - temps["chamber"] = float(info_temp) + # Check for encoded value (target * 65536 + current) + if info_temp > 500: + # Decode: extract current temperature and target + target = info_temp // 65536 + current = info_temp % 65536 + temps["chamber"] = float(current) + # Store decoded target as fallback (may be overridden by ctc.info.target) + if "_chamber_decoded_target" not in temps: + temps["_chamber_decoded_target"] = float(target) + logger.debug(f"[{self.serial_number}] info.temp encoded: {info_temp} -> current={current}, decoded_target={target}") + elif -50 < info_temp < 100: + # Valid direct temperature - heater is OFF + temps["chamber"] = float(info_temp) + temps["chamber_target"] = 0.0 # Direct value means heater off + logger.debug(f"[{self.serial_number}] info.temp direct: {info_temp}°C (heater OFF)") # H2D series: Dual extruder temps are in device.extruder.info array # Temperature values are encoded as fixed-point (value / 65536 = °C) if "device" in data and isinstance(data["device"], dict): @@ -794,28 +843,90 @@ class BambuMQTTClient: if new_mode != self.state.airduct_mode: logger.info(f"[{self.serial_number}] airduct_mode changed: {self.state.airduct_mode} -> {new_mode}") self.state.airduct_mode = new_mode + # Parse chamber temp - may be encoded as (target*65536+current) when > 500 + # Check if we recently set the target locally (within 5 seconds) + local_set_time = self.state.temperatures.get("_chamber_target_set_time", 0) + respect_local_target = (time.time() - local_set_time) < 5.0 + + # Log ctc_info contents for debugging + if ctc_info: + logger.debug(f"[{self.serial_number}] ctc_info keys: {list(ctc_info.keys())}") + + # FIRST: Parse explicit ctc.info.target if available - this is the authoritative target + # (what the slicer shows). This OVERRIDES any previously decoded target. + explicit_target = None + if "target" in ctc_info: + target_val = ctc_info["target"] + logger.debug(f"[{self.serial_number}] ctc_info.target explicit value: {target_val}, respect_local={respect_local_target}") + # Filter out invalid values (valid chamber target is 0-60°C) + if 0 <= target_val <= 60 and not respect_local_target: + explicit_target = float(target_val) + temps["chamber_target"] = explicit_target # Override any previous value + logger.debug(f"[{self.serial_number}] Setting chamber_target from ctc_info.target: {explicit_target}") + + # Parse chamber temp from ctc.info.temp - may be encoded if "temp" in ctc_info and "chamber" not in temps: - temps["chamber"] = float(ctc_info["temp"]) - # Parse chamber target from ctc.info.target if available - if "target" in ctc_info and "chamber_target" not in temps: - temps["chamber_target"] = float(ctc_info["target"]) - # Parse chamber heating state from temp encoding - # temp > 500 means encoded (target*65536+current), heating = target > 0 AND current < target - if "temp" in ctc_info: temp_val = ctc_info["temp"] + logger.debug(f"[{self.serial_number}] ctc_info.temp raw value: {temp_val}") if temp_val > 500: - target = temp_val // 65536 + # Encoded value: decode target and current + decoded_target = temp_val // 65536 current = temp_val % 65536 - temps["chamber_heating"] = target > 0 and current < target + temps["chamber"] = float(current) + logger.debug(f"[{self.serial_number}] ctc_info.temp decoded: target={decoded_target}, current={current}, explicit_target={explicit_target}") + + # Determine which target to use for heating state: + # Priority: local target > explicit target > decoded target + if respect_local_target: + local_target = self.state.temperatures.get("chamber_target", 0) + temps["chamber_heating"] = local_target > 0 and current < local_target + elif explicit_target is not None: + # Use explicit ctc.info.target - this is what slicer sees + temps["chamber_heating"] = explicit_target > 0 and current < explicit_target + else: + # Fallback to decoded target only if no explicit target available + if not respect_local_target and "chamber_target" not in temps: + temps["chamber_target"] = float(decoded_target) + temps["chamber_heating"] = decoded_target > 0 and current < decoded_target else: + # Direct value (not encoded) - heater is OFF + temps["chamber"] = float(temp_val) temps["chamber_heating"] = False except Exception as e: logger.warning(f"[{self.serial_number}] Error parsing H2D temperatures: {e}") if temps: + # Handle chamber_target: prefer explicit over decoded + if "_chamber_decoded_target" in temps and "chamber_target" not in temps: + # No explicit target available, use decoded target from chamber_temper + temps["chamber_target"] = temps["_chamber_decoded_target"] + # Remove internal temp key before merging + temps.pop("_chamber_decoded_target", None) + # Merge new temps into existing, preserving valid values when new ones are filtered out for key, value in temps.items(): self.state.temperatures[key] = value + # Calculate chamber_heating after all targets are known + # Priority: local target (if recent) > explicit target (chamber_target) > 0 + if "chamber" in temps and "chamber_heating" not in temps: + current = self.state.temperatures.get("chamber", 0) + local_set_time = self.state.temperatures.get("_chamber_target_set_time", 0) + respect_local = (time.time() - local_set_time) < 5.0 + + if respect_local: + # Use locally-set target + target = self.state.temperatures.get("chamber_target", 0) + else: + # Use explicit/decoded target from MQTT + target = self.state.temperatures.get("chamber_target", 0) + + self.state.temperatures["chamber_heating"] = target > 0 and current < target + logger.debug(f"[{self.serial_number}] Chamber heating calculated: target={target}, current={current}, heating={self.state.temperatures['chamber_heating']}, respect_local={respect_local}") + + # Debug: log chamber value if it was updated + if "chamber" in temps: + logger.debug(f"[{self.serial_number}] Chamber temp updated to: {self.state.temperatures.get('chamber')}, target: {self.state.temperatures.get('chamber_target')}, heating: {self.state.temperatures.get('chamber_heating')}") + # Parse HMS (Health Management System) errors if "hms" in data: hms_list = data["hms"] @@ -1815,7 +1926,16 @@ class BambuMQTTClient: True if command was sent, False otherwise """ # M141 sets chamber temperature - return self.send_gcode(f"M141 S{target}") + result = self.send_gcode(f"M141 S{target}") + # Track chamber target locally (MQTT reports encoded values that need filtering) + if result: + self.state.temperatures["chamber_target"] = float(target) + self.state.temperatures["_chamber_target_set_time"] = time.time() + # Update heating state immediately based on new target + current_temp = self.state.temperatures.get("chamber", 0) + self.state.temperatures["chamber_heating"] = target > 0 and current_temp < target + logger.info(f"[{self.serial_number}] Tracking chamber target locally: {target}°C (heating={self.state.temperatures['chamber_heating']})") + return result def set_print_speed(self, mode: int) -> bool: """Set the print speed mode. diff --git a/frontend/src/components/control/TemperatureColumn.tsx b/frontend/src/components/control/TemperatureColumn.tsx index e8df95e14..e28a53571 100644 --- a/frontend/src/components/control/TemperatureColumn.tsx +++ b/frontend/src/components/control/TemperatureColumn.tsx @@ -203,14 +203,23 @@ export function TemperatureColumn({ printer, status, disabled = false }: Tempera {renderTargetTemp('chamber', temps.chamber_target ?? 0)} - {/* Air Condition - full width button */} + {/* Air Condition - full width button with mode indicator */} {/* Speed & Lamp - half width each */} diff --git a/static/assets/index-DzdPY90c.js b/static/assets/index-BGXbFbC2.js similarity index 99% rename from static/assets/index-DzdPY90c.js rename to static/assets/index-BGXbFbC2.js index 198d780ad..918938c9f 100644 --- a/static/assets/index-DzdPY90c.js +++ b/static/assets/index-BGXbFbC2.js @@ -8591,7 +8591,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Gg(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. - `},X8e={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 K8e(t){let{announcements:e=X8e,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=q8e}=t;const{announce:a,announcement:s}=$8e(),o=pv("DndLiveRegion"),[l,c]=E.useState(!1);if(E.useEffect(()=>{c(!0)},[]),G8e(E.useMemo(()=>({onDragStart(f){let{active:m}=f;a(e.onDragStart({active:m}))},onDragMove(f){let{active:m,over:g}=f;e.onDragMove&&a(e.onDragMove({active:m,over:g}))},onDragOver(f){let{active:m,over:g}=f;a(e.onDragOver({active:m,over:g}))},onDragEnd(f){let{active:m,over:g}=f;a(e.onDragEnd({active:m,over:g}))},onDragCancel(f){let{active:m,over:g}=f;a(e.onDragCancel({active:m,over:g}))}}),[a,e])),!l)return null;const u=ui.createElement(ui.Fragment,null,ui.createElement(H8e,{id:i,value:r.draggable}),ui.createElement(V8e,{id:o,announcement:s}));return n?Yl.createPortal(u,n):u}var nr;(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"})(nr||(nr={}));function jS(){}function B$(t,e){return E.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Y8e(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const wo=Object.freeze({x:0,y:0});function _J(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function SJ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function Z8e(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function H$(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 wJ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function V$(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 Q8e=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=V$(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=_J(V$(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(SJ)},J8e=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=H$(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=H$(l),u=r.reduce((m,g,b)=>m+_J(c[b],g),0),f=Number((u/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(SJ)};function e6e(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=e6e(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(Z8e)};function n6e(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function MJ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:wo}function i6e(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 r6e=i6e(1);function a6e(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 s6e(t,e,n){const i=a6e(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)),u=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:u,height:f,top:c,right:l+u,bottom:c+f,left:l}}const o6e={ignoreTransform:!1};function jm(t,e){e===void 0&&(e=o6e);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:u}=Ga(t).getComputedStyle(t);c&&(n=s6e(n,c,u))}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 $$(t){return jm(t,{ignoreTransform:!0})}function l6e(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function c6e(t,e){return e===void 0&&(e=Ga(t).getComputedStyle(t)),e.position==="fixed"}function u6e(t,e){e===void 0&&(e=Ga(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 dM(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(ZO(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!fv(r)||vJ(r)||n.includes(r))return n;const a=Ga(t).getComputedStyle(r);return r!==t&&u6e(r,a)&&n.push(r),c6e(r,a)?n:i(r.parentNode)}return t?i(t):n}function EJ(t){const[e]=dM(t,1);return e??null}function aN(t){return!uM||!t?null:Lm(t)?t:YO(t)?ZO(t)||t===Im(t).scrollingElement?window:fv(t)?t:null:null}function AJ(t){return Lm(t)?t.scrollX:t.scrollLeft}function TJ(t){return Lm(t)?t.scrollY:t.scrollTop}function pP(t){return{x:AJ(t),y:TJ(t)}}var Mr;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(Mr||(Mr={}));function CJ(t){return!uM||!t?!1:t===document.scrollingElement}function NJ(t){const e={x:0,y:0},n=CJ(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 d6e={x:.2,y:.2};function f6e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=d6e);const{isTop:c,isBottom:u,isLeft:f,isRight:m}=NJ(t),g={x:0,y:0},b={x:0,y:0},y={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+y.height?(g.y=Mr.Backward,b.y=i*Math.abs((e.top+y.height-a)/y.height)):!u&&l>=e.bottom-y.height&&(g.y=Mr.Forward,b.y=i*Math.abs((e.bottom-y.height-l)/y.height)),!m&&o>=e.right-y.width?(g.x=Mr.Forward,b.x=i*Math.abs((e.right-y.width-o)/y.width)):!f&&s<=e.left+y.width&&(g.x=Mr.Backward,b.x=i*Math.abs((e.left+y.width-s)/y.width)),{direction:g,speed:b}}function h6e(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 RJ(t){return t.reduce((e,n)=>Ip(e,pP(n)),wo)}function p6e(t){return t.reduce((e,n)=>e+AJ(n),0)}function m6e(t){return t.reduce((e,n)=>e+TJ(n),0)}function g6e(t,e){if(e===void 0&&(e=jm),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);EJ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const x6e=[["x",["left","right"],p6e],["y",["top","bottom"],m6e]];class eL{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=dM(n),r=RJ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of x6e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),u=r[a]-c;return this.rect[l]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Rx{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 v6e(t){const{EventTarget:e}=Ga(t);return t instanceof e?t:Im(t)}function sN(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 Ls;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Ls||(Ls={}));function G$(t){t.preventDefault()}function b6e(t){t.stopPropagation()}var _n;(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"})(_n||(_n={}));const PJ={start:[_n.Space,_n.Enter],cancel:[_n.Esc],end:[_n.Space,_n.Enter,_n.Tab]},y6e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case _n.Right:return{...n,x:n.x+25};case _n.Left:return{...n,x:n.x-25};case _n.Down:return{...n,y:n.y+25};case _n.Up:return{...n,y:n.y-25}}};class tL{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 Rx(Im(n)),this.windowListeners=new Rx(Ga(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ls.Resize,this.handleCancel),this.windowListeners.add(Ls.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ls.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&g6e(i),n(wo)}handleKeyDown(e){if(JO(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=PJ,coordinateGetter:s=y6e,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,u=c?{x:c.left,y:c.top}:wo;this.referenceCoordinates||(this.referenceCoordinates=u);const f=s(e,{active:n,context:i.current,currentCoordinates:u});if(f){const m=M0(f,u),g={x:0,y:0},{scrollableAncestors:b}=i.current;for(const y of b){const v=e.code,{isTop:x,isRight:M,isLeft:w,isBottom:A,maxScroll:T,minScroll:R}=NJ(y),N=h6e(y),j={x:Math.min(v===_n.Right?N.right-N.width/2:N.right,Math.max(v===_n.Right?N.left:N.left+N.width/2,f.x)),y:Math.min(v===_n.Down?N.bottom-N.height/2:N.bottom,Math.max(v===_n.Down?N.top:N.top+N.height/2,f.y))},C=v===_n.Right&&!M||v===_n.Left&&!w,k=v===_n.Down&&!A||v===_n.Up&&!x;if(C&&j.x!==f.x){const F=y.scrollLeft+m.x,I=v===_n.Right&&F<=T.x||v===_n.Left&&F>=R.x;if(I&&!m.y){y.scrollTo({left:F,behavior:o});return}I?g.x=y.scrollLeft-F:g.x=v===_n.Right?y.scrollLeft-T.x:y.scrollLeft-R.x,g.x&&y.scrollBy({left:-g.x,behavior:o});break}else if(k&&j.y!==f.y){const F=y.scrollTop+m.y,I=v===_n.Down&&F<=T.y||v===_n.Up&&F>=R.y;if(I&&!m.x){y.scrollTo({top:F,behavior:o});return}I?g.y=y.scrollTop-F:g.y=v===_n.Down?y.scrollTop-T.y:y.scrollTop-R.y,g.y&&y.scrollBy({top:-g.y,behavior:o});break}}this.handleMove(e,Ip(M0(f,this.referenceCoordinates),g))}}}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()}}tL.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=PJ,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 W$(t){return!!(t&&"distance"in t)}function q$(t){return!!(t&&"delay"in t)}class nL{constructor(e,n,i){var r;i===void 0&&(i=v6e(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=Im(s),this.documentListeners=new Rx(this.document),this.listeners=new Rx(i),this.windowListeners=new Rx(Ga(s)),this.initialCoordinates=(r=hP(a))!=null?r:wo,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(Ls.Resize,this.handleCancel),this.windowListeners.add(Ls.DragStart,G$),this.windowListeners.add(Ls.VisibilityChange,this.handleCancel),this.windowListeners.add(Ls.ContextMenu,G$),this.documentListeners.add(Ls.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(q$(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(W$(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(Ls.Click,b6e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ls.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=hP(e))!=null?n:wo,c=M0(r,l);if(!i&&o){if(W$(o)){if(o.tolerance!=null&&sN(c,o.tolerance))return this.handleCancel();if(sN(c,o.distance))return this.handleStart()}if(q$(o)&&sN(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===_n.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const _6e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class iL extends nL{constructor(e){const{event:n}=e,i=Im(n.target);super(e,_6e,i)}}iL.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 S6e={move:{name:"mousemove"},end:{name:"mouseup"}};var mP;(function(t){t[t.RightClick=2]="RightClick"})(mP||(mP={}));class w6e extends nL{constructor(e){super(e,S6e,Im(e.event.target))}}w6e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===mP.RightClick?!1:(i?.({event:n}),!0)}}];const oN={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class M6e extends nL{constructor(e){super(e,oN)}static setup(){return window.addEventListener(oN.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(oN.move.name,e)};function e(){}}}M6e.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 Px;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(Px||(Px={}));var US;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(US||(US={}));function E6e(t){let{acceleration:e,activator:n=Px.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=US.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:f,threshold:m}=t;const g=T6e({delta:f,disabled:!a}),[b,y]=j8e(),v=E.useRef({x:0,y:0}),x=E.useRef({x:0,y:0}),M=E.useMemo(()=>{switch(n){case Px.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Px.DraggableRect:return r}},[n,r,l]),w=E.useRef(null),A=E.useCallback(()=>{const R=w.current;if(!R)return;const N=v.current.x*x.current.x,j=v.current.y*x.current.y;R.scrollBy(N,j)},[]),T=E.useMemo(()=>o===US.TreeOrder?[...c].reverse():c,[o,c]);E.useEffect(()=>{if(!a||!c.length||!M){y();return}for(const R of T){if(i?.(R)===!1)continue;const N=c.indexOf(R),j=u[N];if(!j)continue;const{direction:C,speed:k}=f6e(R,j,M,e,m);for(const F of["x","y"])g[F][C[F]]||(k[F]=0,C[F]=0);if(k.x>0||k.y>0){y(),w.current=R,b(A,s),v.current=k,x.current=C;return}}v.current={x:0,y:0},x.current={x:0,y:0},y()},[e,A,i,y,a,s,JSON.stringify(M),JSON.stringify(g),b,c,T,u,JSON.stringify(m)])}const A6e={x:{[Mr.Backward]:!1,[Mr.Forward]:!1},y:{[Mr.Backward]:!1,[Mr.Forward]:!1}};function T6e(t){let{delta:e,disabled:n}=t;const i=fP(e);return hv(r=>{if(n||!i||!r)return A6e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[Mr.Backward]:r.x[Mr.Backward]||a.x===-1,[Mr.Forward]:r.x[Mr.Forward]||a.x===1},y:{[Mr.Backward]:r.y[Mr.Backward]||a.y===-1,[Mr.Forward]:r.y[Mr.Forward]||a.y===1}}},[n,e,i])}function C6e(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 N6e(t,e){return E.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 A0;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(A0||(A0={}));var gP;(function(t){t.Optimized="optimized"})(gP||(gP={}));const X$=new Map;function R6e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=E.useState(null),{frequency:o,measure:l,strategy:c}=r,u=E.useRef(t),f=v(),m=w0(f),g=E.useCallback(function(x){x===void 0&&(x=[]),!m.current&&s(M=>M===null?x:M.concat(x.filter(w=>!M.includes(w))))},[m]),b=E.useRef(null),y=hv(x=>{if(f&&!n)return X$;if(!x||x===X$||u.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 A=w.node.current,T=A?new eL(l(A),A):null;w.rect.current=T,T&&M.set(w.id,T)}return M}return x},[t,a,n,f,l]);return E.useEffect(()=>{u.current=t},[t]),E.useEffect(()=>{f||g()},[n,f]),E.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),E.useEffect(()=>{f||typeof o!="number"||b.current!==null||(b.current=setTimeout(()=>{g(),b.current=null},o))},[o,f,g,...i]),{droppableRects:y,measureDroppableContainers:g,measuringScheduled:a!=null};function v(){switch(c){case A0.Always:return!1;case A0.BeforeDragging:return n;default:return!n}}}function kJ(t,e){return hv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function P6e(t,e){return kJ(t,e)}function k6e(t){let{callback:e,disabled:n}=t;const i=QO(e),r=E.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return E.useEffect(()=>()=>r?.disconnect(),[r]),r}function fM(t){let{callback:e,disabled:n}=t;const i=QO(e),r=E.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return E.useEffect(()=>()=>r?.disconnect(),[r]),r}function D6e(t){return new eL(jm(t),t)}function K$(t,e,n){e===void 0&&(e=D6e);const[i,r]=E.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const u=e(t);return JSON.stringify(l)===JSON.stringify(u)?l:u})}const s=k6e({callback(l){if(t)for(const c of l){const{type:u,target:f}=c;if(u==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=fM({callback:a});return al(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function O6e(t){const e=kJ(t);return MJ(t,e)}const Y$=[];function L6e(t){const e=E.useRef(t),n=hv(i=>t?i&&i!==Y$&&t&&e.current&&t.parentNode===e.current.parentNode?i:dM(t):Y$,[t]);return E.useEffect(()=>{e.current=t},[t]),n}function I6e(t){const[e,n]=E.useState(null),i=E.useRef(t),r=E.useCallback(a=>{const s=aN(a.target);s&&n(o=>o?(o.set(s,pP(s)),new Map(o)):null)},[]);return E.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=aN(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,pP(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=aN(l);c?.removeEventListener("scroll",r)})}},[r,t]),E.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>Ip(a,s),wo):RJ(t):wo,[t,e])}function Z$(t,e){e===void 0&&(e=[]);const n=E.useRef(null);return E.useEffect(()=>{n.current=null},e),E.useEffect(()=>{const i=t!==wo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?M0(t,n.current):wo}function j6e(t){E.useEffect(()=>{if(!uM)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 U6e(t,e){return E.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function DJ(t){return E.useMemo(()=>t?l6e(t):null,[t])}const Q$=[];function F6e(t,e){e===void 0&&(e=jm);const[n]=t,i=DJ(n?Ga(n):null),[r,a]=E.useState(Q$);function s(){a(()=>t.length?t.map(l=>CJ(l)?i:new eL(e(l),l)):Q$)}const o=fM({callback:s});return al(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function z6e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return fv(e)?e:t}function B6e(t){let{measure:e}=t;const[n,i]=E.useState(null),r=E.useCallback(c=>{for(const{target:u}of c)if(fv(u)){i(f=>{const m=e(u);return f?{...f,width:m.width,height:m.height}:m});break}},[e]),a=fM({callback:r}),s=E.useCallback(c=>{const u=z6e(c);a?.disconnect(),u&&a?.observe(u),i(u?e(u):null)},[e,a]),[o,l]=IS(s);return E.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const H6e=[{sensor:iL,options:{}},{sensor:tL,options:{}}],V6e={current:{}},C_={draggable:{measure:$$},droppable:{measure:$$,strategy:A0.WhileDragging,frequency:gP.Optimized},dragOverlay:{measure:jm}};class kx 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 $6e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new kx,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:jS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:C_,measureDroppableContainers:jS,windowRect:null,measuringScheduled:!1},G6e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:jS,draggableNodes:new Map,over:null,measureDroppableContainers:jS},hM=E.createContext(G6e),OJ=E.createContext($6e);function W6e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new kx}}}function q6e(t,e){switch(e.type){case nr.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case nr.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 nr.DragEnd:case nr.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case nr.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new kx(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case nr.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 kx(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case nr.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new kx(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function X6e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=E.useContext(hM),a=fP(i),s=fP(n?.id);return E.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!JO(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 u of[l.current,c.current]){if(!u)continue;const f=z8e(u);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function K6e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function Y6e(t){return E.useMemo(()=>({draggable:{...C_.draggable,...t?.draggable},droppable:{...C_.droppable,...t?.droppable},dragOverlay:{...C_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Z6e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=E.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;al(()=>{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 u=n(c),f=MJ(u,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const m=EJ(c);m&&m.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const LJ=E.createContext({...wo,scaleX:1,scaleY:1});var Mu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Mu||(Mu={}));const Q6e=E.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:u=H6e,collisionDetection:f=t6e,measuring:m,modifiers:g,...b}=e;const y=E.useReducer(q6e,void 0,W6e),[v,x]=y,[M,w]=W8e(),[A,T]=E.useState(Mu.Uninitialized),R=A===Mu.Initialized,{draggable:{active:N,nodes:j,translate:C},droppable:{containers:k}}=v,F=N!=null?j.get(N):null,I=E.useRef({initial:null,translated:null}),W=E.useMemo(()=>{var Oe;return N!=null?{id:N,data:(Oe=F?.data)!=null?Oe:V6e,rect:I}:null},[N,F]),O=E.useRef(null),[H,V]=E.useState(null),[$,K]=E.useState(null),Y=w0(b,Object.values(b)),se=pv("DndDescribedBy",s),B=E.useMemo(()=>k.getEnabled(),[k]),X=Y6e(m),{droppableRects:ae,measureDroppableContainers:ce,measuringScheduled:xe}=R6e(B,{dragging:R,dependencies:[C.x,C.y],config:X.droppable}),ee=C6e(j,N),ve=E.useMemo(()=>$?hP($):null,[$]),Pe=fe(),pe=P6e(ee,X.draggable.measure);Z6e({activeNode:N!=null?j.get(N):null,config:Pe.layoutShiftCompensation,initialRect:pe,measure:X.draggable.measure});const we=K$(ee,X.draggable.measure,pe),ze=K$(ee?ee.parentElement:null),ue=E.useRef({activatorEvent:null,active:null,activeNode:ee,collisionRect:null,collisions:null,droppableRects:ae,draggableNodes:j,draggingNode:null,draggingNodeRect:null,droppableContainers:k,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ht=k.getNodeFor((n=ue.current.over)==null?void 0:n.id),z=B6e({measure:X.dragOverlay.measure}),q=(i=z.nodeRef.current)!=null?i:ee,re=R?(r=z.rect)!=null?r:we:null,J=!!(z.nodeRef.current&&z.rect),te=O6e(J?null:we),oe=DJ(q?Ga(q):null),ke=L6e(R?ht??ee:null),Ne=F6e(ke),ne=K6e(g,{transform:{x:C.x-te.x,y:C.y-te.y,scaleX:1,scaleY:1},activatorEvent:$,active:W,activeNodeRect:we,containerNodeRect:ze,draggingNodeRect:re,over:ue.current.over,overlayNodeRect:z.rect,scrollableAncestors:ke,scrollableAncestorRects:Ne,windowRect:oe}),U=ve?Ip(ve,C):null,L=I6e(ke),Z=Z$(L),me=Z$(L,[we]),be=Ip(ne,Z),he=re?r6e(re,ne):null,Ze=W&&he?f({active:W,collisionRect:he,droppableRects:ae,droppableContainers:B,pointerCoordinates:U}):null,Le=wJ(Ze,"id"),[Xe,st]=E.useState(null),Ie=J?ne:Ip(ne,me),Re=n6e(Ie,(a=Xe?.rect)!=null?a:null,we),pt=E.useRef(null),nt=E.useCallback((Oe,Me)=>{let{sensor:ge,options:Be}=Me;if(O.current==null)return;const ct=j.get(O.current);if(!ct)return;const _t=Oe.nativeEvent,Rt=new ge({active:O.current,activeNode:ct,event:_t,options:Be,context:ue,onAbort(Dt){if(!j.get(Dt))return;const{onDragAbort:qn}=Y.current,pr={id:Dt};qn?.(pr),M({type:"onDragAbort",event:pr})},onPending(Dt,Rn,qn,pr){if(!j.get(Dt))return;const{onDragPending:mr}=Y.current,Rr={id:Dt,constraint:Rn,initialCoordinates:qn,offset:pr};mr?.(Rr),M({type:"onDragPending",event:Rr})},onStart(Dt){const Rn=O.current;if(Rn==null)return;const qn=j.get(Rn);if(!qn)return;const{onDragStart:pr}=Y.current,Zi={activatorEvent:_t,active:{id:Rn,data:qn.data,rect:I}};Yl.unstable_batchedUpdates(()=>{pr?.(Zi),T(Mu.Initializing),x({type:nr.DragStart,initialCoordinates:Dt,active:Rn}),M({type:"onDragStart",event:Zi}),V(pt.current),K(_t)})},onMove(Dt){x({type:nr.DragMove,coordinates:Dt})},onEnd:ln(nr.DragEnd),onCancel:ln(nr.DragCancel)});pt.current=Rt;function ln(Dt){return async function(){const{active:qn,collisions:pr,over:Zi,scrollAdjustedTranslate:mr}=ue.current;let Rr=null;if(qn&&mr){const{cancelDrop:Wr}=Y.current;Rr={activatorEvent:_t,active:qn,collisions:pr,delta:mr,over:Zi},Dt===nr.DragEnd&&typeof Wr=="function"&&await Promise.resolve(Wr(Rr))&&(Dt=nr.DragCancel)}O.current=null,Yl.unstable_batchedUpdates(()=>{x({type:Dt}),T(Mu.Uninitialized),st(null),V(null),K(null),pt.current=null;const Wr=Dt===nr.DragEnd?"onDragEnd":"onDragCancel";if(Rr){const Li=Y.current[Wr];Li?.(Rr),M({type:Wr,event:Rr})}})}}},[j]),tt=E.useCallback((Oe,Me)=>(ge,Be)=>{const ct=ge.nativeEvent,_t=j.get(Be);if(O.current!==null||!_t||ct.dndKit||ct.defaultPrevented)return;const Rt={active:_t};Oe(ge,Me.options,Rt)===!0&&(ct.dndKit={capturedBy:Me.sensor},O.current=Be,nt(ge,Me))},[j,nt]),ut=N6e(u,tt);j6e(u),al(()=>{we&&A===Mu.Initializing&&T(Mu.Initialized)},[we,A]),E.useEffect(()=>{const{onDragMove:Oe}=Y.current,{active:Me,activatorEvent:ge,collisions:Be,over:ct}=ue.current;if(!Me||!ge)return;const _t={active:Me,activatorEvent:ge,collisions:Be,delta:{x:be.x,y:be.y},over:ct};Yl.unstable_batchedUpdates(()=>{Oe?.(_t),M({type:"onDragMove",event:_t})})},[be.x,be.y]),E.useEffect(()=>{const{active:Oe,activatorEvent:Me,collisions:ge,droppableContainers:Be,scrollAdjustedTranslate:ct}=ue.current;if(!Oe||O.current==null||!Me||!ct)return;const{onDragOver:_t}=Y.current,Rt=Be.get(Le),ln=Rt&&Rt.rect.current?{id:Rt.id,rect:Rt.rect.current,data:Rt.data,disabled:Rt.disabled}:null,Dt={active:Oe,activatorEvent:Me,collisions:ge,delta:{x:ct.x,y:ct.y},over:ln};Yl.unstable_batchedUpdates(()=>{st(ln),_t?.(Dt),M({type:"onDragOver",event:Dt})})},[Le]),al(()=>{ue.current={activatorEvent:$,active:W,activeNode:ee,collisionRect:he,collisions:Ze,droppableRects:ae,draggableNodes:j,draggingNode:q,draggingNodeRect:re,droppableContainers:k,over:Xe,scrollableAncestors:ke,scrollAdjustedTranslate:be},I.current={initial:re,translated:he}},[W,ee,Ze,he,j,q,re,ae,k,Xe,ke,be]),E6e({...Pe,delta:C,draggingRect:he,pointerCoordinates:U,scrollableAncestors:ke,scrollableAncestorRects:Ne});const de=E.useMemo(()=>({active:W,activeNode:ee,activeNodeRect:we,activatorEvent:$,collisions:Ze,containerNodeRect:ze,dragOverlay:z,draggableNodes:j,droppableContainers:k,droppableRects:ae,over:Xe,measureDroppableContainers:ce,scrollableAncestors:ke,scrollableAncestorRects:Ne,measuringConfiguration:X,measuringScheduled:xe,windowRect:oe}),[W,ee,we,$,Ze,ze,z,j,k,ae,Xe,ce,ke,Ne,X,xe,oe]),it=E.useMemo(()=>({activatorEvent:$,activators:ut,active:W,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:x,draggableNodes:j,over:Xe,measureDroppableContainers:ce}),[$,ut,W,we,x,se,j,Xe,ce]);return ui.createElement(yJ.Provider,{value:w},ui.createElement(hM.Provider,{value:it},ui.createElement(OJ.Provider,{value:de},ui.createElement(LJ.Provider,{value:Re},c)),ui.createElement(X6e,{disabled:o?.restoreFocus===!1})),ui.createElement(K8e,{...o,hiddenTextDescribedById:se}));function fe(){const Oe=H?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=R&&!Oe&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),J6e=E.createContext(null),J$="button",eVe="Draggable";function tVe(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=pv(eVe),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:f,over:m}=E.useContext(hM),{role:g=J$,roleDescription:b="draggable",tabIndex:y=0}=r??{},v=l?.id===e,x=E.useContext(v?LJ:J6e),[M,w]=IS(),[A,T]=IS(),R=U6e(s,e),N=w0(n);al(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:A,data:N}),()=>{const C=f.get(e);C&&C.key===a&&f.delete(e)}),[f,e]);const j=E.useMemo(()=>({role:g,tabIndex:y,"aria-disabled":i,"aria-pressed":v&&g===J$?!0:void 0,"aria-roledescription":b,"aria-describedby":u.draggable}),[i,g,y,v,b,u.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:j,isDragging:v,listeners:i?void 0:R,node:M,over:m,setNodeRef:w,setActivatorNodeRef:T,transform:x}}function nVe(){return E.useContext(OJ)}const iVe="Droppable",rVe={timeout:25};function aVe(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=pv(iVe),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=E.useContext(hM),u=E.useRef({disabled:n}),f=E.useRef(!1),m=E.useRef(null),g=E.useRef(null),{disabled:b,updateMeasurementsFor:y,timeout:v}={...rVe,...r},x=w0(y??i),M=E.useCallback(()=>{if(!f.current){f.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{c(Array.isArray(x.current)?x.current:[x.current]),g.current=null},v)},[v]),w=fM({callback:M,disabled:b||!s}),A=E.useCallback((j,C)=>{w&&(C&&(w.unobserve(C),f.current=!1),j&&w.observe(j))},[w]),[T,R]=IS(A),N=w0(e);return E.useEffect(()=>{!w||!T.current||(w.disconnect(),f.current=!1,w.observe(T.current))},[T,w]),E.useEffect(()=>(o({type:nr.RegisterDroppable,element:{id:i,key:a,disabled:n,node:T,rect:m,data:N}}),()=>o({type:nr.UnregisterDroppable,key:a,id:i})),[i]),E.useEffect(()=>{n!==u.current.disabled&&(o({type:nr.SetDroppableDisabled,id:i,key:a,disabled:n}),u.current.disabled=n)},[i,a,n,o]),{active:s,rect:m,isOver:l?.id===i,node:T,over:l,setNodeRef:R}}function rL(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function sVe(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function i_(t){return t!==null&&t>=0}function oVe(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=rL(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}},IJ="Sortable",jJ=ui.createContext({activeIndex:-1,containerId:IJ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:aL,disabled:{draggable:!1,droppable:!1}});function cVe(t){let{children:e,id:n,items:i,strategy:r=aL,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:u}=nVe(),f=pv(IJ,n),m=o.rect!==null,g=E.useMemo(()=>i.map(R=>typeof R=="object"&&"id"in R?R.id:R),[i]),b=s!=null,y=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,x=E.useRef(g),M=!oVe(g,x.current),w=v!==-1&&y===-1||M,A=lVe(a);al(()=>{M&&b&&u(g)},[M,g,b,u]),E.useEffect(()=>{x.current=g},[g]);const T=E.useMemo(()=>({activeIndex:y,containerId:f,disabled:A,disableTransforms:w,items:g,overIndex:v,useDragOverlay:m,sortedRects:sVe(g,l),strategy:r}),[y,f,A.draggable,A.droppable,w,g,v,l,m,r]);return ui.createElement(jJ.Provider,{value:T},e)}const uVe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return rL(n,i,r).indexOf(e)},dVe=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},fVe={duration:200,easing:"ease"},UJ="transform",hVe=E0.Transition.toString({property:UJ,duration:0,easing:"linear"}),pVe={roleDescription:"sortable"};function mVe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=E.useState(null),o=E.useRef(n);return al(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=jm(i.current,{ignoreTransform:!0}),u={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(u.x||u.y)&&s(u)}}n!==o.current&&(o.current=n)},[e,n,i,r]),E.useEffect(()=>{a&&s(null)},[a]),a}function gVe(t){let{animateLayoutChanges:e=dVe,attributes:n,disabled:i,data:r,getNewIndex:a=uVe,id:s,strategy:o,resizeObserverConfig:l,transition:c=fVe}=t;const{items:u,containerId:f,activeIndex:m,disabled:g,disableTransforms:b,sortedRects:y,overIndex:v,useDragOverlay:x,strategy:M}=E.useContext(jJ),w=xVe(i,g),A=u.indexOf(s),T=E.useMemo(()=>({sortable:{containerId:f,index:A,items:u},...r}),[f,r,A,u]),R=E.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:N,node:j,isOver:C,setNodeRef:k}=aVe({id:s,data:T,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:R,...l}}),{active:F,activatorEvent:I,activeNodeRect:W,attributes:O,setNodeRef:H,listeners:V,isDragging:$,over:K,setActivatorNodeRef:Y,transform:se}=tVe({id:s,data:T,attributes:{...pVe,...n},disabled:w.draggable}),B=I8e(k,H),X=!!F,ae=X&&!b&&i_(m)&&i_(v),ce=!x&&$,xe=ce&&ae?se:null,ve=ae?xe??(o??M)({rects:y,activeNodeRect:W,activeIndex:m,overIndex:v,index:A}):null,Pe=i_(m)&&i_(v)?a({id:s,items:u,activeIndex:m,overIndex:v}):A,pe=F?.id,we=E.useRef({activeId:pe,items:u,newIndex:Pe,containerId:f}),ze=u!==we.current.items,ue=e({active:F,containerId:f,isDragging:$,isSorting:X,id:s,index:A,items:u,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ht=mVe({disabled:!ue,index:A,node:j,rect:N});return E.useEffect(()=>{X&&we.current.newIndex!==Pe&&(we.current.newIndex=Pe),f!==we.current.containerId&&(we.current.containerId=f),u!==we.current.items&&(we.current.items=u)},[X,Pe,f,u]),E.useEffect(()=>{if(pe===we.current.activeId)return;if(pe!=null&&we.current.activeId==null){we.current.activeId=pe;return}const q=setTimeout(()=>{we.current.activeId=pe},50);return()=>clearTimeout(q)},[pe]),{active:F,activeIndex:m,attributes:O,data:T,rect:N,index:A,newIndex:Pe,items:u,isOver:C,isSorting:X,isDragging:$,listeners:V,node:j,overIndex:v,over:K,setNodeRef:B,setActivatorNodeRef:Y,setDroppableNodeRef:k,setDraggableNodeRef:H,transform:ht??ve,transition:z()};function z(){if(ht||ze&&we.current.newIndex===A)return hVe;if(!(ce&&!JO(I)||!c)&&(X||ue))return E0.Transition.toString({...c,property:UJ})}}function xVe(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 FS(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 vVe=[_n.Down,_n.Right,_n.Up,_n.Left],bVe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(vVe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const m=r.get(f.id);if(m)switch(t.code){case _n.Down:i.topm.top&&l.push(f);break;case _n.Left:i.left>m.left&&l.push(f);break;case _n.Right:i.left1&&(u=c[1].id),u!=null){const f=a.get(n.id),m=a.get(u),g=m?r.get(m.id):null,b=m?.node.current;if(b&&g&&f&&m){const v=dM(b).some((R,N)=>o[N]!==R),x=FJ(f,m),M=yVe(f,m),w=v||!x?{x:0,y:0}:{x:M?i.width-g.width:0,y:M?i.height-g.height:0},A={x:g.left,y:g.top};return w.x&&w.y?A:M0(A,w)}}}};function FJ(t,e){return!FS(t)||!FS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function yVe(t,e){return!FS(t)||!FS(e)||!FJ(t,e)?!1:t.data.current.sortable.index{const v={};return t.forEach(x=>{v[x.id]=x.defaultSize||4}),v},[r,a]=E.useState(()=>{const v=localStorage.getItem(e);if(v)try{const x=JSON.parse(v);return x.sizes||(x.sizes=i()),x}catch{}return{order:t.map(x=>x.id),hidden:t.filter(x=>x.defaultVisible===!1).map(x=>x.id),sizes:i()}}),[s,o]=E.useState(!1);E.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),E.useEffect(()=>{const x=t.map(M=>M.id).filter(M=>!r.order.includes(M));x.length>0&&a(M=>({...M,order:[...M.order,...x]}))},[t,r.order]);const l=Y8e(B$(iL,{activationConstraint:{distance:8}}),B$(tL,{coordinateGetter:bVe})),c=v=>{const{active:x,over:M}=v;M&&x.id!==M.id&&a(w=>{const A=w.order.indexOf(x.id),T=w.order.indexOf(M.id);return{...w,order:rL(w.order,A,T)}})},u=v=>{a(x=>({...x,hidden:x.hidden.includes(v)?x.hidden.filter(M=>M!==v):[...x.hidden,v]}))},f=v=>{a(x=>{const M=x.sizes[v]||4,w=M===1?2:M===2?4:1;return{...x,sizes:{...x.sizes,[v]:w}}})},m=()=>{const v={order:t.map(x=>x.id),hidden:t.filter(x=>x.defaultVisible===!1).map(x=>x.id),sizes:i()};a(v)},g=r.order.map(v=>t.find(x=>x.id===v)).filter(Boolean),b=g.filter(v=>!r.hidden.includes(v.id)),y=g.filter(v=>r.hidden.includes(v.id));return h.jsxs("div",{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-end gap-2",children:[y.length>0&&h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[h.jsx(F4,{className:"w-4 h-4"}),y.length," Hidden"]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:m,children:[h.jsx(XS,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&y.length>0&&h.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),h.jsx("div",{className:"flex flex-wrap gap-2",children:y.map(v=>h.jsxs("button",{onClick:()=>u(v.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:[h.jsx(F4,{className:"w-3 h-3"}),v.title]},v.id))})]}),h.jsx(Q6e,{sensors:l,collisionDetection:Q8e,onDragEnd:c,children:h.jsx(cVe,{items:b.map(v=>v.id),strategy:aL,children:h.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:b.map(v=>h.jsx(_Ve,{id:v.id,title:v.title,isHidden:r.hidden.includes(v.id),size:r.sizes[v.id]||2,onToggleVisibility:()=>u(v.id),onToggleSize:()=>f(v.id),children:v.component},v.id))})})}),b.length===0&&h.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[h.jsx("p",{children:"All widgets are hidden."}),h.jsx(lt,{className:"mt-4",onClick:m,children:"Reset Layout"})]})]})}function wVe({stats:t,currency:e}){return h.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:h.jsx(F_,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),h.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:h.jsx(xa,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:h.jsx(F_,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:h.jsx(U4,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:h.jsx(s9,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:h.jsx(U4,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function MVe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return h.jsxs("div",{className:"flex items-center gap-6",children:[h.jsxs("div",{className:"relative w-28 h-28",children:[h.jsxs("svg",{className:"w-full h-full -rotate-90",children:[h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),h.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:h.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(rd,{className:"w-4 h-4 text-bambu-green"}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),h.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(R0,{className:"w-4 h-4 text-red-400"}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),h.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function EVe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return h.jsx("div",{className:"flex items-center justify-center h-full",children:h.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 h.jsxs("div",{className:"flex items-center gap-6",children:[h.jsxs("div",{className:"relative w-28 h-28",children:[h.jsxs("svg",{className:"w-full h-full -rotate-90",children:[h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),h.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[h.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),h.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),h.jsxs("div",{className:"space-y-2 flex-1",children:[h.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[h.jsx(qoe,{className:"w-3 h-3"}),h.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&h.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>h.jsxs("div",{className:"flex items-center justify-between text-xs",children:[h.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),h.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 AVe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return h.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 h.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return h.jsxs("div",{children:[h.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[h.jsx("span",{className:"text-white",children:n}),h.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),h.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:h.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function TVe({printDates:t}){return h.jsx(C2e,{printDates:t,months:4})}function CVe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?h.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):h.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>h.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[h.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:h.jsx(hc,{className:"w-4 h-4 text-bambu-green"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),h.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function NVe({archives:t,currency:e}){return!t||t.length===0?h.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):h.jsx(L8e,{archives:t,currency:e})}function RVe(){const{data:t,isLoading:e}=Ht({queryKey:["archiveStats"],queryFn:He.getArchiveStats}),{data:n}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:i}=Ht({queryKey:["archives"],queryFn:()=>He.getArchives(void 0,1e3,0)}),{data:r}=Ht({queryKey:["settings"],queryFn:He.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 h.jsx("div",{className:"p-8",children:h.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:h.jsx(wVe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:h.jsx(MVe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:h.jsx(EVe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:h.jsx(AVe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:h.jsx(TVe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:h.jsx(CVe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:h.jsx(NVe,{archives:i||[],currency:a}),defaultSize:4}];return h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),h.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),h.jsx(SVe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function PVe({plug:t,onEdit:e}){const n=Gn(),[i,r]=E.useState(!1),[a,s]=E.useState(!1),[o,l]=E.useState(!1),[c,u]=E.useState(!1),{data:f,isLoading:m,refetch:g}=Ht({queryKey:["smart-plug-status",t.id],queryFn:()=>He.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:b}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),y=b?.find(R=>R.id===t.printer_id),v=yt({mutationFn:R=>He.controlSmartPlug(t.id,R),onSuccess:()=>{g()}}),x=yt({mutationFn:R=>He.updateSmartPlug(t.id,R),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=yt({mutationFn:()=>He.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",A=f?.reachable??!1,T=v.isPending;return h.jsxs(h.Fragment,{children:[h.jsx(Xt,{className:"relative",children:h.jsxs(en,{className:"p-4",children:[h.jsxs("div",{className:"flex items-start justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:`p-2 rounded-lg ${A?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:h.jsx(AN,{className:`w-5 h-5 ${A?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),h.jsxs("div",{children:[h.jsx("h3",{className:"font-medium text-white",children:t.name}),h.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),h.jsx("div",{className:"flex items-center gap-2",children:m?h.jsx(It,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?h.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[h.jsx(LP,{className:"w-4 h-4 text-bambu-green"}),h.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):h.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[h.jsx(Fp,{className:"w-4 h-4"}),h.jsx("span",{children:"Offline"})]})})]}),y&&h.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),h.jsx("span",{className:"text-sm text-white",children:y.name})]}),h.jsxs("div",{className:"flex gap-2 mb-3",children:[h.jsxs(lt,{size:"sm",variant:w?"primary":"secondary",disabled:!A||T,onClick:()=>s(!0),className:"flex-1",children:[T?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(qS,{className:"w-4 h-4"}),"On"]}),h.jsxs(lt,{size:"sm",variant:w?"secondary":"primary",disabled:!A||T,onClick:()=>l(!0),className:"flex-1",children:[T?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(n9,{className:"w-4 h-4"}),"Off"]})]}),h.jsxs("button",{onClick:()=>u(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[h.jsxs("span",{className:"flex items-center gap-2",children:[h.jsx(OP,{className:"w-4 h-4"}),"Automation Settings"]}),h.jsx("span",{children:c?"-":"+"})]}),c&&h.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Enabled"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.enabled,onChange:R=>x.mutate({enabled:R.target.checked}),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Auto On"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:R=>x.mutate({auto_on:R.target.checked}),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:R=>x.mutate({auto_off:R.target.checked}),className:"sr-only peer"}),h.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&&h.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),h.jsxs("div",{className:"flex gap-2",children:[h.jsxs("button",{onClick:()=>x.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:[h.jsx(xa,{className:"w-4 h-4"}),"Time"]}),h.jsxs("button",{onClick:()=>x.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:[h.jsx(o_,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),h.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:R=>x.mutate({off_delay_minutes:parseInt(R.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"})]}):h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),h.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:R=>x.mutate({off_temp_threshold:parseInt(R.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"}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),h.jsxs("div",{className:"flex gap-2 pt-2",children:[h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[h.jsx(t9,{className:"w-4 h-4"}),"Edit"]}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:h.jsx(ia,{className:"w-4 h-4"})})]})]})]})}),i&&h.jsx(rr,{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&&h.jsx(rr,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&h.jsx(rr,{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:()=>{v.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function kVe({plug:t,onClose:e}){const n=Gn(),i=!!t,[r,a]=E.useState(t?.name||""),[s,o]=E.useState(t?.ip_address||""),[l,c]=E.useState(t?.username||""),[u,f]=E.useState(t?.password||""),[m,g]=E.useState(t?.printer_id||null),[b,y]=E.useState(null),[v,x]=E.useState(null),{data:M}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:w}=Ht({queryKey:["smart-plugs"],queryFn:He.getSmartPlugs});E.useEffect(()=>{const k=F=>{F.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const A=yt({mutationFn:()=>He.testSmartPlugConnection(s,l||null,u||null),onSuccess:k=>{y(k),x(null),!r&&k.device_name&&a(k.device_name)},onError:k=>{y(null),x(k.message)}}),T=yt({mutationFn:k=>He.createSmartPlug(k),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:k=>{x(k.message)}}),R=yt({mutationFn:k=>He.updateSmartPlug(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:k=>{x(k.message)}}),N=M?.filter(k=>!w?.some(I=>I.printer_id===k.id&&I.id!==t?.id)),j=k=>{if(k.preventDefault(),x(null),!r.trim()){x("Name is required");return}if(!s.trim()){x("IP address is required");return}const F={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:u.trim()||null,printer_id:m};i?R.mutate(F):T.mutate(F)},C=T.isPending||R.isPending;return h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:k=>k.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:j,className:"p-6 space-y-4",children:[v&&h.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:v}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx("input",{type:"text",value:s,onChange:k=>{o(k.target.value),y(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"}),h.jsxs(lt,{type:"button",variant:"secondary",onClick:()=>A.mutate(),disabled:!s.trim()||A.isPending,children:[A.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(LP,{className:"w-4 h-4"}),"Test"]})]})]}),b&&h.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${b.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:b.success?h.jsxs(h.Fragment,{children:[h.jsx(rd,{className:"w-5 h-5"}),h.jsxs("div",{children:[h.jsx("p",{className:"font-medium",children:"Connected!"}),h.jsxs("p",{className:"text-sm opacity-80",children:[b.device_name&&`Device: ${b.device_name} - `,"State: ",b.state]})]})]}):h.jsxs(h.Fragment,{children:[h.jsx(Fp,{className:"w-5 h-5"}),h.jsx("span",{children:"Connection failed"})]})}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),h.jsx("input",{type:"text",value:r,onChange:k=>a(k.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"})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),h.jsx("input",{type:"text",value:l,onChange:k=>c(k.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),h.jsx("input",{type:"password",value:u,onChange:k=>f(k.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"})]})]}),h.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),h.jsxs("select",{value:m??"",onChange:k=>g(k.target.value?Number(k.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:[h.jsx("option",{value:"",children:"No printer (manual control only)"}),N?.map(k=>h.jsx("option",{value:k.id,children:k.name},k.id))]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),h.jsxs("div",{className:"flex gap-3 pt-2",children:[h.jsx(lt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:C,className:"flex-1",children:[C?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(P0,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function is({checked:t,onChange:e,disabled:n}){const i=r=>{r.preventDefault(),r.stopPropagation(),n||e(!t)};return h.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:i,className:`relative inline-flex w-9 h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:h.jsx("span",{className:`pointer-events-none absolute top-[2px] left-[2px] w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const DVe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email"};function OVe({provider:t,onEdit:e}){const n=Gn(),[i,r]=E.useState(!1),[a,s]=E.useState(!1),[o,l]=E.useState(null),{data:c}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),u=c?.find(y=>y.id===t.printer_id),f=yt({mutationFn:y=>He.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=yt({mutationFn:()=>He.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=yt({mutationFn:()=>He.testNotificationProvider(t.id),onSuccess:y=>{l(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{l({success:!1,message:y.message})}}),b=y=>y||"";return h.jsxs(h.Fragment,{children:[h.jsx(Xt,{className:"relative",children:h.jsxs(en,{className:"p-4",children:[h.jsxs("div",{className:"flex items-start justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:h.jsx(wN,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),h.jsxs("div",{children:[h.jsx("h3",{className:"font-medium text-white",children:t.name}),h.jsx("p",{className:"text-sm text-bambu-gray",children:DVe[t.provider_type]||t.provider_type})]})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[t.last_success&&h.jsxs("span",{className:"text-xs text-bambu-green",children:["Last sent: ",new Date(t.last_success).toLocaleDateString()]}),t.last_error&&h.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"})]})]}),u&&h.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),h.jsx("span",{className:"text-sm text-white",children:u.name})]}),!u&&!t.printer_id&&h.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:h.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),h.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&h.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&h.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&h.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&h.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&h.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&h.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&h.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Error"}),t.on_filament_low&&h.jsx("span",{className:"px-2 py-0.5 bg-amber-500/20 text-amber-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&h.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.quiet_hours_enabled&&h.jsxs("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded flex items-center gap-1",children:[h.jsx(U_,{className:"w-3 h-3"}),"Quiet"]})]}),h.jsx("div",{className:"mb-3",children:h.jsxs(lt,{size:"sm",variant:"secondary",disabled:g.isPending,onClick:()=>{l(null),g.mutate()},className:"w-full",children:[g.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(i9,{className:"w-4 h-4"}),"Send Test Notification"]})}),o&&h.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${o.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[o.success?h.jsx(rd,{className:"w-4 h-4"}):h.jsx(R0,{className:"w-4 h-4"}),h.jsx("span",{children:o.message})]}),h.jsxs("button",{onClick:()=>s(!a),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[h.jsxs("span",{className:"flex items-center gap-2",children:[h.jsx(OP,{className:"w-4 h-4"}),"Event Settings"]}),a?h.jsx(NP,{className:"w-4 h-4"}):h.jsx(gm,{className:"w-4 h-4"})]}),a&&h.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Enabled"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),h.jsx(is,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Started"}),h.jsx(is,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),h.jsx(is,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),h.jsx(is,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),h.jsx(is,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),h.jsx(is,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),h.jsx(is,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),h.jsx(is,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),h.jsx(is,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),h.jsx(is,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(U_,{className:"w-4 h-4 text-purple-400"}),h.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),h.jsx(is,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&h.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(xa,{className:"w-4 h-4 text-bambu-gray"}),h.jsxs("span",{className:"text-sm text-white",children:[b(t.quiet_hours_start)||"22:00"," - ",b(t.quiet_hours_end)||"07:00"]})]}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),h.jsxs("div",{className:"flex gap-2 pt-2",children:[h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[h.jsx(t9,{className:"w-4 h-4"}),"Edit"]}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:h.jsx(ia,{className:"w-4 h-4"})})]})]})]})}),i&&h.jsx(rr,{title:"Delete Notification Provider",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)})]})}const eG=[{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"email",label:"Email",description:"SMTP email notifications"}];function LVe({provider:t,onClose:e}){const n=Gn(),i=!!t,[r,a]=E.useState(t?.name||""),[s,o]=E.useState(t?.provider_type||"ntfy"),[l,c]=E.useState(t?.printer_id||null),[u,f]=E.useState(t?.quiet_hours_enabled||!1),[m,g]=E.useState(t?.quiet_hours_start||"22:00"),[b,y]=E.useState(t?.quiet_hours_end||"07:00"),[v,x]=E.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([H,V])=>[H,String(V)])):{}),[M,w]=E.useState(null),[A,T]=E.useState(null),{data:R}=Ht({queryKey:["printers"],queryFn:He.getPrinters});E.useEffect(()=>{const H=V=>{V.key==="Escape"&&e()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[e]);const N=yt({mutationFn:()=>He.testNotificationConfig({provider_type:s,config:v}),onSuccess:H=>{w(H),T(null)},onError:H=>{w({success:!1,message:H.message})}}),j=yt({mutationFn:H=>He.createNotificationProvider(H),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:H=>{T(H.message)}}),C=yt({mutationFn:H=>He.updateNotificationProvider(t.id,H),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:H=>{T(H.message)}}),k=H=>{if(H.preventDefault(),T(null),!r.trim()){T("Name is required");return}const V=W(s);for(const K of V)if(!v[K.key]?.trim()){T(`${K.label} is required`);return}const $={name:r.trim(),provider_type:s,config:v,printer_id:l,quiet_hours_enabled:u,quiet_hours_start:u?m:null,quiet_hours_end:u?b:null};i?C.mutate($):j.mutate($)},F=j.isPending||C.isPending,I=H=>{switch(H){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambutrack",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];default:return[]}},W=H=>I(H).filter(V=>V.required),O=I(s);return h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8",onClick:H=>H.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Notification Provider":"Add Notification Provider"}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:k,className:"p-6 space-y-4",children:[A&&h.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:A}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),h.jsx("input",{type:"text",value:r,onChange:H=>a(H.target.value),placeholder:"My Notifications",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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),h.jsx("select",{value:s,onChange:H=>{o(H.target.value),x({}),w(null)},disabled:i,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 disabled:opacity-50",children:eG.map(H=>h.jsx("option",{value:H.value,children:H.label},H.value))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:eG.find(H=>H.value===s)?.description})]}),h.jsxs("div",{className:"space-y-3",children:[h.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),O.map(H=>h.jsxs("div",{children:[h.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[H.label," ",H.required&&"*"]}),H.type==="select"&&H.options?h.jsx("select",{value:v[H.key]||H.options[0]?.value||"",onChange:V=>{x({...v,[H.key]:V.target.value}),w(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:H.options.map(V=>h.jsx("option",{value:V.value,children:V.label},V.value))}):h.jsx("input",{type:H.type,value:v[H.key]||"",onChange:V=>{x({...v,[H.key]:V.target.value}),w(null)},placeholder:H.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"})]},H.key))]}),h.jsx("div",{className:"flex gap-2",children:h.jsxs(lt,{type:"button",variant:"secondary",onClick:()=>{w(null),N.mutate()},disabled:N.isPending||!v[W(s)[0]?.key],className:"flex-1",children:[N.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(i9,{className:"w-4 h-4"}),"Test Configuration"]})}),M&&h.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${M.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:M.success?h.jsxs(h.Fragment,{children:[h.jsx(rd,{className:"w-5 h-5"}),h.jsx("span",{children:M.message})]}):h.jsxs(h.Fragment,{children:[h.jsx(R0,{className:"w-5 h-5"}),h.jsx("span",{children:M.message})]})}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),h.jsxs("select",{value:l??"",onChange:H=>c(H.target.value?Number(H.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:[h.jsx("option",{value:"",children:"All printers"}),R?.map(H=>h.jsx("option",{value:H.id,children:H.name},H.id))]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),h.jsx(is,{checked:u,onChange:f})]}),u&&h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),h.jsx("input",{type:"time",value:m,onChange:H=>g(H.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),h.jsx("input",{type:"time",value:b,onChange:H=>y(H.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"})]})]})]}),h.jsxs("div",{className:"flex gap-3 pt-2",children:[h.jsx(lt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:F,className:"flex-1",children:[F?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(P0,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}async function IVe(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function jVe(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function UVe(){const t=Gn(),[e,n]=E.useState(!1),[i,r]=E.useState(""),[a,s]=E.useState("auto"),[o,l]=E.useState(!1),[c,u]=E.useState(!1),[f,m]=E.useState("all"),{data:g,isLoading:b}=Ht({queryKey:["spoolman-settings"],queryFn:IVe}),{data:y,isLoading:v,refetch:x}=Ht({queryKey:["spoolman-status"],queryFn:He.getSpoolmanStatus,refetchInterval:3e4}),{data:M}=Ht({queryKey:["printers"],queryFn:He.getPrinters});E.useEffect(()=>{g&&(n(g.spoolman_enabled==="true"),r(g.spoolman_url||""),s(g.spoolman_sync_mode||"auto"))},[g]),E.useEffect(()=>{if(g){const I=g.spoolman_enabled==="true"!==e||(g.spoolman_url||"")!==i||(g.spoolman_sync_mode||"auto")!==a;l(I)}},[g,e,i,a]);const w=yt({mutationFn:()=>jVe({spoolman_enabled:e?"true":"false",spoolman_url:i,spoolman_sync_mode:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),l(!1),u(!0),setTimeout(()=>u(!1),2e3)}}),A=yt({mutationFn:He.connectSpoolman,onSuccess:()=>{x()}}),T=yt({mutationFn:He.disconnectSpoolman,onSuccess:()=>{x()}}),R=yt({mutationFn:He.syncAllPrintersAms,onSuccess:I=>{I.success}}),N=yt({mutationFn:I=>He.syncPrinterAms(I),onSuccess:I=>{I.success}}),j=()=>{f==="all"?R.mutate():N.mutate(f)},C=R.isPending||N.isPending,k=f==="all"?R.data:N.data,F=f==="all"?R.isSuccess:N.isSuccess;return b?h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(j4,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),h.jsx(en,{children:h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(j4,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),o&&h.jsx(lt,{size:"sm",onClick:()=>w.mutate(),disabled:w.isPending,children:w.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):c?h.jsx(jp,{className:"w-4 h-4"}):"Save"})]})}),h.jsxs(en,{className:"space-y-4",children:[h.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Enable Spoolman"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:e,onChange:I=>n(I.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),h.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:i,onChange:I=>r(I.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),h.jsxs("select",{value:a,onChange:I=>s(I.target.value),disabled:!e,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 disabled:opacity-50",children:[h.jsx("option",{value:"auto",children:"Automatic"}),h.jsx("option",{value:"manual",children:"Manual Only"})]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&h.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),v?h.jsx(It,{className:"w-4 h-4 text-bambu-gray animate-spin"}):y?.connected?h.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[h.jsx(jp,{className:"w-4 h-4"}),"Connected"]}):h.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[h.jsx(bn,{className:"w-4 h-4"}),"Disconnected"]})]}),h.jsx("div",{className:"flex gap-2",children:y?.connected?h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>T.mutate(),disabled:T.isPending,children:[T.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Wse,{className:"w-4 h-4"}),"Disconnect"]}):h.jsxs(lt,{size:"sm",onClick:()=>A.mutate(),disabled:A.isPending||!i,children:[A.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Xse,{className:"w-4 h-4"}),"Connect"]})})]}),A.isError&&h.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:A.error.message}),y?.connected&&h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("div",{className:"relative flex-1",children:[h.jsxs("select",{value:f,onChange:I=>m(I.target.value==="all"?"all":Number(I.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[h.jsx("option",{value:"all",children:"All Printers"}),M?.map(I=>h.jsx("option",{value:I.id,children:I.name},I.id))]}),h.jsx(gm,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:j,disabled:C,children:[C?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Zo,{className:"w-4 h-4"}),"Sync"]})]})]}),F&&k&&h.jsx("div",{className:`mt-2 p-2 rounded text-sm ${k.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:k.success?`Synced ${k.synced_count} trays successfully`:`Synced ${k.synced_count} trays with ${k.errors.length} errors`})]})]})]})}function FVe(){const t=Gn(),{t:e,i18n:n}=bP(),[i,r]=E.useState(null),[a,s]=E.useState(!1),[o,l]=E.useState(!1),[c,u]=E.useState(!1),[f,m]=E.useState(null),[g,b]=E.useState(!1),[y,v]=E.useState(null),[x,M]=E.useState(l9()),w=X=>{M(X),kle(X)},A=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:T,isLoading:R}=Ht({queryKey:["settings"],queryFn:He.getSettings}),{data:N,isLoading:j}=Ht({queryKey:["smart-plugs"],queryFn:He.getSmartPlugs}),{data:C,isLoading:k}=Ht({queryKey:["notification-providers"],queryFn:He.getNotificationProviders}),{data:F}=Ht({queryKey:["ffmpeg-status"],queryFn:He.checkFfmpeg}),{data:I}=Ht({queryKey:["version"],queryFn:He.getVersion}),{data:W,refetch:O,isRefetching:H}=Ht({queryKey:["updateCheck"],queryFn:He.checkForUpdates,staleTime:300*1e3}),{data:V,refetch:$}=Ht({queryKey:["updateStatus"],queryFn:He.getUpdateStatus,refetchInterval:X=>{const ae=X.state.data;return ae?.status==="downloading"||ae?.status==="installing"?1e3:!1}}),K=yt({mutationFn:He.applyUpdate,onSuccess:()=>{$()}});E.useEffect(()=>{T&&!i&&r(T)},[T,i]),E.useEffect(()=>{if(T&&i){const X=T.auto_archive!==i.auto_archive||T.save_thumbnails!==i.save_thumbnails||T.capture_finish_photo!==i.capture_finish_photo||T.default_filament_cost!==i.default_filament_cost||T.currency!==i.currency||T.energy_cost_per_kwh!==i.energy_cost_per_kwh||T.energy_tracking_mode!==i.energy_tracking_mode||T.check_updates!==i.check_updates||T.notification_language!==i.notification_language;s(X)}},[T,i]);const Y=yt({mutationFn:He.updateSettings,onSuccess:X=>{t.setQueryData(["settings"],X),r(X),s(!1),l(!0),setTimeout(()=>l(!1),2e3),t.invalidateQueries({queryKey:["archiveStats"]})}}),se=()=>{i&&Y.mutate(i)},B=(X,ae)=>{i&&r({...i,[X]:ae})};return R||!i?h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),h.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),h.jsxs(lt,{onClick:se,disabled:!a||Y.isPending,children:[Y.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):o?h.jsx(jp,{className:"w-4 h-4"}):h.jsx(P0,{className:"w-4 h-4"}),o?"Saved!":"Save"]})]}),Y.isError&&h.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: ",Y.error.message]}),h.jsxs("div",{className:"flex gap-8",children:[h.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Auto-archive prints"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.auto_archive,onChange:X=>B("auto_archive",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Save thumbnails"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.save_thumbnails,onChange:X=>B("save_thumbnails",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Capture finish photo"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.capture_finish_photo,onChange:X=>B("capture_finish_photo",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),i.capture_finish_photo&&F&&!F.installed&&h.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),h.jsxs("div",{className:"text-sm",children:[h.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),h.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",h.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",h.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),h.jsx("input",{type:"number",step:"0.01",min:"0",value:i.default_filament_cost,onChange:X=>B("default_filament_cost",parseFloat(X.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),h.jsxs("select",{value:i.currency,onChange:X=>B("currency",X.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:[h.jsx("option",{value:"USD",children:"USD ($)"}),h.jsx("option",{value:"EUR",children:"EUR (€)"}),h.jsx("option",{value:"GBP",children:"GBP (£)"}),h.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),h.jsx("option",{value:"JPY",children:"JPY (¥)"}),h.jsx("option",{value:"CNY",children:"CNY (¥)"}),h.jsx("option",{value:"CAD",children:"CAD ($)"}),h.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),h.jsx("input",{type:"number",step:"0.01",min:"0",value:i.energy_cost_per_kwh,onChange:X=>B("energy_cost_per_kwh",parseFloat(X.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),h.jsxs("select",{value:i.energy_tracking_mode||"total",onChange:X=>B("energy_tracking_mode",X.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:[h.jsx("option",{value:"print",children:"Prints Only"}),h.jsx("option",{value:"total",children:"Total Consumption"})]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:e("settings.general")})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{children:[h.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[h.jsx(j_,{className:"w-4 h-4 inline mr-1"}),e("settings.language")]}),h.jsx("select",{value:n.language,onChange:X=>n.changeLanguage(X.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:x4.map(X=>h.jsxs("option",{value:X.code,children:[X.nativeName," (",X.name,")"]},X.code))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.languageDescription")})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("settings.defaultView")}),h.jsx("select",{value:x,onChange:X=>w(X.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:l_.map(X=>h.jsx("option",{value:X.to,children:e(X.labelKey)},X.id))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.defaultViewDescription")})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Sidebar order"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:A,children:[h.jsx(XS,{className:"w-4 h-4"}),"Reset"]})]})]})]})]}),h.jsxs("div",{className:"space-y-6 flex-1 max-w-md",children:[h.jsx(UVe,{}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Check for updates"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.check_updates,onChange:X=>B("check_updates",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[h.jsxs("div",{className:"flex items-center justify-between mb-2",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Current version"}),h.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",I?.version||"..."]})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>O(),disabled:H,children:[H?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Zo,{className:"w-4 h-4"}),"Check now"]})]}),W?.update_available?h.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[h.jsxs("div",{className:"flex items-start justify-between",children:[h.jsxs("div",{children:[h.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",W.latest_version]}),W.release_name&&W.release_name!==W.latest_version&&h.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:W.release_name}),W.release_notes&&h.jsx("p",{className:"text-sm text-bambu-gray mt-2 whitespace-pre-line line-clamp-3",children:W.release_notes})]}),W.release_url&&h.jsx("a",{href:W.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:h.jsx(fc,{className:"w-4 h-4"})})]}),V?.status==="downloading"||V?.status==="installing"?h.jsxs("div",{className:"mt-3",children:[h.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[h.jsx(It,{className:"w-4 h-4 animate-spin"}),h.jsx("span",{children:V.message})]}),h.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:h.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${V.progress}%`}})})]}):V?.status==="complete"?h.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:V.message}):V?.status==="error"?h.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:V.error||V.message}):h.jsxs(lt,{className:"mt-3",onClick:()=>K.mutate(),disabled:K.isPending,children:[K.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Gu,{className:"w-4 h-4"}),"Install Update"]})]}):W?.error?h.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",W.error]}):W&&!W.update_available?h.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]})]}),h.jsx("div",{className:"w-80 flex-shrink-0",children:h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(AN,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),h.jsxs(lt,{size:"sm",onClick:()=>{m(null),u(!0)},children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add"]})]})}),h.jsxs(en,{children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),j?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})}):N&&N.length>0?h.jsx("div",{className:"space-y-4",children:N.map(X=>h.jsx(PVe,{plug:X,onEdit:ae=>{m(ae),u(!0)}},X.id))}):h.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[h.jsx(AN,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),h.jsx("p",{children:"No smart plugs configured"}),h.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})}),h.jsx("div",{className:"w-80 flex-shrink-0",children:h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(wN,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notifications"})]}),h.jsxs(lt,{size:"sm",onClick:()=>{v(null),b(!0)},children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add"]})]})}),h.jsxs(en,{children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Get notified about print events via WhatsApp, Telegram, Email, and more."}),h.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary mb-4",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:e("settings.notificationLanguage")}),h.jsx("p",{className:"text-sm text-bambu-gray",children:e("settings.notificationLanguageDescription")})]}),h.jsx("select",{value:i.notification_language||"en",onChange:X=>B("notification_language",X.target.value),className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green",children:x4.map(X=>h.jsx("option",{value:X.code,children:X.nativeName},X.code))})]}),k?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})}):C&&C.length>0?h.jsx("div",{className:"space-y-4",children:C.map(X=>h.jsx(OVe,{provider:X,onEdit:ae=>{v(ae),b(!0)}},X.id))}):h.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[h.jsx(wN,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),h.jsx("p",{children:"No notification providers configured"}),h.jsx("p",{className:"text-sm mt-1",children:"Add a provider to get started"})]})]})]})})]}),c&&h.jsx(kVe,{plug:f,onClose:()=>{u(!1),m(null)}}),g&&h.jsx(LVe,{provider:y,onClose:()=>{b(!1),v(null)}})]})}const zJ=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},zVe=t=>t.startsWith("HH")?"HF":"S",BVe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},BJ=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const i of e)if(t.startsWith(i))return t.slice(i.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function lN({profile:t,onEdit:e}){const n=zVe(t.nozzle_id),i=t.nozzle_diameter,r=t.name||"Unnamed",a=BJ(t.name||"");return h.jsxs("button",{onClick:e,className:"w-full text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:zJ(t.k_value)}),h.jsx("span",{className:"text-white text-sm truncate flex-1",title:r,children:r}),h.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[n," ",i]})]}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 truncate",title:`Filament: ${a}`,children:["Filament: ",a||t.filament_id]})]})}function tG({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:i=[],isDualNozzle:r=!1,onClose:a,onSave:s}){const{showToast:o}=Mo(),l=Gn(),[c,u]=E.useState(t?.name||""),[f,m]=E.useState(t?.k_value?zJ(t.k_value):"0.020"),[g,b]=E.useState(t?.filament_id||""),[y,v]=E.useState(t?.nozzle_id?BVe(t.nozzle_id):"HH00"),[x,M]=E.useState(t?.nozzle_diameter||n),[w,A]=E.useState(t?[t.extruder_id]:r?[0,1]:[0]),[T,R]=E.useState(!1),[N,j]=E.useState({current:0,total:0}),C=ui.useMemo(()=>{const V=new Map;for(const $ of i)if($.filament_id&&!V.has($.filament_id)){const K=BJ($.name||"");V.set($.filament_id,{id:$.filament_id,name:K||$.filament_id})}return Array.from(V.values()).sort(($,K)=>$.name.localeCompare(K.name))},[i]),k=yt({mutationFn:V=>(console.log("[KProfile] Calling API..."),He.setKProfile(e,V)),onSuccess:V=>{console.log("[KProfile] Save success:",V),o("K-profile saved"),R(!0),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),s()},2500)},onError:V=>{console.error("[KProfile] Save error:",V),o(V.message,"error"),R(!1)}}),F=yt({mutationFn:V=>(console.log("[KProfile] Deleting profile..."),He.deleteKProfile(e,V)),onSuccess:V=>{console.log("[KProfile] Delete success:",V),o("K-profile deleted"),R(!0),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),a()},2500)},onError:V=>{console.error("[KProfile] Delete error:",V),o(V.message,"error"),R(!1)}}),[I,W]=E.useState(!1),O=()=>{t&&F.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async V=>{if(V.preventDefault(),r&&!t&&w.length===0){o("Please select at least one extruder","error");return}const $=parseFloat(f).toFixed(6),K=`${y}-${x}`;if(t||w.length===1){const Y={name:c,k_value:$,filament_id:g,nozzle_id:K,nozzle_diameter:x,extruder_id:t?t.extruder_id:w[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",Y),k.mutate(Y);return}R(!0),j({current:0,total:w.length});for(let Y=0;YsetTimeout(X,1500))}catch(X){console.error(`[KProfile] Failed to save for extruder ${se}:`,X),o(`Failed to save for ${se===1?"Left":"Right"} extruder`,"error"),R(!1),j({current:0,total:0});return}}o(`K-profile saved to ${w.length} extruders`),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),j({current:0,total:0}),s()},2500)};return h.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[h.jsxs(Xt,{className:"w-full max-w-md relative",children:[T&&h.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),h.jsx("p",{className:"text-white font-medium",children:N.total>1?`Saving to extruder ${N.current}/${N.total}...`:"Syncing with printer..."}),h.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),h.jsxs(en,{className:"p-0",children:[h.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),h.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors",disabled:T,children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),h.jsx("input",{type:"text",value:c,onChange:V=>u(V.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!t})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),h.jsx("input",{type:"text",inputMode:"decimal",value:f,onChange:V=>{const $=V.target.value;($===""||/^\d*\.?\d*$/.test($))&&m($)},onBlur:V=>{const $=parseFloat(V.target.value);isNaN($)||m((Math.trunc($*1e3)/1e3).toFixed(3))},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 font-mono",placeholder:"0.020",required:!0}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),h.jsxs("select",{value:g,onChange:V=>{const $=V.target.value;if(b($),!t&&$&&!c){const K=C.find(Y=>Y.id===$);K&&u(`${y==="HH00"?"HF":"S"} ${K.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[h.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&h.jsx("option",{value:t.filament_id,children:C.find(V=>V.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&C.map(V=>h.jsx("option",{value:V.id,children:V.name},V.id))]}),!t&&C.length===0&&h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),h.jsxs("select",{value:y,onChange:V=>{const $=V.target.value;if(v($),!t&&g&&!c){const K=C.find(Y=>Y.id===g);K&&u(`${$==="HH00"?"HF":"S"} ${K.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[h.jsx("option",{value:"HH00",children:"High Flow"}),h.jsx("option",{value:"HS00",children:"Standard"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),h.jsxs("select",{value:x,onChange:V=>M(V.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[h.jsx("option",{value:"0.2",children:"0.2mm"}),h.jsx("option",{value:"0.4",children:"0.4mm"}),h.jsx("option",{value:"0.6",children:"0.6mm"}),h.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),r&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?h.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?"Left":"Right"}):h.jsxs("div",{className:"flex gap-4",children:[h.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:w.includes(1),onChange:V=>{V.target.checked?A([...w,1]):A(w.filter($=>$!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),h.jsx("span",{className:"text-white",children:"Left"})]}),h.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:w.includes(0),onChange:V=>{V.target.checked?A([...w,0]):A(w.filter($=>$!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),h.jsx("span",{className:"text-white",children:"Right"})]})]})]}),h.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&h.jsx(lt,{type:"button",variant:"secondary",onClick:()=>W(!0),disabled:F.isPending||T,className:"text-red-500 hover:bg-red-500/10",children:F.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(ia,{className:"w-4 h-4"})}),h.jsx(lt,{type:"button",variant:"secondary",onClick:a,disabled:T,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:k.isPending||T,className:"flex-1",children:[k.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(PP,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),I&&h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:h.jsx(Xt,{className:"w-full max-w-sm",children:h.jsxs(en,{className:"p-6",children:[h.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[h.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:h.jsx(ia,{className:"w-5 h-5 text-red-500"})}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),h.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",h.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),h.jsxs("div",{className:"flex gap-3",children:[h.jsx(lt,{variant:"secondary",onClick:()=>W(!1),className:"flex-1",children:"Cancel"}),h.jsxs(lt,{onClick:()=>{W(!1),O()},disabled:F.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[F.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(ia,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function HVe(){const[t,e]=E.useState(null),[n,i]=E.useState("0.4"),[r,a]=E.useState(null),[s,o]=E.useState(!1),[l,c]=E.useState(""),[u,f]=E.useState("all"),[m,g]=E.useState("all"),{data:b,isLoading:y}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:v,isLoading:x,error:M,refetch:w}=Ht({queryKey:["kprofiles",t,n],queryFn:()=>He.getKProfiles(t,n),enabled:!!t,retry:!1,staleTime:0,refetchOnMount:"always"}),A=M?.message?.includes("not connected");E.useEffect(()=>{if(!t&&b&&b.length>0){const C=b.find(k=>k.is_active);C&&e(C.id)}},[t,b]),E.useEffect(()=>{if(t){const C=setTimeout(()=>{w()},150);return()=>clearTimeout(C)}},[t,n]);const T=b?.filter(C=>C.is_active)||[],R=ui.useMemo(()=>v?.profiles?v.profiles.filter(C=>{const k=l.toLowerCase(),F=!k||C.name.toLowerCase().includes(k)||C.filament_id.toLowerCase().includes(k),I=u==="all"||u==="left"&&C.extruder_id===1||u==="right"&&C.extruder_id===0,W=m==="all"||m==="hf"&&C.nozzle_id.startsWith("HH")||m==="s"&&C.nozzle_id.startsWith("HS");return F&&I&&W}):[],[v?.profiles,l,u,m]),j=b?.find(C=>C.id===t)?.nozzle_count===2;return y?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!b||b.length===0?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(id,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),h.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):T.length===0?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(hc,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),h.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[h.jsxs("div",{className:"flex-1 min-w-48",children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),h.jsx("select",{value:t||"",onChange:C=>e(parseInt(C.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:T.map(C=>h.jsx("option",{value:C.id,children:C.name},C.id))})]}),h.jsxs("div",{className:"w-32",children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),h.jsxs("select",{value:n,onChange:C=>i(C.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:[h.jsx("option",{value:"0.2",children:"0.2mm"}),h.jsx("option",{value:"0.4",children:"0.4mm"}),h.jsx("option",{value:"0.6",children:"0.6mm"}),h.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),h.jsxs("div",{className:"flex items-end gap-2",children:[h.jsxs(lt,{variant:"secondary",onClick:()=>w(),disabled:x,children:[h.jsx(Zo,{className:`w-4 h-4 ${x?"animate-spin":""}`}),"Refresh"]}),h.jsxs(lt,{onClick:()=>o(!0),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add Profile"]})]})]}),h.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[h.jsxs("div",{className:"flex-1 min-w-48 relative",children:[h.jsx(z_,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),h.jsx("input",{type:"text",value:l,onChange:C=>c(C.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),j&&h.jsx("div",{className:"w-36",children:h.jsxs("select",{value:u,onChange:C=>f(C.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:[h.jsx("option",{value:"all",children:"All Extruders"}),h.jsx("option",{value:"left",children:"Left Only"}),h.jsx("option",{value:"right",children:"Right Only"})]})}),h.jsx("div",{className:"w-32",children:h.jsxs("select",{value:m,onChange:C=>g(C.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:[h.jsx("option",{value:"all",children:"All Flow"}),h.jsx("option",{value:"hf",children:"HF Only"}),h.jsx("option",{value:"s",children:"S Only"})]})})]}),x?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):A?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(Fp,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),h.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),h.jsxs(lt,{variant:"secondary",onClick:()=>w(),children:[h.jsx(Zo,{className:"w-4 h-4"}),"Retry"]})]})}):R.length>0?j?h.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),h.jsx("div",{className:"space-y-1",children:R.filter(C=>C.extruder_id===1).map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))})]}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),h.jsx("div",{className:"space-y-1",children:R.filter(C=>C.extruder_id===0).map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))})]})]}):h.jsx("div",{className:"space-y-1",children:R.map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))}):l||u!=="all"||m!=="all"?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(z_,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),h.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(PP,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),h.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",n,"mm nozzle"]}),h.jsxs(lt,{onClick:()=>o(!0),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Create First Profile"]})]})}),r&&t&&h.jsx(tG,{profile:r,printerId:t,nozzleDiameter:n,existingProfiles:v?.profiles,isDualNozzle:j,onClose:()=>a(null),onSave:()=>a(null)}),s&&t&&h.jsx(tG,{printerId:t,nozzleDiameter:n,existingProfiles:v?.profiles,isDualNozzle:j,onClose:()=>o(!1),onSave:()=>o(!1)})]})}function VVe({onSuccess:t}){const{showToast:e}=Mo(),[n,i]=E.useState("email"),[r,a]=E.useState(""),[s,o]=E.useState(""),[l,c]=E.useState(""),[u,f]=E.useState(""),[m,g]=E.useState("global"),b=yt({mutationFn:()=>He.cloudLogin(r,s,m),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")}}),y=yt({mutationFn:()=>He.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),v=yt({mutationFn:()=>He.cloudSetToken(u),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),x=w=>{w.preventDefault(),n==="email"?b.mutate():n==="code"?y.mutate():n==="token"&&v.mutate()},M=b.isPending||y.isPending||v.isPending;return h.jsxs(Xt,{className:"max-w-md mx-auto",children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(RP,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),h.jsx(en,{children:h.jsxs("form",{onSubmit:x,className:"space-y-4",children:[n==="email"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),h.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})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),h.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})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),h.jsxs("select",{value:m,onChange:w=>g(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:[h.jsx("option",{value:"global",children:"Global"}),h.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),h.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),h.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"&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),h.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),h.jsx("textarea",{value:u,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})]}),h.jsxs("div",{className:"flex gap-2",children:[n==="code"&&h.jsx(lt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),h.jsxs(lt,{type:"submit",disabled:M,className:"flex-1",children:[M?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(H4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&h.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:h.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[h.jsx(zse,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&h.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:h.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[h.jsx(H4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function $Ve({setting:t,onClick:e}){return h.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[h.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&h.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function GVe({setting:t,onClose:e}){const{data:n,isLoading:i}=Ht({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>He.getCloudSettingDetail(t.setting_id)});return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:h.jsx(Xt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:h.jsxs(en,{className:"p-0 flex flex-col h-full",children:[h.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{children:[h.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),h.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?h.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)}):h.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),h.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:h.jsx(lt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function WVe({settings:t}){const[e,n]=E.useState(new Set),[i,r]=E.useState(null),a=l=>[...l].sort((c,u)=>c.name.localeCompare(u.name)),s=l=>{n(c=>{const u=new Set(c);return u.has(l)?u.delete(l):u.add(l),u})},o=[{key:"filament",label:"Filament Presets",icon:WG,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:hc,items:a(t.printer)},{key:"process",label:"Process Presets",icon:OP,items:a(t.process)}];return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:u,items:f})=>h.jsxs(Xt,{children:[h.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(u,{className:"w-5 h-5 text-bambu-green"}),h.jsx("span",{className:"text-lg font-semibold text-white",children:c}),h.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?h.jsx(gm,{className:"w-5 h-5 text-bambu-gray"}):h.jsx(Bf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&h.jsx(en,{className:"pt-0",children:h.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(m=>h.jsx($Ve,{setting:m,onClick:()=>r(m)},m.setting_id))})}),e.has(l)&&f.length===0&&h.jsx(en,{className:"pt-0",children:h.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&h.jsx(GVe,{setting:i,onClose:()=>r(null)})]})}function qVe(){const t=Gn(),{showToast:e}=Mo(),[n,i]=E.useState("kprofiles"),{data:r,isLoading:a}=Ht({queryKey:["cloudStatus"],queryFn:He.getCloudStatus}),{data:s,isLoading:o,refetch:l}=Ht({queryKey:["cloudSettings"],queryFn:()=>He.getCloudSettings(),enabled:!!r?.is_authenticated,retry:!1,staleTime:1e3*60*5}),c=yt({mutationFn:He.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),u=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return a?h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),h.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),h.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[h.jsxs("button",{onClick:()=>i("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[h.jsx(RP,{className:"w-4 h-4"}),"Cloud Profiles"]}),h.jsxs("button",{onClick:()=>i("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[h.jsx(PP,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[h.jsx("p",{className:"text-bambu-gray",children:r?.is_authenticated?`Connected as ${r.email}`:"Connect to Bambu Cloud to access your slicer presets"}),r?.is_authenticated&&h.jsxs("div",{className:"flex gap-2",children:[h.jsxs(lt,{variant:"secondary",onClick:()=>l(),disabled:o,children:[h.jsx(Zo,{className:`w-4 h-4 ${o?"animate-spin":""}`}),"Refresh"]}),h.jsxs(lt,{variant:"secondary",onClick:()=>c.mutate(),disabled:c.isPending,children:[h.jsx(ioe,{className:"w-4 h-4"}),"Logout"]})]})]}),r?.is_authenticated?o?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s?h.jsx(WVe,{settings:s}):h.jsx(Xt,{children:h.jsxs(en,{className:"py-8 text-center",children:[h.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),h.jsx(lt,{className:"mt-4",onClick:()=>l(),children:"Retry"})]})}):h.jsx(VVe,{onSuccess:u})]}),n==="kprofiles"&&h.jsx(HVe,{})]})}const xP={Droplet:WG,Flame:XG,Ruler:Aoe,Sparkles:Uoe,Square:Up,Cable:kae,Wrench:zp};function N_(t){return t&&xP[t]||zp}function Dx(t){return t<1?`${Math.round(t*60)}m`:`${t.toFixed(1)}h`}function XVe(t){const e=Math.floor(t),n=Math.round((t-e)*60);return e===0?`${n} minutes`:n===0?`${e} hours`:`${e}h ${n}m`}function KVe({item:t,onPerform:e,onToggle:n}){const i=N_(t.maintenance_type_icon),r=Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100)),a=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-yellow-400":"text-bambu-green":"text-bambu-gray",s=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-yellow-500":"bg-bambu-green":"bg-bambu-gray/30",o=()=>t.enabled?t.is_due?`Overdue by ${Dx(Math.abs(t.hours_until_due))}`:t.is_warning?`Due in ${Dx(t.hours_until_due)}`:`${Dx(t.hours_until_due)} left`:"Disabled";return h.jsxs("div",{className:`flex items-center gap-4 p-3 rounded-lg ${t.is_due?"bg-red-500/10":t.is_warning?"bg-yellow-500/10":"bg-bambu-dark"}`,children:[h.jsxs("div",{className:"flex items-center gap-3 min-w-[180px]",children:[h.jsx(i,{className:`w-4 h-4 ${a()}`}),h.jsx("span",{className:`text-sm ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name})]}),h.jsx("div",{className:"flex-1 max-w-[200px]",children:h.jsx("div",{className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:h.jsx("div",{className:`h-full transition-all ${s()}`,style:{width:`${r}%`}})})}),h.jsxs("div",{className:`text-xs min-w-[120px] ${a()}`,children:[t.is_due&&h.jsx(va,{className:"w-3 h-3 inline mr-1"}),t.is_warning&&h.jsx(xa,{className:"w-3 h-3 inline mr-1"}),!t.is_due&&!t.is_warning&&t.enabled&&h.jsx(jp,{className:"w-3 h-3 inline mr-1"}),o()]}),h.jsx(is,{checked:t.enabled,onChange:l=>n(t.id,l)}),h.jsxs(lt,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled,className:"min-w-[70px]",children:[h.jsx(XS,{className:"w-3 h-3"}),"Done"]})]})}function YVe({overview:t,onPerform:e,onToggle:n,onSetHours:i}){const[r,a]=E.useState(!1),[s,o]=E.useState(!1),[l,c]=E.useState(t.total_print_hours.toFixed(1)),u=[...t.maintenance_items].sort((g,b)=>g.maintenance_type_id-b.maintenance_type_id),f=[...t.maintenance_items].filter(g=>g.enabled).sort((g,b)=>g.is_due&&!b.is_due?-1:!g.is_due&&b.is_due?1:g.is_warning&&!b.is_warning?-1:!g.is_warning&&b.is_warning?1:g.hours_until_due-b.hours_until_due)[0],m=()=>{const g=parseFloat(l);!isNaN(g)&&g>=0&&(i(t.printer_id,g),o(!1))};return h.jsxs(Xt,{children:[h.jsxs("div",{className:"p-4",children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:t.printer_name}),t.due_count>0&&h.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(va,{className:"w-3 h-3"}),t.due_count," overdue"]}),t.warning_count>0&&h.jsxs("span",{className:"px-2.5 py-1 bg-yellow-500/20 text-yellow-400 text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(xa,{className:"w-3 h-3"}),t.warning_count," due soon"]}),t.due_count===0&&t.warning_count===0&&h.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(jp,{className:"w-3 h-3"}),"All good"]})]}),h.jsx("button",{onClick:()=>a(!r),className:"flex items-center gap-1 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded transition-colors",children:r?h.jsxs(h.Fragment,{children:[h.jsx(NP,{className:"w-4 h-4"}),"Hide"]}):h.jsxs(h.Fragment,{children:[h.jsx(gm,{className:"w-4 h-4"}),"Details"]})})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-1 uppercase tracking-wide",children:"Total Print Time"}),s?h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{type:"number",value:l,onChange:g=>c(g.target.value),onKeyDown:g=>{g.key==="Enter"&&m(),g.key==="Escape"&&o(!1)},className:"w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-lg font-semibold",min:"0",step:"1",autoFocus:!0}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"hours"}),h.jsxs("div",{className:"flex gap-1 ml-auto",children:[h.jsx(lt,{size:"sm",onClick:m,children:"Save"}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>o(!1),children:"✕"})]})]}):h.jsxs("button",{onClick:()=>{c(Math.round(t.total_print_hours).toString()),o(!0)},className:"flex items-center gap-2 group",title:"Click to edit total print hours",children:[h.jsx("span",{className:"text-xl font-semibold text-white group-hover:text-bambu-green transition-colors",children:XVe(t.total_print_hours)}),h.jsx(DP,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})]})]}),h.jsxs("div",{className:`p-3 rounded-lg ${f?.is_due?"bg-red-500/10":f?.is_warning?"bg-yellow-500/10":"bg-bambu-dark"}`,children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-1 uppercase tracking-wide",children:"Next Maintenance"}),f?h.jsxs("div",{children:[h.jsx("div",{className:`text-lg font-semibold ${f.is_due?"text-red-400":f.is_warning?"text-yellow-400":"text-white"}`,children:f.maintenance_type_name}),h.jsx("div",{className:`text-sm ${f.is_due?"text-red-400":f.is_warning?"text-yellow-400":"text-bambu-gray"}`,children:f.is_due?h.jsxs(h.Fragment,{children:["Overdue by ",Dx(Math.abs(f.hours_until_due))]}):h.jsxs(h.Fragment,{children:["Due in ",Dx(f.hours_until_due)]})})]}):h.jsx("div",{className:"text-white",children:"No tasks enabled"})]})]})]}),r&&h.jsx(en,{className:"pt-0 space-y-2 border-t border-bambu-dark-tertiary mt-4",children:h.jsx("div",{className:"pt-4",children:u.map(g=>h.jsx(KVe,{item:g,onPerform:e,onToggle:n},g.id))})})]})}function ZVe({overview:t,types:e,onUpdateInterval:n,onAddType:i,onDeleteType:r}){const[a,s]=E.useState(null),[o,l]=E.useState(""),[c,u]=E.useState(!1),[f,m]=E.useState(""),[g,b]=E.useState("100"),[y,v]=E.useState("Wrench"),x=(R,N)=>{const j=parseFloat(o);if(!isNaN(j)&&j>0){const C=Math.abs(j-N)<.01?null:j;n(R,C)}s(null)},M=R=>{R.preventDefault(),f.trim()&&parseFloat(g)>0&&(i({name:f.trim(),default_interval_hours:parseFloat(g),icon:y}),m(""),b("100"),u(!1))},w=t?.map(R=>({printerId:R.printer_id,printerName:R.printer_name,items:R.maintenance_items.sort((N,j)=>N.maintenance_type_id-j.maintenance_type_id)})).sort((R,N)=>R.printerName.localeCompare(N.printerName))||[],A=e.filter(R=>R.is_system),T=e.filter(R=>!R.is_system);return h.jsxs("div",{className:"space-y-8",children:[h.jsxs("div",{children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Maintenance Types"}),h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>u(!c),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add Custom Type"]})]}),c&&h.jsx(Xt,{className:"mb-4",children:h.jsx("div",{className:"p-4",children:h.jsx("form",{onSubmit:M,children:h.jsxs("div",{className:"flex gap-3 items-end",children:[h.jsxs("div",{className:"flex-1",children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Name"}),h.jsx("input",{type:"text",value:f,onChange:R=>m(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",placeholder:"e.g., Replace HEPA Filter",autoFocus:!0})]}),h.jsxs("div",{className:"w-28",children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Interval (hours)"}),h.jsx("input",{type:"number",value:g,onChange:R=>b(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"1"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Icon"}),h.jsx("div",{className:"flex gap-1",children:Object.keys(xP).map(R=>{const N=xP[R];return h.jsx("button",{type:"button",onClick:()=>v(R),className:`p-2 rounded ${y===R?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:h.jsx(N,{className:"w-4 h-4"})},R)})})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(lt,{type:"submit",size:"sm",disabled:!f.trim(),children:"Add"}),h.jsx(lt,{type:"button",size:"sm",variant:"secondary",onClick:()=>u(!1),children:"Cancel"})]})]})})})}),h.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[A.map(R=>{const N=N_(R.icon);return h.jsx("div",{className:"bg-bambu-dark-secondary rounded-lg p-4 border border-bambu-dark-tertiary",children:h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"p-2 bg-bambu-dark rounded-lg",children:h.jsx(N,{className:"w-5 h-5 text-bambu-gray"})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm font-medium text-white truncate",children:R.name}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5",children:[R.default_interval_hours,"h interval"]})]})]})},R.id)}),T.map(R=>{const N=N_(R.icon);return h.jsx("div",{className:"bg-bambu-dark-secondary rounded-lg p-4 border border-bambu-green/30",children:h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"p-2 bg-bambu-green/20 rounded-lg",children:h.jsx(N,{className:"w-5 h-5 text-bambu-green"})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-sm font-medium text-white truncate",children:R.name}),h.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:"Custom"})]}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5",children:[R.default_interval_hours,"h interval"]})]}),h.jsx("button",{onClick:()=>{confirm(`Delete "${R.name}"?`)&&r(R.id)},className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",children:h.jsx(ia,{className:"w-4 h-4"})})]})},R.id)})]})]}),w.length>0&&h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold text-white mb-2",children:"Interval Overrides"}),h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Set custom intervals per printer."}),h.jsx("div",{className:"space-y-3",children:w.map(R=>h.jsx(Xt,{children:h.jsxs("div",{className:"p-4",children:[h.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:R.printerName}),h.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:R.items.map(N=>{const j=N_(N.maintenance_type_icon),k=e.find(I=>I.id===N.maintenance_type_id)?.default_interval_hours||N.interval_hours,F=a===N.id;return h.jsxs("div",{className:"flex items-center gap-2 p-2 bg-bambu-dark rounded-lg",children:[h.jsx(j,{className:"w-4 h-4 text-bambu-gray shrink-0"}),h.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:N.maintenance_type_name}),F?h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("input",{type:"number",value:o,onChange:I=>l(I.target.value),onKeyDown:I=>{I.key==="Enter"&&x(N.id,k),I.key==="Escape"&&s(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1",autoFocus:!0}),h.jsx(lt,{size:"sm",onClick:()=>x(N.id,k),children:"OK"})]}):h.jsxs("button",{onClick:()=>{s(N.id),l(N.interval_hours.toString())},className:"px-2 py-1 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green rounded text-xs font-medium text-white transition-colors",children:[N.interval_hours,"h",h.jsx(DP,{className:"w-3 h-3 inline ml-1.5 text-bambu-gray"})]})]},N.id)})})]})},R.printerId))})]}),w.length===0&&h.jsx(Xt,{children:h.jsxs(en,{className:"text-center py-12",children:[h.jsx(xa,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),h.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),h.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to configure maintenance intervals"})]})})]})}function QVe(){const t=Gn(),{showToast:e}=Mo(),[n,i]=E.useState("status"),{data:r,isLoading:a}=Ht({queryKey:["maintenanceOverview"],queryFn:He.getMaintenanceOverview}),{data:s}=Ht({queryKey:["maintenanceTypes"],queryFn:He.getMaintenanceTypes}),o=yt({mutationFn:({id:x,notes:M})=>He.performMaintenance(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Maintenance marked as done")},onError:x=>{e(x.message,"error")}}),l=yt({mutationFn:({id:x,data:M})=>He.updateMaintenanceItem(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:x=>{e(x.message,"error")}}),c=yt({mutationFn:He.createMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type added")},onError:x=>{e(x.message,"error")}}),u=yt({mutationFn:He.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type deleted")},onError:x=>{e(x.message,"error")}}),f=yt({mutationFn:({printerId:x,hours:M})=>He.setPrinterHours(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Print hours updated")},onError:x=>{e(x.message,"error")}}),m=x=>{o.mutate({id:x})},g=(x,M)=>{l.mutate({id:x,data:{enabled:M}})},b=(x,M)=>{f.mutate({printerId:x,hours:M})};if(a)return h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})});const y=r?.reduce((x,M)=>x+M.due_count,0)||0,v=r?.reduce((x,M)=>x+M.warning_count,0)||0;return h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Maintenance"}),h.jsx("p",{className:"text-bambu-gray text-sm",children:n==="status"?h.jsxs(h.Fragment,{children:[y>0&&h.jsxs("span",{className:"text-red-400",children:[y," tasks overdue"]}),y>0&&v>0&&" · ",v>0&&h.jsxs("span",{className:"text-yellow-400",children:[v," due soon"]}),y===0&&v===0&&"All maintenance up to date"]}):"Configure maintenance types and intervals"})]}),h.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[h.jsx("button",{onClick:()=>i("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Status"}),h.jsx("button",{onClick:()=>i("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Settings"})]}),n==="status"?h.jsx("div",{className:"space-y-4",children:r&&r.length>0?[...r].sort((x,M)=>x.printer_name.localeCompare(M.printer_name)).map(x=>h.jsx(YVe,{overview:x,onPerform:m,onToggle:g,onSetHours:b},x.printer_id)):h.jsx(Xt,{children:h.jsxs(en,{className:"text-center py-12",children:[h.jsx(zp,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),h.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),h.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to start tracking maintenance"})]})})}):h.jsx(ZVe,{overview:r,types:s||[],onUpdateInterval:(x,M)=>l.mutate({id:x,data:{custom_interval_hours:M}}),onAddType:x=>c.mutate(x),onDeleteType:x=>u.mutate(x)})]})}function JVe({printerId:t,isConnected:e}){const[n,i]=E.useState(!1),[r,a]=E.useState(!1),[s,o]=E.useState(null),l=E.useRef(null),c=He.getCameraStreamUrl(t,10),u=()=>{n?(i(!1),o(null)):(a(!0),o(null),i(!0))},f=()=>{a(!1),o(null)},m=()=>{a(!1),o("Failed to load camera stream")},g=()=>{l.current&&(document.fullscreenElement?document.exitFullscreen():l.current.requestFullscreen())},b=()=>{i(!1),setTimeout(()=>{a(!0),i(!0)},100)};return h.jsx("div",{className:"relative w-full h-full bg-black",children:n?h.jsxs(h.Fragment,{children:[r&&h.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:h.jsx(It,{className:"w-8 h-8 animate-spin text-bambu-green"})}),s?h.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-red-400",children:[h.jsx(jae,{className:"w-12 h-12 mb-2"}),h.jsx("span",{className:"text-sm",children:s}),h.jsx("button",{onClick:b,className:"mt-2 text-xs text-bambu-green hover:underline",children:"Retry"})]}):h.jsx("img",{ref:l,src:c,alt:"Camera stream",className:"w-full h-full object-contain",onLoad:f,onError:m}),h.jsxs("div",{className:"absolute top-2 right-2 flex gap-2",children:[h.jsx("button",{onClick:b,className:"p-2 rounded bg-black/50 hover:bg-black/70 text-white transition-colors",title:"Refresh stream",children:h.jsx(Zo,{className:"w-4 h-4"})}),h.jsx("button",{onClick:g,className:"p-2 rounded bg-black/50 hover:bg-black/70 text-white transition-colors",title:"Fullscreen",children:h.jsx(JG,{className:"w-4 h-4"})}),h.jsx("button",{onClick:u,className:"px-3 py-1.5 rounded bg-red-500/80 hover:bg-red-500 text-white text-sm transition-colors",children:"Stop"})]})]}):h.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-bambu-gray",children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 flex flex-col items-center",children:[h.jsx(I_,{className:"w-8 h-8 mb-2"}),h.jsx("span",{className:"text-sm mb-3",children:e?"Click Start to view camera":"Printer not connected"}),h.jsx("button",{onClick:u,disabled:!e,className:"px-4 py-1.5 rounded text-sm bg-bambu-green text-white hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed",children:"Start"})]})})})}function e$e(t){if(!t)return"N/A";const e=new Date;return new Date(e.getTime()+t*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function t$e({printerId:t,status:e}){const n=Gn(),[i,r]=E.useState(null),a=e?.connected??!1,s=e?.state==="RUNNING",o=e?.state==="PAUSE",l=e?.progress??0,c=yt({mutationFn:()=>He.pausePrint(t),onSuccess:()=>{n.invalidateQueries({queryKey:["printerStatuses"]})}}),u=yt({mutationFn:()=>He.resumePrint(t),onSuccess:()=>{n.invalidateQueries({queryKey:["printerStatuses"]})}}),f=yt({mutationFn:x=>He.stopPrint(t,x),onSuccess:x=>{Bx(x)?r({action:"stop",token:x.token,warning:x.warning}):n.invalidateQueries({queryKey:["printerStatuses"]})}}),m=()=>{s?c.mutate():o&&u.mutate()},g=()=>{f.mutate(void 0)},b=()=>{i&&(f.mutate(i.token),r(null))},y=c.isPending||u.isPending||f.isPending,v=a&&(s||o);return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-3",children:"Printing Progress"}),h.jsxs("div",{className:"flex gap-4 items-center",children:[h.jsx("div",{className:"w-20 h-20 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg flex items-center justify-center flex-shrink-0 overflow-hidden",children:e?.subtask_name?h.jsx("img",{src:`/api/v1/archives/thumbnail/${encodeURIComponent(e.subtask_name)}`,alt:"",className:"w-full h-full object-contain",onError:x=>{x.target.style.display="none",x.target.parentElement.innerHTML='Bambu
Lab
'}}):h.jsxs("span",{className:"text-xs text-bambu-gray text-center",children:["Bambu",h.jsx("br",{}),"Lab"]})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"font-medium text-sm text-white truncate mb-0.5",children:e?.subtask_name||"N/A"}),h.jsx("div",{className:`text-sm mb-2 ${e?.state==="RUNNING"||e?.state==="PAUSE"?"text-bambu-green":"text-bambu-gray"}`,children:e?.state||"N/A"}),h.jsx("div",{className:"h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mb-2",children:h.jsx("div",{className:`h-full transition-all duration-300 ${e?.state==="PAUSE"?"bg-yellow-500":"bg-bambu-green"}`,style:{width:`${l}%`}})}),h.jsxs("div",{className:"text-xs text-bambu-gray mb-1",children:["Layer: ",e?.layer_num??"N/A"," / ",e?.total_layers??"N/A","    ",Math.round(l),"%"]}),h.jsxs("div",{className:"text-xs text-bambu-gray",children:["Estimated finish time: ",e$e(e?.remaining_time)]})]}),h.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[h.jsx("button",{onClick:m,disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:s?"Pause":"Resume",children:c.isPending||u.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(e9,{className:"w-4 h-4"})}),h.jsx("button",{onClick:g,disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Stop",children:f.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Up,{className:"w-4 h-4"})}),h.jsx("button",{disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Skip Objects",children:h.jsx("img",{src:"/icons/skip-objects.svg",alt:"Skip Objects",className:"w-4 h-4 icon-theme"})})]})]}),(c.error||u.error||f.error)&&h.jsx("p",{className:"mt-2 text-xs text-red-500",children:(c.error||u.error||f.error)?.message}),i&&h.jsx(rr,{title:"Confirm Stop",message:i.warning,confirmText:"Stop Print",variant:"danger",onConfirm:b,onCancel:()=>r(null)})]})}function n$e({checked:t,onChange:e,disabled:n}){return h.jsx("button",{onClick:()=>!n&&e(!t),disabled:n,className:`w-11 h-6 rounded-full relative transition-all shadow-inner border ${t?"bg-bambu-green border-bambu-green":"bg-bambu-dark-tertiary border-bambu-dark-tertiary"} ${n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:h.jsx("div",{className:`w-5 h-5 rounded-full bg-white shadow-md absolute top-0.5 transition-transform ${t?"translate-x-5":"translate-x-0.5"}`})})}function cN({name:t,icon:e,speed:n,enabled:i,onToggle:r,onSpeedChange:a,disabled:s,showSpeedControl:o=!0}){const l=()=>{const u=Math.min(100,n+10);a(u)},c=()=>{const u=Math.max(0,n-10);a(u)};return h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-4 shadow-lg border border-bambu-dark-tertiary/50",children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsxs("div",{className:"flex items-center gap-2.5",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center",children:e}),h.jsx("span",{className:"text-white font-medium",children:t})]}),o&&h.jsx(n$e,{checked:i,onChange:r,disabled:s})]}),o?h.jsxs("div",{className:"flex items-center justify-between bg-bambu-dark-secondary rounded-lg p-2",children:[h.jsx("button",{onClick:c,disabled:s||!i,className:"w-9 h-9 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center text-white hover:bg-bambu-dark transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:h.jsx(loe,{className:"w-4 h-4"})}),h.jsx("div",{className:"flex-1 text-center",children:h.jsxs("span",{className:`text-xl font-semibold ${i?"text-white":"text-bambu-gray"}`,children:[n,"%"]})}),h.jsx("button",{onClick:l,disabled:s||!i,className:"w-9 h-9 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center text-white hover:bg-bambu-dark transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:h.jsx(Yo,{className:"w-4 h-4"})})]}):h.jsx("div",{className:"p-3 text-center",children:h.jsx("span",{className:"text-xl font-semibold text-bambu-green",children:i?"Auto":"Off"})})]})}function i$e({onConfirm:t,onCancel:e}){return h.jsx("div",{className:"absolute inset-0 bg-black/80 flex items-center justify-center z-10 rounded-2xl",children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-5 m-4 max-w-sm border border-bambu-dark-tertiary shadow-xl",children:[h.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[h.jsx("div",{className:"w-10 h-10 rounded-full bg-yellow-500/20 flex items-center justify-center flex-shrink-0",children:h.jsx(va,{className:"w-5 h-5 text-yellow-500"})}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-white font-semibold",children:"Print in Progress"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"The printer is currently controlling air conditioning."})]})]}),h.jsx("p",{className:"text-sm text-bambu-gray mb-5",children:"Changing these settings during a print may affect print quality. Are you sure you want to continue?"}),h.jsxs("div",{className:"flex gap-3",children:[h.jsx("button",{onClick:e,className:"flex-1 py-2.5 px-4 rounded-lg font-medium text-sm bg-bambu-dark-tertiary text-white hover:bg-bambu-dark transition-colors",children:"Cancel"}),h.jsx("button",{onClick:t,className:"flex-1 py-2.5 px-4 rounded-lg font-medium text-sm bg-yellow-600 text-white hover:bg-yellow-700 transition-colors",children:"Continue"})]})]})})}function r$e({printer:t,status:e,onClose:n}){const i=e?.connected??!1,r=e?.state==="RUNNING"||e?.state==="PRINTING",a=!i,s=(e?.airduct_mode??0)===1?"heating":"cooling",[o,l]=E.useState(s),[c,u]=E.useState(!1),[f,m]=E.useState(null),[g,b]=E.useState(!1),[y,v]=E.useState(0),[x,M]=E.useState(!1),[w,A]=E.useState(0),[T,R]=E.useState(!1),[N,j]=E.useState(0),C=yt({mutationFn:ee=>He.setAirductMode(t.id,ee)}),k=yt({mutationFn:ee=>He.setPartFan(t.id,ee)}),F=yt({mutationFn:ee=>He.setAuxFan(t.id,ee)}),I=yt({mutationFn:ee=>He.setChamberFan(t.id,ee)}),W=ee=>{r?(m(()=>ee),u(!0)):ee()},O=()=>{f&&(f(),m(null)),u(!1)},H=()=>{m(null),u(!1)},V=ee=>{ee!==o&&W(()=>{l(ee),C.mutate(ee)})},$=ee=>{W(()=>{b(ee),ee||(v(0),k.mutate(0))})},K=ee=>{W(()=>{v(ee),b(ee>0),k.mutate(ee)})},Y=ee=>{W(()=>{M(ee),ee||(A(0),F.mutate(0))})},se=ee=>{W(()=>{A(ee),M(ee>0),F.mutate(ee)})},B=ee=>{W(()=>{R(ee),ee||(j(0),I.mutate(0))})},X=ee=>{W(()=>{j(ee),R(ee>0),I.mutate(ee)})};E.useEffect(()=>{const ee=ve=>{ve.key==="Escape"&&(c?H():n())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[n,c]);const ae={cooling:"Suitable for PLA, PETG, TPU. Filters and cools the chamber air.",heating:"Suitable for ABS, ASA, PC, PA. Circulates and heats chamber air."},ce=()=>h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-theme"}),xe=()=>h.jsx("img",{src:"/icons/chamber.svg",alt:"",className:"w-5 h-5 icon-theme"});return h.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:n,children:h.jsxs("div",{className:"relative w-full max-w-lg bg-bambu-dark-secondary rounded-2xl shadow-2xl border border-bambu-dark-tertiary overflow-hidden",onClick:ee=>ee.stopPropagation(),children:[c&&h.jsx(i$e,{onConfirm:O,onCancel:H}),h.jsxs("div",{className:"flex items-center justify-between px-5 py-4 bg-bambu-dark border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-green"})}),h.jsx("span",{className:"text-base font-semibold text-white",children:"Air Condition"})]}),h.jsx("button",{onClick:n,className:"w-8 h-8 rounded-lg flex items-center justify-center text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("div",{className:"p-5 space-y-5",children:[r&&h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-yellow-500 flex-shrink-0"}),h.jsx("span",{className:"text-xs text-yellow-500",children:"Print in progress. Changes may affect print quality."})]}),h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-1.5 flex gap-1.5 shadow-inner",children:[h.jsxs("button",{onClick:()=>V("cooling"),disabled:a||C.isPending,className:`flex-1 py-3 px-4 rounded-lg flex items-center justify-center gap-2 font-medium transition-all disabled:opacity-50 ${o==="cooling"?"bg-bambu-green text-white shadow-lg":"text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:[h.jsx(vle,{className:"w-4 h-4"}),"Cooling"]}),h.jsxs("button",{onClick:()=>V("heating"),disabled:a||C.isPending,className:`flex-1 py-3 px-4 rounded-lg flex items-center justify-center gap-2 font-medium transition-all disabled:opacity-50 ${o==="heating"?"bg-bambu-green text-white shadow-lg":"text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:[h.jsx(XG,{className:"w-4 h-4"}),"Heating"]})]}),h.jsx("p",{className:"text-sm text-bambu-gray text-center px-2",children:ae[o]}),h.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsx(cN,{name:"Part",icon:h.jsx(ce,{}),speed:y,enabled:g,onToggle:$,onSpeedChange:K,disabled:a,showSpeedControl:!0}),h.jsx(cN,{name:"Aux",icon:h.jsx(ce,{}),speed:w,enabled:x,onToggle:Y,onSpeedChange:se,disabled:a,showSpeedControl:o==="cooling"}),h.jsx(cN,{name:"Exhaust",icon:h.jsx(ce,{}),speed:N,enabled:T,onToggle:B,onSpeedChange:X,disabled:a,showSpeedControl:o==="cooling"}),h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-4 shadow-lg border border-bambu-dark-tertiary/50",children:[h.jsxs("div",{className:"flex items-center gap-2.5 mb-4",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center",children:h.jsx(xe,{})}),h.jsx("span",{className:"text-white font-medium",children:"Heat"})]}),h.jsx("div",{className:"p-3 text-center",children:h.jsx("span",{className:"text-xl font-semibold text-bambu-green",children:o==="heating"?"Auto":"Off"})})]})]})]})]})})}const a$e=[{mode:1,name:"Silent",description:"Quieter printing, slower speed",percentage:"50%"},{mode:2,name:"Standard",description:"Balanced speed and quality",percentage:"100%"},{mode:3,name:"Sport",description:"Faster printing, moderate noise",percentage:"124%"},{mode:4,name:"Ludicrous",description:"Maximum speed",percentage:"166%"}];function s$e({printer:t,status:e,onClose:n}){const i=e?.connected??!1,r=e?.state==="RUNNING"||e?.state==="PRINTING",a=!i||!r,s=e?.speed_level??2,[o,l]=E.useState(s),c=yt({mutationFn:f=>He.setPrintSpeed(t.id,f)}),u=f=>{f===o||a||(l(f),c.mutate(f))};return E.useEffect(()=>{const f=m=>{m.key==="Escape"&&n()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[n]),h.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:n,children:h.jsxs("div",{className:"relative w-full max-w-md bg-bambu-dark-secondary rounded-2xl shadow-2xl border border-bambu-dark-tertiary overflow-hidden",onClick:f=>f.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-5 py-4 bg-bambu-dark border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:h.jsx("img",{src:"/icons/speed.svg",alt:"",className:"w-5 h-5 icon-green"})}),h.jsx("span",{className:"text-base font-semibold text-white",children:"Print Speed"})]}),h.jsx("button",{onClick:n,className:"w-8 h-8 rounded-lg flex items-center justify-center text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("div",{className:"p-5 space-y-4",children:[r?h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-yellow-500 flex-shrink-0"}),h.jsx("span",{className:"text-xs text-yellow-500",children:"Speed changes take effect immediately."})]}):h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),h.jsx("span",{className:"text-xs text-bambu-gray",children:"No print in progress. Speed can only be changed during printing."})]}),h.jsx("div",{className:"space-y-2",children:a$e.map(f=>h.jsxs("button",{onClick:()=>u(f.mode),disabled:a||c.isPending,className:`w-full p-4 rounded-xl flex items-center justify-between transition-all disabled:opacity-50 disabled:cursor-not-allowed ${o===f.mode?"bg-bambu-green text-white shadow-lg":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary"}`,children:[h.jsxs("div",{className:"flex flex-col items-start",children:[h.jsx("span",{className:"font-medium",children:f.name}),h.jsx("span",{className:`text-xs ${o===f.mode?"text-white/80":"text-bambu-gray"}`,children:f.description})]}),h.jsx("span",{className:`text-lg font-semibold ${o===f.mode?"text-white":"text-bambu-gray"}`,children:f.percentage})]},f.mode))})]})]})})}function o$e({printer:t,status:e,disabled:n=!1}){const i=e?.temperatures??{},r=t.nozzle_count>1,a=(e?.connected??!1)&&!n,[s,o]=E.useState(null),[l,c]=E.useState(""),[u,f]=E.useState(!1),[m,g]=E.useState(!1),b=yt({mutationFn:I=>He.setBedTemperature(t.id,I)}),y=yt({mutationFn:({target:I,nozzle:W})=>He.setNozzleTemperature(t.id,I,W)}),v=yt({mutationFn:I=>He.setChamberTemperature(t.id,I)}),x=yt({mutationFn:I=>He.setChamberLight(t.id,I)}),M=(I,W)=>{a&&(o(I),c(String(Math.round(W))))},w=()=>{o(null),c("")},A=()=>{const I=parseInt(l,10);if(isNaN(I)||I<0){w();return}s==="bed"?b.mutate(I):s==="nozzle"?y.mutate({target:I,nozzle:r?1:0}):s==="nozzle_2"?y.mutate({target:I,nozzle:0}):s==="chamber"&&v.mutate(I),w()},T=I=>{I.key==="Enter"?A():I.key==="Escape"&&w()},R=!a,N=i.nozzle_heating??!1,j=i.nozzle_2_heating??!1,C=i.bed_heating??!1,k=i.chamber_heating??!1,F=(I,W)=>s===I?h.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",value:l,onChange:O=>{const H=O.target.value.replace(/[^0-9]/g,"");c(H)},onBlur:A,onKeyDown:T,autoFocus:!0,className:"w-12 text-sm bg-bambu-dark border border-bambu-green rounded px-1 py-0.5 text-white text-center [appearance:textfield]"}):h.jsxs("button",{onClick:()=>M(I,W),disabled:R,className:"text-sm text-bambu-gray hover:text-bambu-green disabled:hover:text-bambu-gray disabled:cursor-not-allowed",title:R?"Printer not connected":"Click to set target temperature",children:["/",Math.round(W)," °C"]});return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col justify-evenly min-w-[150px] pr-5 border-r border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/hotend.svg",alt:"",className:`w-5 ${N?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"text-[11px] font-semibold text-bambu-green bg-bambu-green/20 px-1.5 py-0.5 rounded min-w-[18px] text-center flex-shrink-0",children:"L"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.nozzle??0)}),F("nozzle",i.nozzle_target??0)]}),r&&h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/hotend.svg",alt:"",className:`w-5 ${j?"icon-heating":"icon-theme"}`})}),h.jsx("span",{className:"text-[11px] font-semibold text-bambu-green bg-bambu-green/20 px-1.5 py-0.5 rounded min-w-[18px] text-center flex-shrink-0",children:"R"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.nozzle_2??0)}),F("nozzle_2",i.nozzle_2_target??0)]}),h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/heatbed.svg",alt:"",className:`w-5 ${C?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"min-w-[18px] flex-shrink-0"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.bed??0)}),F("bed",i.bed_target??0)]}),h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/chamber.svg",alt:"",className:`w-5 ${k?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"min-w-[18px] flex-shrink-0"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.chamber??0)}),F("chamber",i.chamber_target??0)]}),h.jsxs("button",{onClick:()=>f(!0),disabled:R,className:"flex items-center justify-center gap-2 w-full py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-theme"}),h.jsx("span",{className:"text-xs text-bambu-gray",children:"Air Condition"})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("button",{onClick:()=>g(!0),disabled:R,className:"flex-1 flex flex-col items-center py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsx("img",{src:"/icons/speed.svg",alt:"",className:"w-5 h-5 icon-theme"}),h.jsx("span",{className:"text-[10px] text-bambu-gray mt-0.5",children:e?.speed_level===1?"50%":e?.speed_level===3?"124%":e?.speed_level===4?"166%":"100%"})]}),h.jsxs("button",{onClick:()=>x.mutate(!(e?.chamber_light??!1)),disabled:R||x.isPending,className:"flex-1 flex flex-col items-center py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsx("img",{src:"/icons/lamp.svg",alt:"",className:`w-5 h-5 ${e?.chamber_light?"icon-green":"icon-theme"}`}),h.jsx("span",{className:"text-[10px] text-bambu-gray mt-0.5",children:"Lamp"})]})]})]}),u&&h.jsx(r$e,{printer:t,status:e,onClose:()=>f(!1)}),m&&h.jsx(s$e,{printer:t,status:e,onClose:()=>g(!1)})]})}function l$e({printerId:t,status:e,disabled:n=!1}){const i=(e?.connected??!1)&&!n,[r,a]=E.useState(null),s=yt({mutationFn:({axes:g,token:b})=>He.homeAxes(t,g,b),onSuccess:g=>{Bx(g)&&a({action:"home",token:g.token,warning:g.warning,onConfirm:()=>s.mutate({axes:"XY",token:g.token})})}}),o=yt({mutationFn:({axis:g,distance:b,token:y})=>He.moveAxis(t,g,b,3e3,y),onSuccess:(g,b)=>{Bx(g)&&a({action:"move",token:g.token,warning:g.warning,onConfirm:()=>o.mutate({axis:b.axis,distance:b.distance,token:g.token})})}}),l=()=>{s.mutate({axes:"XY"})},c=(g,b)=>{o.mutate({axis:g,distance:b})},u=()=>{r&&(r.onConfirm(),a(null))},f=s.isPending||o.isPending,m=!i||f;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"relative w-[220px] h-[220px] mb-3.5",children:[h.jsx("img",{src:"/icons/jogpad.svg",alt:"Jog Pad",className:"w-full h-full jogpad-theme"}),h.jsx("button",{onClick:()=>c("Y",10),disabled:m,className:"absolute top-[8px] left-1/2 -translate-x-1/2 w-[40px] h-[30px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y+10"}),h.jsx("button",{onClick:()=>c("Y",-10),disabled:m,className:"absolute bottom-[8px] left-1/2 -translate-x-1/2 w-[40px] h-[30px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y-10"}),h.jsx("button",{onClick:()=>c("X",-10),disabled:m,className:"absolute left-[8px] top-1/2 -translate-y-1/2 w-[30px] h-[40px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X-10"}),h.jsx("button",{onClick:()=>c("X",10),disabled:m,className:"absolute right-[8px] top-1/2 -translate-y-1/2 w-[30px] h-[40px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X+10"}),h.jsx("button",{onClick:()=>c("Y",1),disabled:m,className:"absolute top-[42px] left-1/2 -translate-x-1/2 w-[35px] h-[25px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y+1"}),h.jsx("button",{onClick:()=>c("Y",-1),disabled:m,className:"absolute bottom-[42px] left-1/2 -translate-x-1/2 w-[35px] h-[25px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y-1"}),h.jsx("button",{onClick:()=>c("X",-1),disabled:m,className:"absolute left-[42px] top-1/2 -translate-y-1/2 w-[25px] h-[35px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X-1"}),h.jsx("button",{onClick:()=>c("X",1),disabled:m,className:"absolute right-[42px] top-1/2 -translate-y-1/2 w-[25px] h-[35px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X+1"}),h.jsx("button",{onClick:l,disabled:m,className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[50px] h-[50px] rounded-full opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Home XY"})]}),r&&h.jsx(rr,{title:"Confirm Action",message:r.warning,confirmText:"Continue",variant:"warning",onConfirm:u,onCancel:()=>a(null)})]})}function c$e({printerId:t,status:e,disabled:n=!1}){const i=(e?.connected??!1)&&!n,[r,a]=E.useState(null),s=yt({mutationFn:({distance:u,token:f})=>He.moveAxis(t,"Z",u,1e3,f),onSuccess:(u,f)=>{Bx(u)&&a({token:u.token,warning:u.warning,distance:f.distance})}}),o=u=>{s.mutate({distance:u})},l=()=>{r&&(s.mutate({distance:r.distance,token:r.token}),a(null))},c=!i||s.isPending;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("button",{onClick:()=>o(10),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z+10",children:"↑10"}),h.jsx("button",{onClick:()=>o(1),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z+1",children:"↑1"}),h.jsx("span",{className:"px-2 py-2 text-sm text-bambu-gray",children:"Bed"}),h.jsx("button",{onClick:()=>o(-1),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z-1",children:"↓1"}),h.jsx("button",{onClick:()=>o(-10),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z-10",children:"↓10"})]}),r&&h.jsx(rr,{title:"Confirm Bed Movement",message:r.warning,confirmText:"Continue",variant:"warning",onConfirm:l,onCancel:()=>a(null)})]})}function u$e({printerId:t,status:e,nozzleCount:n,disabled:i=!1}){const r=(e?.connected??!1)&&!i,a=e?.state==="RUNNING"||e?.state==="PAUSE",s=n>1,[o,l]=E.useState("left"),[c,u]=E.useState(null),f=yt({mutationFn:({distance:y,token:v})=>{const M=`${s?`T${o==="left"?0:1} + `},X8e={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 K8e(t){let{announcements:e=X8e,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=q8e}=t;const{announce:a,announcement:s}=$8e(),o=pv("DndLiveRegion"),[l,c]=E.useState(!1);if(E.useEffect(()=>{c(!0)},[]),G8e(E.useMemo(()=>({onDragStart(f){let{active:m}=f;a(e.onDragStart({active:m}))},onDragMove(f){let{active:m,over:g}=f;e.onDragMove&&a(e.onDragMove({active:m,over:g}))},onDragOver(f){let{active:m,over:g}=f;a(e.onDragOver({active:m,over:g}))},onDragEnd(f){let{active:m,over:g}=f;a(e.onDragEnd({active:m,over:g}))},onDragCancel(f){let{active:m,over:g}=f;a(e.onDragCancel({active:m,over:g}))}}),[a,e])),!l)return null;const u=ui.createElement(ui.Fragment,null,ui.createElement(H8e,{id:i,value:r.draggable}),ui.createElement(V8e,{id:o,announcement:s}));return n?Yl.createPortal(u,n):u}var nr;(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"})(nr||(nr={}));function jS(){}function B$(t,e){return E.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Y8e(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const wo=Object.freeze({x:0,y:0});function _J(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function SJ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function Z8e(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function H$(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 wJ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function V$(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 Q8e=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=V$(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=_J(V$(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(SJ)},J8e=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=H$(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=H$(l),u=r.reduce((m,g,b)=>m+_J(c[b],g),0),f=Number((u/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(SJ)};function e6e(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=e6e(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(Z8e)};function n6e(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function MJ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:wo}function i6e(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 r6e=i6e(1);function a6e(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 s6e(t,e,n){const i=a6e(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)),u=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:u,height:f,top:c,right:l+u,bottom:c+f,left:l}}const o6e={ignoreTransform:!1};function jm(t,e){e===void 0&&(e=o6e);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:u}=Ga(t).getComputedStyle(t);c&&(n=s6e(n,c,u))}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 $$(t){return jm(t,{ignoreTransform:!0})}function l6e(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function c6e(t,e){return e===void 0&&(e=Ga(t).getComputedStyle(t)),e.position==="fixed"}function u6e(t,e){e===void 0&&(e=Ga(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 dM(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(ZO(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!fv(r)||vJ(r)||n.includes(r))return n;const a=Ga(t).getComputedStyle(r);return r!==t&&u6e(r,a)&&n.push(r),c6e(r,a)?n:i(r.parentNode)}return t?i(t):n}function EJ(t){const[e]=dM(t,1);return e??null}function aN(t){return!uM||!t?null:Lm(t)?t:YO(t)?ZO(t)||t===Im(t).scrollingElement?window:fv(t)?t:null:null}function AJ(t){return Lm(t)?t.scrollX:t.scrollLeft}function TJ(t){return Lm(t)?t.scrollY:t.scrollTop}function pP(t){return{x:AJ(t),y:TJ(t)}}var Mr;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(Mr||(Mr={}));function CJ(t){return!uM||!t?!1:t===document.scrollingElement}function NJ(t){const e={x:0,y:0},n=CJ(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 d6e={x:.2,y:.2};function f6e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=d6e);const{isTop:c,isBottom:u,isLeft:f,isRight:m}=NJ(t),g={x:0,y:0},b={x:0,y:0},y={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+y.height?(g.y=Mr.Backward,b.y=i*Math.abs((e.top+y.height-a)/y.height)):!u&&l>=e.bottom-y.height&&(g.y=Mr.Forward,b.y=i*Math.abs((e.bottom-y.height-l)/y.height)),!m&&o>=e.right-y.width?(g.x=Mr.Forward,b.x=i*Math.abs((e.right-y.width-o)/y.width)):!f&&s<=e.left+y.width&&(g.x=Mr.Backward,b.x=i*Math.abs((e.left+y.width-s)/y.width)),{direction:g,speed:b}}function h6e(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 RJ(t){return t.reduce((e,n)=>Ip(e,pP(n)),wo)}function p6e(t){return t.reduce((e,n)=>e+AJ(n),0)}function m6e(t){return t.reduce((e,n)=>e+TJ(n),0)}function g6e(t,e){if(e===void 0&&(e=jm),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);EJ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const x6e=[["x",["left","right"],p6e],["y",["top","bottom"],m6e]];class eL{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=dM(n),r=RJ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of x6e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),u=r[a]-c;return this.rect[l]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Rx{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 v6e(t){const{EventTarget:e}=Ga(t);return t instanceof e?t:Im(t)}function sN(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 Ls;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Ls||(Ls={}));function G$(t){t.preventDefault()}function b6e(t){t.stopPropagation()}var _n;(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"})(_n||(_n={}));const PJ={start:[_n.Space,_n.Enter],cancel:[_n.Esc],end:[_n.Space,_n.Enter,_n.Tab]},y6e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case _n.Right:return{...n,x:n.x+25};case _n.Left:return{...n,x:n.x-25};case _n.Down:return{...n,y:n.y+25};case _n.Up:return{...n,y:n.y-25}}};class tL{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 Rx(Im(n)),this.windowListeners=new Rx(Ga(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ls.Resize,this.handleCancel),this.windowListeners.add(Ls.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ls.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&g6e(i),n(wo)}handleKeyDown(e){if(JO(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=PJ,coordinateGetter:s=y6e,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,u=c?{x:c.left,y:c.top}:wo;this.referenceCoordinates||(this.referenceCoordinates=u);const f=s(e,{active:n,context:i.current,currentCoordinates:u});if(f){const m=M0(f,u),g={x:0,y:0},{scrollableAncestors:b}=i.current;for(const y of b){const v=e.code,{isTop:x,isRight:M,isLeft:w,isBottom:A,maxScroll:T,minScroll:R}=NJ(y),N=h6e(y),j={x:Math.min(v===_n.Right?N.right-N.width/2:N.right,Math.max(v===_n.Right?N.left:N.left+N.width/2,f.x)),y:Math.min(v===_n.Down?N.bottom-N.height/2:N.bottom,Math.max(v===_n.Down?N.top:N.top+N.height/2,f.y))},C=v===_n.Right&&!M||v===_n.Left&&!w,k=v===_n.Down&&!A||v===_n.Up&&!x;if(C&&j.x!==f.x){const F=y.scrollLeft+m.x,I=v===_n.Right&&F<=T.x||v===_n.Left&&F>=R.x;if(I&&!m.y){y.scrollTo({left:F,behavior:o});return}I?g.x=y.scrollLeft-F:g.x=v===_n.Right?y.scrollLeft-T.x:y.scrollLeft-R.x,g.x&&y.scrollBy({left:-g.x,behavior:o});break}else if(k&&j.y!==f.y){const F=y.scrollTop+m.y,I=v===_n.Down&&F<=T.y||v===_n.Up&&F>=R.y;if(I&&!m.x){y.scrollTo({top:F,behavior:o});return}I?g.y=y.scrollTop-F:g.y=v===_n.Down?y.scrollTop-T.y:y.scrollTop-R.y,g.y&&y.scrollBy({top:-g.y,behavior:o});break}}this.handleMove(e,Ip(M0(f,this.referenceCoordinates),g))}}}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()}}tL.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=PJ,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 W$(t){return!!(t&&"distance"in t)}function q$(t){return!!(t&&"delay"in t)}class nL{constructor(e,n,i){var r;i===void 0&&(i=v6e(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=Im(s),this.documentListeners=new Rx(this.document),this.listeners=new Rx(i),this.windowListeners=new Rx(Ga(s)),this.initialCoordinates=(r=hP(a))!=null?r:wo,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(Ls.Resize,this.handleCancel),this.windowListeners.add(Ls.DragStart,G$),this.windowListeners.add(Ls.VisibilityChange,this.handleCancel),this.windowListeners.add(Ls.ContextMenu,G$),this.documentListeners.add(Ls.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(q$(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(W$(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(Ls.Click,b6e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ls.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=hP(e))!=null?n:wo,c=M0(r,l);if(!i&&o){if(W$(o)){if(o.tolerance!=null&&sN(c,o.tolerance))return this.handleCancel();if(sN(c,o.distance))return this.handleStart()}if(q$(o)&&sN(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===_n.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const _6e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class iL extends nL{constructor(e){const{event:n}=e,i=Im(n.target);super(e,_6e,i)}}iL.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 S6e={move:{name:"mousemove"},end:{name:"mouseup"}};var mP;(function(t){t[t.RightClick=2]="RightClick"})(mP||(mP={}));class w6e extends nL{constructor(e){super(e,S6e,Im(e.event.target))}}w6e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===mP.RightClick?!1:(i?.({event:n}),!0)}}];const oN={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class M6e extends nL{constructor(e){super(e,oN)}static setup(){return window.addEventListener(oN.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(oN.move.name,e)};function e(){}}}M6e.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 Px;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(Px||(Px={}));var US;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(US||(US={}));function E6e(t){let{acceleration:e,activator:n=Px.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=US.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:f,threshold:m}=t;const g=T6e({delta:f,disabled:!a}),[b,y]=j8e(),v=E.useRef({x:0,y:0}),x=E.useRef({x:0,y:0}),M=E.useMemo(()=>{switch(n){case Px.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Px.DraggableRect:return r}},[n,r,l]),w=E.useRef(null),A=E.useCallback(()=>{const R=w.current;if(!R)return;const N=v.current.x*x.current.x,j=v.current.y*x.current.y;R.scrollBy(N,j)},[]),T=E.useMemo(()=>o===US.TreeOrder?[...c].reverse():c,[o,c]);E.useEffect(()=>{if(!a||!c.length||!M){y();return}for(const R of T){if(i?.(R)===!1)continue;const N=c.indexOf(R),j=u[N];if(!j)continue;const{direction:C,speed:k}=f6e(R,j,M,e,m);for(const F of["x","y"])g[F][C[F]]||(k[F]=0,C[F]=0);if(k.x>0||k.y>0){y(),w.current=R,b(A,s),v.current=k,x.current=C;return}}v.current={x:0,y:0},x.current={x:0,y:0},y()},[e,A,i,y,a,s,JSON.stringify(M),JSON.stringify(g),b,c,T,u,JSON.stringify(m)])}const A6e={x:{[Mr.Backward]:!1,[Mr.Forward]:!1},y:{[Mr.Backward]:!1,[Mr.Forward]:!1}};function T6e(t){let{delta:e,disabled:n}=t;const i=fP(e);return hv(r=>{if(n||!i||!r)return A6e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[Mr.Backward]:r.x[Mr.Backward]||a.x===-1,[Mr.Forward]:r.x[Mr.Forward]||a.x===1},y:{[Mr.Backward]:r.y[Mr.Backward]||a.y===-1,[Mr.Forward]:r.y[Mr.Forward]||a.y===1}}},[n,e,i])}function C6e(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 N6e(t,e){return E.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 A0;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(A0||(A0={}));var gP;(function(t){t.Optimized="optimized"})(gP||(gP={}));const X$=new Map;function R6e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=E.useState(null),{frequency:o,measure:l,strategy:c}=r,u=E.useRef(t),f=v(),m=w0(f),g=E.useCallback(function(x){x===void 0&&(x=[]),!m.current&&s(M=>M===null?x:M.concat(x.filter(w=>!M.includes(w))))},[m]),b=E.useRef(null),y=hv(x=>{if(f&&!n)return X$;if(!x||x===X$||u.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 A=w.node.current,T=A?new eL(l(A),A):null;w.rect.current=T,T&&M.set(w.id,T)}return M}return x},[t,a,n,f,l]);return E.useEffect(()=>{u.current=t},[t]),E.useEffect(()=>{f||g()},[n,f]),E.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),E.useEffect(()=>{f||typeof o!="number"||b.current!==null||(b.current=setTimeout(()=>{g(),b.current=null},o))},[o,f,g,...i]),{droppableRects:y,measureDroppableContainers:g,measuringScheduled:a!=null};function v(){switch(c){case A0.Always:return!1;case A0.BeforeDragging:return n;default:return!n}}}function kJ(t,e){return hv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function P6e(t,e){return kJ(t,e)}function k6e(t){let{callback:e,disabled:n}=t;const i=QO(e),r=E.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return E.useEffect(()=>()=>r?.disconnect(),[r]),r}function fM(t){let{callback:e,disabled:n}=t;const i=QO(e),r=E.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return E.useEffect(()=>()=>r?.disconnect(),[r]),r}function D6e(t){return new eL(jm(t),t)}function K$(t,e,n){e===void 0&&(e=D6e);const[i,r]=E.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const u=e(t);return JSON.stringify(l)===JSON.stringify(u)?l:u})}const s=k6e({callback(l){if(t)for(const c of l){const{type:u,target:f}=c;if(u==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=fM({callback:a});return al(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function O6e(t){const e=kJ(t);return MJ(t,e)}const Y$=[];function L6e(t){const e=E.useRef(t),n=hv(i=>t?i&&i!==Y$&&t&&e.current&&t.parentNode===e.current.parentNode?i:dM(t):Y$,[t]);return E.useEffect(()=>{e.current=t},[t]),n}function I6e(t){const[e,n]=E.useState(null),i=E.useRef(t),r=E.useCallback(a=>{const s=aN(a.target);s&&n(o=>o?(o.set(s,pP(s)),new Map(o)):null)},[]);return E.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=aN(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,pP(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=aN(l);c?.removeEventListener("scroll",r)})}},[r,t]),E.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>Ip(a,s),wo):RJ(t):wo,[t,e])}function Z$(t,e){e===void 0&&(e=[]);const n=E.useRef(null);return E.useEffect(()=>{n.current=null},e),E.useEffect(()=>{const i=t!==wo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?M0(t,n.current):wo}function j6e(t){E.useEffect(()=>{if(!uM)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 U6e(t,e){return E.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function DJ(t){return E.useMemo(()=>t?l6e(t):null,[t])}const Q$=[];function F6e(t,e){e===void 0&&(e=jm);const[n]=t,i=DJ(n?Ga(n):null),[r,a]=E.useState(Q$);function s(){a(()=>t.length?t.map(l=>CJ(l)?i:new eL(e(l),l)):Q$)}const o=fM({callback:s});return al(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function z6e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return fv(e)?e:t}function B6e(t){let{measure:e}=t;const[n,i]=E.useState(null),r=E.useCallback(c=>{for(const{target:u}of c)if(fv(u)){i(f=>{const m=e(u);return f?{...f,width:m.width,height:m.height}:m});break}},[e]),a=fM({callback:r}),s=E.useCallback(c=>{const u=z6e(c);a?.disconnect(),u&&a?.observe(u),i(u?e(u):null)},[e,a]),[o,l]=IS(s);return E.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const H6e=[{sensor:iL,options:{}},{sensor:tL,options:{}}],V6e={current:{}},C_={draggable:{measure:$$},droppable:{measure:$$,strategy:A0.WhileDragging,frequency:gP.Optimized},dragOverlay:{measure:jm}};class kx 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 $6e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new kx,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:jS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:C_,measureDroppableContainers:jS,windowRect:null,measuringScheduled:!1},G6e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:jS,draggableNodes:new Map,over:null,measureDroppableContainers:jS},hM=E.createContext(G6e),OJ=E.createContext($6e);function W6e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new kx}}}function q6e(t,e){switch(e.type){case nr.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case nr.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 nr.DragEnd:case nr.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case nr.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new kx(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case nr.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 kx(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case nr.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new kx(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function X6e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=E.useContext(hM),a=fP(i),s=fP(n?.id);return E.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!JO(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 u of[l.current,c.current]){if(!u)continue;const f=z8e(u);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function K6e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function Y6e(t){return E.useMemo(()=>({draggable:{...C_.draggable,...t?.draggable},droppable:{...C_.droppable,...t?.droppable},dragOverlay:{...C_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Z6e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=E.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;al(()=>{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 u=n(c),f=MJ(u,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const m=EJ(c);m&&m.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const LJ=E.createContext({...wo,scaleX:1,scaleY:1});var Mu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Mu||(Mu={}));const Q6e=E.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:u=H6e,collisionDetection:f=t6e,measuring:m,modifiers:g,...b}=e;const y=E.useReducer(q6e,void 0,W6e),[v,x]=y,[M,w]=W8e(),[A,T]=E.useState(Mu.Uninitialized),R=A===Mu.Initialized,{draggable:{active:N,nodes:j,translate:C},droppable:{containers:k}}=v,F=N!=null?j.get(N):null,I=E.useRef({initial:null,translated:null}),W=E.useMemo(()=>{var Oe;return N!=null?{id:N,data:(Oe=F?.data)!=null?Oe:V6e,rect:I}:null},[N,F]),O=E.useRef(null),[H,V]=E.useState(null),[$,K]=E.useState(null),Y=w0(b,Object.values(b)),se=pv("DndDescribedBy",s),B=E.useMemo(()=>k.getEnabled(),[k]),X=Y6e(m),{droppableRects:ae,measureDroppableContainers:ce,measuringScheduled:xe}=R6e(B,{dragging:R,dependencies:[C.x,C.y],config:X.droppable}),ee=C6e(j,N),ve=E.useMemo(()=>$?hP($):null,[$]),Pe=fe(),pe=P6e(ee,X.draggable.measure);Z6e({activeNode:N!=null?j.get(N):null,config:Pe.layoutShiftCompensation,initialRect:pe,measure:X.draggable.measure});const we=K$(ee,X.draggable.measure,pe),ze=K$(ee?ee.parentElement:null),ue=E.useRef({activatorEvent:null,active:null,activeNode:ee,collisionRect:null,collisions:null,droppableRects:ae,draggableNodes:j,draggingNode:null,draggingNodeRect:null,droppableContainers:k,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ht=k.getNodeFor((n=ue.current.over)==null?void 0:n.id),z=B6e({measure:X.dragOverlay.measure}),q=(i=z.nodeRef.current)!=null?i:ee,re=R?(r=z.rect)!=null?r:we:null,J=!!(z.nodeRef.current&&z.rect),te=O6e(J?null:we),oe=DJ(q?Ga(q):null),ke=L6e(R?ht??ee:null),Ne=F6e(ke),ne=K6e(g,{transform:{x:C.x-te.x,y:C.y-te.y,scaleX:1,scaleY:1},activatorEvent:$,active:W,activeNodeRect:we,containerNodeRect:ze,draggingNodeRect:re,over:ue.current.over,overlayNodeRect:z.rect,scrollableAncestors:ke,scrollableAncestorRects:Ne,windowRect:oe}),U=ve?Ip(ve,C):null,L=I6e(ke),Z=Z$(L),me=Z$(L,[we]),be=Ip(ne,Z),he=re?r6e(re,ne):null,Ze=W&&he?f({active:W,collisionRect:he,droppableRects:ae,droppableContainers:B,pointerCoordinates:U}):null,Le=wJ(Ze,"id"),[Xe,st]=E.useState(null),Ie=J?ne:Ip(ne,me),Re=n6e(Ie,(a=Xe?.rect)!=null?a:null,we),pt=E.useRef(null),nt=E.useCallback((Oe,Me)=>{let{sensor:ge,options:Be}=Me;if(O.current==null)return;const ct=j.get(O.current);if(!ct)return;const _t=Oe.nativeEvent,Rt=new ge({active:O.current,activeNode:ct,event:_t,options:Be,context:ue,onAbort(Dt){if(!j.get(Dt))return;const{onDragAbort:qn}=Y.current,pr={id:Dt};qn?.(pr),M({type:"onDragAbort",event:pr})},onPending(Dt,Rn,qn,pr){if(!j.get(Dt))return;const{onDragPending:mr}=Y.current,Rr={id:Dt,constraint:Rn,initialCoordinates:qn,offset:pr};mr?.(Rr),M({type:"onDragPending",event:Rr})},onStart(Dt){const Rn=O.current;if(Rn==null)return;const qn=j.get(Rn);if(!qn)return;const{onDragStart:pr}=Y.current,Zi={activatorEvent:_t,active:{id:Rn,data:qn.data,rect:I}};Yl.unstable_batchedUpdates(()=>{pr?.(Zi),T(Mu.Initializing),x({type:nr.DragStart,initialCoordinates:Dt,active:Rn}),M({type:"onDragStart",event:Zi}),V(pt.current),K(_t)})},onMove(Dt){x({type:nr.DragMove,coordinates:Dt})},onEnd:ln(nr.DragEnd),onCancel:ln(nr.DragCancel)});pt.current=Rt;function ln(Dt){return async function(){const{active:qn,collisions:pr,over:Zi,scrollAdjustedTranslate:mr}=ue.current;let Rr=null;if(qn&&mr){const{cancelDrop:Wr}=Y.current;Rr={activatorEvent:_t,active:qn,collisions:pr,delta:mr,over:Zi},Dt===nr.DragEnd&&typeof Wr=="function"&&await Promise.resolve(Wr(Rr))&&(Dt=nr.DragCancel)}O.current=null,Yl.unstable_batchedUpdates(()=>{x({type:Dt}),T(Mu.Uninitialized),st(null),V(null),K(null),pt.current=null;const Wr=Dt===nr.DragEnd?"onDragEnd":"onDragCancel";if(Rr){const Li=Y.current[Wr];Li?.(Rr),M({type:Wr,event:Rr})}})}}},[j]),tt=E.useCallback((Oe,Me)=>(ge,Be)=>{const ct=ge.nativeEvent,_t=j.get(Be);if(O.current!==null||!_t||ct.dndKit||ct.defaultPrevented)return;const Rt={active:_t};Oe(ge,Me.options,Rt)===!0&&(ct.dndKit={capturedBy:Me.sensor},O.current=Be,nt(ge,Me))},[j,nt]),ut=N6e(u,tt);j6e(u),al(()=>{we&&A===Mu.Initializing&&T(Mu.Initialized)},[we,A]),E.useEffect(()=>{const{onDragMove:Oe}=Y.current,{active:Me,activatorEvent:ge,collisions:Be,over:ct}=ue.current;if(!Me||!ge)return;const _t={active:Me,activatorEvent:ge,collisions:Be,delta:{x:be.x,y:be.y},over:ct};Yl.unstable_batchedUpdates(()=>{Oe?.(_t),M({type:"onDragMove",event:_t})})},[be.x,be.y]),E.useEffect(()=>{const{active:Oe,activatorEvent:Me,collisions:ge,droppableContainers:Be,scrollAdjustedTranslate:ct}=ue.current;if(!Oe||O.current==null||!Me||!ct)return;const{onDragOver:_t}=Y.current,Rt=Be.get(Le),ln=Rt&&Rt.rect.current?{id:Rt.id,rect:Rt.rect.current,data:Rt.data,disabled:Rt.disabled}:null,Dt={active:Oe,activatorEvent:Me,collisions:ge,delta:{x:ct.x,y:ct.y},over:ln};Yl.unstable_batchedUpdates(()=>{st(ln),_t?.(Dt),M({type:"onDragOver",event:Dt})})},[Le]),al(()=>{ue.current={activatorEvent:$,active:W,activeNode:ee,collisionRect:he,collisions:Ze,droppableRects:ae,draggableNodes:j,draggingNode:q,draggingNodeRect:re,droppableContainers:k,over:Xe,scrollableAncestors:ke,scrollAdjustedTranslate:be},I.current={initial:re,translated:he}},[W,ee,Ze,he,j,q,re,ae,k,Xe,ke,be]),E6e({...Pe,delta:C,draggingRect:he,pointerCoordinates:U,scrollableAncestors:ke,scrollableAncestorRects:Ne});const de=E.useMemo(()=>({active:W,activeNode:ee,activeNodeRect:we,activatorEvent:$,collisions:Ze,containerNodeRect:ze,dragOverlay:z,draggableNodes:j,droppableContainers:k,droppableRects:ae,over:Xe,measureDroppableContainers:ce,scrollableAncestors:ke,scrollableAncestorRects:Ne,measuringConfiguration:X,measuringScheduled:xe,windowRect:oe}),[W,ee,we,$,Ze,ze,z,j,k,ae,Xe,ce,ke,Ne,X,xe,oe]),it=E.useMemo(()=>({activatorEvent:$,activators:ut,active:W,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:x,draggableNodes:j,over:Xe,measureDroppableContainers:ce}),[$,ut,W,we,x,se,j,Xe,ce]);return ui.createElement(yJ.Provider,{value:w},ui.createElement(hM.Provider,{value:it},ui.createElement(OJ.Provider,{value:de},ui.createElement(LJ.Provider,{value:Re},c)),ui.createElement(X6e,{disabled:o?.restoreFocus===!1})),ui.createElement(K8e,{...o,hiddenTextDescribedById:se}));function fe(){const Oe=H?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=R&&!Oe&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),J6e=E.createContext(null),J$="button",eVe="Draggable";function tVe(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=pv(eVe),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:f,over:m}=E.useContext(hM),{role:g=J$,roleDescription:b="draggable",tabIndex:y=0}=r??{},v=l?.id===e,x=E.useContext(v?LJ:J6e),[M,w]=IS(),[A,T]=IS(),R=U6e(s,e),N=w0(n);al(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:A,data:N}),()=>{const C=f.get(e);C&&C.key===a&&f.delete(e)}),[f,e]);const j=E.useMemo(()=>({role:g,tabIndex:y,"aria-disabled":i,"aria-pressed":v&&g===J$?!0:void 0,"aria-roledescription":b,"aria-describedby":u.draggable}),[i,g,y,v,b,u.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:j,isDragging:v,listeners:i?void 0:R,node:M,over:m,setNodeRef:w,setActivatorNodeRef:T,transform:x}}function nVe(){return E.useContext(OJ)}const iVe="Droppable",rVe={timeout:25};function aVe(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=pv(iVe),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=E.useContext(hM),u=E.useRef({disabled:n}),f=E.useRef(!1),m=E.useRef(null),g=E.useRef(null),{disabled:b,updateMeasurementsFor:y,timeout:v}={...rVe,...r},x=w0(y??i),M=E.useCallback(()=>{if(!f.current){f.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{c(Array.isArray(x.current)?x.current:[x.current]),g.current=null},v)},[v]),w=fM({callback:M,disabled:b||!s}),A=E.useCallback((j,C)=>{w&&(C&&(w.unobserve(C),f.current=!1),j&&w.observe(j))},[w]),[T,R]=IS(A),N=w0(e);return E.useEffect(()=>{!w||!T.current||(w.disconnect(),f.current=!1,w.observe(T.current))},[T,w]),E.useEffect(()=>(o({type:nr.RegisterDroppable,element:{id:i,key:a,disabled:n,node:T,rect:m,data:N}}),()=>o({type:nr.UnregisterDroppable,key:a,id:i})),[i]),E.useEffect(()=>{n!==u.current.disabled&&(o({type:nr.SetDroppableDisabled,id:i,key:a,disabled:n}),u.current.disabled=n)},[i,a,n,o]),{active:s,rect:m,isOver:l?.id===i,node:T,over:l,setNodeRef:R}}function rL(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function sVe(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function i_(t){return t!==null&&t>=0}function oVe(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=rL(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}},IJ="Sortable",jJ=ui.createContext({activeIndex:-1,containerId:IJ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:aL,disabled:{draggable:!1,droppable:!1}});function cVe(t){let{children:e,id:n,items:i,strategy:r=aL,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:u}=nVe(),f=pv(IJ,n),m=o.rect!==null,g=E.useMemo(()=>i.map(R=>typeof R=="object"&&"id"in R?R.id:R),[i]),b=s!=null,y=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,x=E.useRef(g),M=!oVe(g,x.current),w=v!==-1&&y===-1||M,A=lVe(a);al(()=>{M&&b&&u(g)},[M,g,b,u]),E.useEffect(()=>{x.current=g},[g]);const T=E.useMemo(()=>({activeIndex:y,containerId:f,disabled:A,disableTransforms:w,items:g,overIndex:v,useDragOverlay:m,sortedRects:sVe(g,l),strategy:r}),[y,f,A.draggable,A.droppable,w,g,v,l,m,r]);return ui.createElement(jJ.Provider,{value:T},e)}const uVe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return rL(n,i,r).indexOf(e)},dVe=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},fVe={duration:200,easing:"ease"},UJ="transform",hVe=E0.Transition.toString({property:UJ,duration:0,easing:"linear"}),pVe={roleDescription:"sortable"};function mVe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=E.useState(null),o=E.useRef(n);return al(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=jm(i.current,{ignoreTransform:!0}),u={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(u.x||u.y)&&s(u)}}n!==o.current&&(o.current=n)},[e,n,i,r]),E.useEffect(()=>{a&&s(null)},[a]),a}function gVe(t){let{animateLayoutChanges:e=dVe,attributes:n,disabled:i,data:r,getNewIndex:a=uVe,id:s,strategy:o,resizeObserverConfig:l,transition:c=fVe}=t;const{items:u,containerId:f,activeIndex:m,disabled:g,disableTransforms:b,sortedRects:y,overIndex:v,useDragOverlay:x,strategy:M}=E.useContext(jJ),w=xVe(i,g),A=u.indexOf(s),T=E.useMemo(()=>({sortable:{containerId:f,index:A,items:u},...r}),[f,r,A,u]),R=E.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:N,node:j,isOver:C,setNodeRef:k}=aVe({id:s,data:T,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:R,...l}}),{active:F,activatorEvent:I,activeNodeRect:W,attributes:O,setNodeRef:H,listeners:V,isDragging:$,over:K,setActivatorNodeRef:Y,transform:se}=tVe({id:s,data:T,attributes:{...pVe,...n},disabled:w.draggable}),B=I8e(k,H),X=!!F,ae=X&&!b&&i_(m)&&i_(v),ce=!x&&$,xe=ce&&ae?se:null,ve=ae?xe??(o??M)({rects:y,activeNodeRect:W,activeIndex:m,overIndex:v,index:A}):null,Pe=i_(m)&&i_(v)?a({id:s,items:u,activeIndex:m,overIndex:v}):A,pe=F?.id,we=E.useRef({activeId:pe,items:u,newIndex:Pe,containerId:f}),ze=u!==we.current.items,ue=e({active:F,containerId:f,isDragging:$,isSorting:X,id:s,index:A,items:u,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ht=mVe({disabled:!ue,index:A,node:j,rect:N});return E.useEffect(()=>{X&&we.current.newIndex!==Pe&&(we.current.newIndex=Pe),f!==we.current.containerId&&(we.current.containerId=f),u!==we.current.items&&(we.current.items=u)},[X,Pe,f,u]),E.useEffect(()=>{if(pe===we.current.activeId)return;if(pe!=null&&we.current.activeId==null){we.current.activeId=pe;return}const q=setTimeout(()=>{we.current.activeId=pe},50);return()=>clearTimeout(q)},[pe]),{active:F,activeIndex:m,attributes:O,data:T,rect:N,index:A,newIndex:Pe,items:u,isOver:C,isSorting:X,isDragging:$,listeners:V,node:j,overIndex:v,over:K,setNodeRef:B,setActivatorNodeRef:Y,setDroppableNodeRef:k,setDraggableNodeRef:H,transform:ht??ve,transition:z()};function z(){if(ht||ze&&we.current.newIndex===A)return hVe;if(!(ce&&!JO(I)||!c)&&(X||ue))return E0.Transition.toString({...c,property:UJ})}}function xVe(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 FS(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 vVe=[_n.Down,_n.Right,_n.Up,_n.Left],bVe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(vVe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const m=r.get(f.id);if(m)switch(t.code){case _n.Down:i.topm.top&&l.push(f);break;case _n.Left:i.left>m.left&&l.push(f);break;case _n.Right:i.left1&&(u=c[1].id),u!=null){const f=a.get(n.id),m=a.get(u),g=m?r.get(m.id):null,b=m?.node.current;if(b&&g&&f&&m){const v=dM(b).some((R,N)=>o[N]!==R),x=FJ(f,m),M=yVe(f,m),w=v||!x?{x:0,y:0}:{x:M?i.width-g.width:0,y:M?i.height-g.height:0},A={x:g.left,y:g.top};return w.x&&w.y?A:M0(A,w)}}}};function FJ(t,e){return!FS(t)||!FS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function yVe(t,e){return!FS(t)||!FS(e)||!FJ(t,e)?!1:t.data.current.sortable.index{const v={};return t.forEach(x=>{v[x.id]=x.defaultSize||4}),v},[r,a]=E.useState(()=>{const v=localStorage.getItem(e);if(v)try{const x=JSON.parse(v);return x.sizes||(x.sizes=i()),x}catch{}return{order:t.map(x=>x.id),hidden:t.filter(x=>x.defaultVisible===!1).map(x=>x.id),sizes:i()}}),[s,o]=E.useState(!1);E.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),E.useEffect(()=>{const x=t.map(M=>M.id).filter(M=>!r.order.includes(M));x.length>0&&a(M=>({...M,order:[...M.order,...x]}))},[t,r.order]);const l=Y8e(B$(iL,{activationConstraint:{distance:8}}),B$(tL,{coordinateGetter:bVe})),c=v=>{const{active:x,over:M}=v;M&&x.id!==M.id&&a(w=>{const A=w.order.indexOf(x.id),T=w.order.indexOf(M.id);return{...w,order:rL(w.order,A,T)}})},u=v=>{a(x=>({...x,hidden:x.hidden.includes(v)?x.hidden.filter(M=>M!==v):[...x.hidden,v]}))},f=v=>{a(x=>{const M=x.sizes[v]||4,w=M===1?2:M===2?4:1;return{...x,sizes:{...x.sizes,[v]:w}}})},m=()=>{const v={order:t.map(x=>x.id),hidden:t.filter(x=>x.defaultVisible===!1).map(x=>x.id),sizes:i()};a(v)},g=r.order.map(v=>t.find(x=>x.id===v)).filter(Boolean),b=g.filter(v=>!r.hidden.includes(v.id)),y=g.filter(v=>r.hidden.includes(v.id));return h.jsxs("div",{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-end gap-2",children:[y.length>0&&h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[h.jsx(F4,{className:"w-4 h-4"}),y.length," Hidden"]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:m,children:[h.jsx(XS,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&y.length>0&&h.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),h.jsx("div",{className:"flex flex-wrap gap-2",children:y.map(v=>h.jsxs("button",{onClick:()=>u(v.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:[h.jsx(F4,{className:"w-3 h-3"}),v.title]},v.id))})]}),h.jsx(Q6e,{sensors:l,collisionDetection:Q8e,onDragEnd:c,children:h.jsx(cVe,{items:b.map(v=>v.id),strategy:aL,children:h.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:b.map(v=>h.jsx(_Ve,{id:v.id,title:v.title,isHidden:r.hidden.includes(v.id),size:r.sizes[v.id]||2,onToggleVisibility:()=>u(v.id),onToggleSize:()=>f(v.id),children:v.component},v.id))})})}),b.length===0&&h.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[h.jsx("p",{children:"All widgets are hidden."}),h.jsx(lt,{className:"mt-4",onClick:m,children:"Reset Layout"})]})]})}function wVe({stats:t,currency:e}){return h.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:h.jsx(F_,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),h.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:h.jsx(xa,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:h.jsx(F_,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:h.jsx(U4,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:h.jsx(s9,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:h.jsx(U4,{className:"w-5 h-5"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),h.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function MVe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return h.jsxs("div",{className:"flex items-center gap-6",children:[h.jsxs("div",{className:"relative w-28 h-28",children:[h.jsxs("svg",{className:"w-full h-full -rotate-90",children:[h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),h.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:h.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(rd,{className:"w-4 h-4 text-bambu-green"}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),h.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(R0,{className:"w-4 h-4 text-red-400"}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),h.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function EVe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return h.jsx("div",{className:"flex items-center justify-center h-full",children:h.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 h.jsxs("div",{className:"flex items-center gap-6",children:[h.jsxs("div",{className:"relative w-28 h-28",children:[h.jsxs("svg",{className:"w-full h-full -rotate-90",children:[h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),h.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),h.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[h.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),h.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),h.jsxs("div",{className:"space-y-2 flex-1",children:[h.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[h.jsx(qoe,{className:"w-3 h-3"}),h.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&h.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>h.jsxs("div",{className:"flex items-center justify-between text-xs",children:[h.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),h.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 AVe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return h.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 h.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return h.jsxs("div",{children:[h.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[h.jsx("span",{className:"text-white",children:n}),h.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),h.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:h.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function TVe({printDates:t}){return h.jsx(C2e,{printDates:t,months:4})}function CVe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?h.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):h.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>h.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[h.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:h.jsx(hc,{className:"w-4 h-4 text-bambu-green"})}),h.jsxs("div",{children:[h.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),h.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function NVe({archives:t,currency:e}){return!t||t.length===0?h.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):h.jsx(L8e,{archives:t,currency:e})}function RVe(){const{data:t,isLoading:e}=Ht({queryKey:["archiveStats"],queryFn:He.getArchiveStats}),{data:n}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:i}=Ht({queryKey:["archives"],queryFn:()=>He.getArchives(void 0,1e3,0)}),{data:r}=Ht({queryKey:["settings"],queryFn:He.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 h.jsx("div",{className:"p-8",children:h.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:h.jsx(wVe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:h.jsx(MVe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:h.jsx(EVe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:h.jsx(AVe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:h.jsx(TVe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:h.jsx(CVe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:h.jsx(NVe,{archives:i||[],currency:a}),defaultSize:4}];return h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),h.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),h.jsx(SVe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function PVe({plug:t,onEdit:e}){const n=Gn(),[i,r]=E.useState(!1),[a,s]=E.useState(!1),[o,l]=E.useState(!1),[c,u]=E.useState(!1),{data:f,isLoading:m,refetch:g}=Ht({queryKey:["smart-plug-status",t.id],queryFn:()=>He.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:b}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),y=b?.find(R=>R.id===t.printer_id),v=yt({mutationFn:R=>He.controlSmartPlug(t.id,R),onSuccess:()=>{g()}}),x=yt({mutationFn:R=>He.updateSmartPlug(t.id,R),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=yt({mutationFn:()=>He.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",A=f?.reachable??!1,T=v.isPending;return h.jsxs(h.Fragment,{children:[h.jsx(Xt,{className:"relative",children:h.jsxs(en,{className:"p-4",children:[h.jsxs("div",{className:"flex items-start justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:`p-2 rounded-lg ${A?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:h.jsx(AN,{className:`w-5 h-5 ${A?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),h.jsxs("div",{children:[h.jsx("h3",{className:"font-medium text-white",children:t.name}),h.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),h.jsx("div",{className:"flex items-center gap-2",children:m?h.jsx(It,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?h.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[h.jsx(LP,{className:"w-4 h-4 text-bambu-green"}),h.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):h.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[h.jsx(Fp,{className:"w-4 h-4"}),h.jsx("span",{children:"Offline"})]})})]}),y&&h.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),h.jsx("span",{className:"text-sm text-white",children:y.name})]}),h.jsxs("div",{className:"flex gap-2 mb-3",children:[h.jsxs(lt,{size:"sm",variant:w?"primary":"secondary",disabled:!A||T,onClick:()=>s(!0),className:"flex-1",children:[T?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(qS,{className:"w-4 h-4"}),"On"]}),h.jsxs(lt,{size:"sm",variant:w?"secondary":"primary",disabled:!A||T,onClick:()=>l(!0),className:"flex-1",children:[T?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(n9,{className:"w-4 h-4"}),"Off"]})]}),h.jsxs("button",{onClick:()=>u(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[h.jsxs("span",{className:"flex items-center gap-2",children:[h.jsx(OP,{className:"w-4 h-4"}),"Automation Settings"]}),h.jsx("span",{children:c?"-":"+"})]}),c&&h.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Enabled"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.enabled,onChange:R=>x.mutate({enabled:R.target.checked}),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Auto On"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:R=>x.mutate({auto_on:R.target.checked}),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:R=>x.mutate({auto_off:R.target.checked}),className:"sr-only peer"}),h.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&&h.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),h.jsxs("div",{className:"flex gap-2",children:[h.jsxs("button",{onClick:()=>x.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:[h.jsx(xa,{className:"w-4 h-4"}),"Time"]}),h.jsxs("button",{onClick:()=>x.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:[h.jsx(o_,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),h.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:R=>x.mutate({off_delay_minutes:parseInt(R.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"})]}):h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),h.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:R=>x.mutate({off_temp_threshold:parseInt(R.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"}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),h.jsxs("div",{className:"flex gap-2 pt-2",children:[h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[h.jsx(t9,{className:"w-4 h-4"}),"Edit"]}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:h.jsx(ia,{className:"w-4 h-4"})})]})]})]})}),i&&h.jsx(rr,{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&&h.jsx(rr,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&h.jsx(rr,{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:()=>{v.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function kVe({plug:t,onClose:e}){const n=Gn(),i=!!t,[r,a]=E.useState(t?.name||""),[s,o]=E.useState(t?.ip_address||""),[l,c]=E.useState(t?.username||""),[u,f]=E.useState(t?.password||""),[m,g]=E.useState(t?.printer_id||null),[b,y]=E.useState(null),[v,x]=E.useState(null),{data:M}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:w}=Ht({queryKey:["smart-plugs"],queryFn:He.getSmartPlugs});E.useEffect(()=>{const k=F=>{F.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const A=yt({mutationFn:()=>He.testSmartPlugConnection(s,l||null,u||null),onSuccess:k=>{y(k),x(null),!r&&k.device_name&&a(k.device_name)},onError:k=>{y(null),x(k.message)}}),T=yt({mutationFn:k=>He.createSmartPlug(k),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:k=>{x(k.message)}}),R=yt({mutationFn:k=>He.updateSmartPlug(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:k=>{x(k.message)}}),N=M?.filter(k=>!w?.some(I=>I.printer_id===k.id&&I.id!==t?.id)),j=k=>{if(k.preventDefault(),x(null),!r.trim()){x("Name is required");return}if(!s.trim()){x("IP address is required");return}const F={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:u.trim()||null,printer_id:m};i?R.mutate(F):T.mutate(F)},C=T.isPending||R.isPending;return h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:k=>k.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:j,className:"p-6 space-y-4",children:[v&&h.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:v}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx("input",{type:"text",value:s,onChange:k=>{o(k.target.value),y(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"}),h.jsxs(lt,{type:"button",variant:"secondary",onClick:()=>A.mutate(),disabled:!s.trim()||A.isPending,children:[A.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(LP,{className:"w-4 h-4"}),"Test"]})]})]}),b&&h.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${b.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:b.success?h.jsxs(h.Fragment,{children:[h.jsx(rd,{className:"w-5 h-5"}),h.jsxs("div",{children:[h.jsx("p",{className:"font-medium",children:"Connected!"}),h.jsxs("p",{className:"text-sm opacity-80",children:[b.device_name&&`Device: ${b.device_name} - `,"State: ",b.state]})]})]}):h.jsxs(h.Fragment,{children:[h.jsx(Fp,{className:"w-5 h-5"}),h.jsx("span",{children:"Connection failed"})]})}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),h.jsx("input",{type:"text",value:r,onChange:k=>a(k.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"})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),h.jsx("input",{type:"text",value:l,onChange:k=>c(k.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),h.jsx("input",{type:"password",value:u,onChange:k=>f(k.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"})]})]}),h.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),h.jsxs("select",{value:m??"",onChange:k=>g(k.target.value?Number(k.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:[h.jsx("option",{value:"",children:"No printer (manual control only)"}),N?.map(k=>h.jsx("option",{value:k.id,children:k.name},k.id))]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),h.jsxs("div",{className:"flex gap-3 pt-2",children:[h.jsx(lt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:C,className:"flex-1",children:[C?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(P0,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function is({checked:t,onChange:e,disabled:n}){const i=r=>{r.preventDefault(),r.stopPropagation(),n||e(!t)};return h.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:i,className:`relative inline-flex w-9 h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:h.jsx("span",{className:`pointer-events-none absolute top-[2px] left-[2px] w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const DVe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email"};function OVe({provider:t,onEdit:e}){const n=Gn(),[i,r]=E.useState(!1),[a,s]=E.useState(!1),[o,l]=E.useState(null),{data:c}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),u=c?.find(y=>y.id===t.printer_id),f=yt({mutationFn:y=>He.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=yt({mutationFn:()=>He.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=yt({mutationFn:()=>He.testNotificationProvider(t.id),onSuccess:y=>{l(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{l({success:!1,message:y.message})}}),b=y=>y||"";return h.jsxs(h.Fragment,{children:[h.jsx(Xt,{className:"relative",children:h.jsxs(en,{className:"p-4",children:[h.jsxs("div",{className:"flex items-start justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:h.jsx(wN,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),h.jsxs("div",{children:[h.jsx("h3",{className:"font-medium text-white",children:t.name}),h.jsx("p",{className:"text-sm text-bambu-gray",children:DVe[t.provider_type]||t.provider_type})]})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[t.last_success&&h.jsxs("span",{className:"text-xs text-bambu-green",children:["Last sent: ",new Date(t.last_success).toLocaleDateString()]}),t.last_error&&h.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"})]})]}),u&&h.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),h.jsx("span",{className:"text-sm text-white",children:u.name})]}),!u&&!t.printer_id&&h.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:h.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),h.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&h.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&h.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&h.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&h.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&h.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&h.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&h.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Error"}),t.on_filament_low&&h.jsx("span",{className:"px-2 py-0.5 bg-amber-500/20 text-amber-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&h.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.quiet_hours_enabled&&h.jsxs("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded flex items-center gap-1",children:[h.jsx(U_,{className:"w-3 h-3"}),"Quiet"]})]}),h.jsx("div",{className:"mb-3",children:h.jsxs(lt,{size:"sm",variant:"secondary",disabled:g.isPending,onClick:()=>{l(null),g.mutate()},className:"w-full",children:[g.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(i9,{className:"w-4 h-4"}),"Send Test Notification"]})}),o&&h.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${o.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[o.success?h.jsx(rd,{className:"w-4 h-4"}):h.jsx(R0,{className:"w-4 h-4"}),h.jsx("span",{children:o.message})]}),h.jsxs("button",{onClick:()=>s(!a),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[h.jsxs("span",{className:"flex items-center gap-2",children:[h.jsx(OP,{className:"w-4 h-4"}),"Event Settings"]}),a?h.jsx(NP,{className:"w-4 h-4"}):h.jsx(gm,{className:"w-4 h-4"})]}),a&&h.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Enabled"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),h.jsx(is,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Started"}),h.jsx(is,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),h.jsx(is,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),h.jsx(is,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),h.jsx(is,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),h.jsx(is,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),h.jsx(is,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),h.jsx(is,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),h.jsx(is,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),h.jsx(is,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(U_,{className:"w-4 h-4 text-purple-400"}),h.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),h.jsx(is,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&h.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[h.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(xa,{className:"w-4 h-4 text-bambu-gray"}),h.jsxs("span",{className:"text-sm text-white",children:[b(t.quiet_hours_start)||"22:00"," - ",b(t.quiet_hours_end)||"07:00"]})]}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),h.jsxs("div",{className:"flex gap-2 pt-2",children:[h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[h.jsx(t9,{className:"w-4 h-4"}),"Edit"]}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:h.jsx(ia,{className:"w-4 h-4"})})]})]})]})}),i&&h.jsx(rr,{title:"Delete Notification Provider",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)})]})}const eG=[{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"email",label:"Email",description:"SMTP email notifications"}];function LVe({provider:t,onClose:e}){const n=Gn(),i=!!t,[r,a]=E.useState(t?.name||""),[s,o]=E.useState(t?.provider_type||"ntfy"),[l,c]=E.useState(t?.printer_id||null),[u,f]=E.useState(t?.quiet_hours_enabled||!1),[m,g]=E.useState(t?.quiet_hours_start||"22:00"),[b,y]=E.useState(t?.quiet_hours_end||"07:00"),[v,x]=E.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([H,V])=>[H,String(V)])):{}),[M,w]=E.useState(null),[A,T]=E.useState(null),{data:R}=Ht({queryKey:["printers"],queryFn:He.getPrinters});E.useEffect(()=>{const H=V=>{V.key==="Escape"&&e()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[e]);const N=yt({mutationFn:()=>He.testNotificationConfig({provider_type:s,config:v}),onSuccess:H=>{w(H),T(null)},onError:H=>{w({success:!1,message:H.message})}}),j=yt({mutationFn:H=>He.createNotificationProvider(H),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:H=>{T(H.message)}}),C=yt({mutationFn:H=>He.updateNotificationProvider(t.id,H),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:H=>{T(H.message)}}),k=H=>{if(H.preventDefault(),T(null),!r.trim()){T("Name is required");return}const V=W(s);for(const K of V)if(!v[K.key]?.trim()){T(`${K.label} is required`);return}const $={name:r.trim(),provider_type:s,config:v,printer_id:l,quiet_hours_enabled:u,quiet_hours_start:u?m:null,quiet_hours_end:u?b:null};i?C.mutate($):j.mutate($)},F=j.isPending||C.isPending,I=H=>{switch(H){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambutrack",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];default:return[]}},W=H=>I(H).filter(V=>V.required),O=I(s);return h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8",onClick:H=>H.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Notification Provider":"Add Notification Provider"}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:k,className:"p-6 space-y-4",children:[A&&h.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:A}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),h.jsx("input",{type:"text",value:r,onChange:H=>a(H.target.value),placeholder:"My Notifications",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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),h.jsx("select",{value:s,onChange:H=>{o(H.target.value),x({}),w(null)},disabled:i,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 disabled:opacity-50",children:eG.map(H=>h.jsx("option",{value:H.value,children:H.label},H.value))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:eG.find(H=>H.value===s)?.description})]}),h.jsxs("div",{className:"space-y-3",children:[h.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),O.map(H=>h.jsxs("div",{children:[h.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[H.label," ",H.required&&"*"]}),H.type==="select"&&H.options?h.jsx("select",{value:v[H.key]||H.options[0]?.value||"",onChange:V=>{x({...v,[H.key]:V.target.value}),w(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:H.options.map(V=>h.jsx("option",{value:V.value,children:V.label},V.value))}):h.jsx("input",{type:H.type,value:v[H.key]||"",onChange:V=>{x({...v,[H.key]:V.target.value}),w(null)},placeholder:H.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"})]},H.key))]}),h.jsx("div",{className:"flex gap-2",children:h.jsxs(lt,{type:"button",variant:"secondary",onClick:()=>{w(null),N.mutate()},disabled:N.isPending||!v[W(s)[0]?.key],className:"flex-1",children:[N.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(i9,{className:"w-4 h-4"}),"Test Configuration"]})}),M&&h.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${M.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:M.success?h.jsxs(h.Fragment,{children:[h.jsx(rd,{className:"w-5 h-5"}),h.jsx("span",{children:M.message})]}):h.jsxs(h.Fragment,{children:[h.jsx(R0,{className:"w-5 h-5"}),h.jsx("span",{children:M.message})]})}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),h.jsxs("select",{value:l??"",onChange:H=>c(H.target.value?Number(H.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:[h.jsx("option",{value:"",children:"All printers"}),R?.map(H=>h.jsx("option",{value:H.id,children:H.name},H.id))]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),h.jsx(is,{checked:u,onChange:f})]}),u&&h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),h.jsx("input",{type:"time",value:m,onChange:H=>g(H.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),h.jsx("input",{type:"time",value:b,onChange:H=>y(H.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"})]})]})]}),h.jsxs("div",{className:"flex gap-3 pt-2",children:[h.jsx(lt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:F,className:"flex-1",children:[F?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(P0,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}async function IVe(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function jVe(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function UVe(){const t=Gn(),[e,n]=E.useState(!1),[i,r]=E.useState(""),[a,s]=E.useState("auto"),[o,l]=E.useState(!1),[c,u]=E.useState(!1),[f,m]=E.useState("all"),{data:g,isLoading:b}=Ht({queryKey:["spoolman-settings"],queryFn:IVe}),{data:y,isLoading:v,refetch:x}=Ht({queryKey:["spoolman-status"],queryFn:He.getSpoolmanStatus,refetchInterval:3e4}),{data:M}=Ht({queryKey:["printers"],queryFn:He.getPrinters});E.useEffect(()=>{g&&(n(g.spoolman_enabled==="true"),r(g.spoolman_url||""),s(g.spoolman_sync_mode||"auto"))},[g]),E.useEffect(()=>{if(g){const I=g.spoolman_enabled==="true"!==e||(g.spoolman_url||"")!==i||(g.spoolman_sync_mode||"auto")!==a;l(I)}},[g,e,i,a]);const w=yt({mutationFn:()=>jVe({spoolman_enabled:e?"true":"false",spoolman_url:i,spoolman_sync_mode:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),l(!1),u(!0),setTimeout(()=>u(!1),2e3)}}),A=yt({mutationFn:He.connectSpoolman,onSuccess:()=>{x()}}),T=yt({mutationFn:He.disconnectSpoolman,onSuccess:()=>{x()}}),R=yt({mutationFn:He.syncAllPrintersAms,onSuccess:I=>{I.success}}),N=yt({mutationFn:I=>He.syncPrinterAms(I),onSuccess:I=>{I.success}}),j=()=>{f==="all"?R.mutate():N.mutate(f)},C=R.isPending||N.isPending,k=f==="all"?R.data:N.data,F=f==="all"?R.isSuccess:N.isSuccess;return b?h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(j4,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),h.jsx(en,{children:h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(j4,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),o&&h.jsx(lt,{size:"sm",onClick:()=>w.mutate(),disabled:w.isPending,children:w.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):c?h.jsx(jp,{className:"w-4 h-4"}):"Save"})]})}),h.jsxs(en,{className:"space-y-4",children:[h.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Enable Spoolman"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:e,onChange:I=>n(I.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),h.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:i,onChange:I=>r(I.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),h.jsxs("select",{value:a,onChange:I=>s(I.target.value),disabled:!e,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 disabled:opacity-50",children:[h.jsx("option",{value:"auto",children:"Automatic"}),h.jsx("option",{value:"manual",children:"Manual Only"})]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&h.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center justify-between mb-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),v?h.jsx(It,{className:"w-4 h-4 text-bambu-gray animate-spin"}):y?.connected?h.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[h.jsx(jp,{className:"w-4 h-4"}),"Connected"]}):h.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[h.jsx(bn,{className:"w-4 h-4"}),"Disconnected"]})]}),h.jsx("div",{className:"flex gap-2",children:y?.connected?h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>T.mutate(),disabled:T.isPending,children:[T.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Wse,{className:"w-4 h-4"}),"Disconnect"]}):h.jsxs(lt,{size:"sm",onClick:()=>A.mutate(),disabled:A.isPending||!i,children:[A.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Xse,{className:"w-4 h-4"}),"Connect"]})})]}),A.isError&&h.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:A.error.message}),y?.connected&&h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("div",{className:"relative flex-1",children:[h.jsxs("select",{value:f,onChange:I=>m(I.target.value==="all"?"all":Number(I.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[h.jsx("option",{value:"all",children:"All Printers"}),M?.map(I=>h.jsx("option",{value:I.id,children:I.name},I.id))]}),h.jsx(gm,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:j,disabled:C,children:[C?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Zo,{className:"w-4 h-4"}),"Sync"]})]})]}),F&&k&&h.jsx("div",{className:`mt-2 p-2 rounded text-sm ${k.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:k.success?`Synced ${k.synced_count} trays successfully`:`Synced ${k.synced_count} trays with ${k.errors.length} errors`})]})]})]})}function FVe(){const t=Gn(),{t:e,i18n:n}=bP(),[i,r]=E.useState(null),[a,s]=E.useState(!1),[o,l]=E.useState(!1),[c,u]=E.useState(!1),[f,m]=E.useState(null),[g,b]=E.useState(!1),[y,v]=E.useState(null),[x,M]=E.useState(l9()),w=X=>{M(X),kle(X)},A=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:T,isLoading:R}=Ht({queryKey:["settings"],queryFn:He.getSettings}),{data:N,isLoading:j}=Ht({queryKey:["smart-plugs"],queryFn:He.getSmartPlugs}),{data:C,isLoading:k}=Ht({queryKey:["notification-providers"],queryFn:He.getNotificationProviders}),{data:F}=Ht({queryKey:["ffmpeg-status"],queryFn:He.checkFfmpeg}),{data:I}=Ht({queryKey:["version"],queryFn:He.getVersion}),{data:W,refetch:O,isRefetching:H}=Ht({queryKey:["updateCheck"],queryFn:He.checkForUpdates,staleTime:300*1e3}),{data:V,refetch:$}=Ht({queryKey:["updateStatus"],queryFn:He.getUpdateStatus,refetchInterval:X=>{const ae=X.state.data;return ae?.status==="downloading"||ae?.status==="installing"?1e3:!1}}),K=yt({mutationFn:He.applyUpdate,onSuccess:()=>{$()}});E.useEffect(()=>{T&&!i&&r(T)},[T,i]),E.useEffect(()=>{if(T&&i){const X=T.auto_archive!==i.auto_archive||T.save_thumbnails!==i.save_thumbnails||T.capture_finish_photo!==i.capture_finish_photo||T.default_filament_cost!==i.default_filament_cost||T.currency!==i.currency||T.energy_cost_per_kwh!==i.energy_cost_per_kwh||T.energy_tracking_mode!==i.energy_tracking_mode||T.check_updates!==i.check_updates||T.notification_language!==i.notification_language;s(X)}},[T,i]);const Y=yt({mutationFn:He.updateSettings,onSuccess:X=>{t.setQueryData(["settings"],X),r(X),s(!1),l(!0),setTimeout(()=>l(!1),2e3),t.invalidateQueries({queryKey:["archiveStats"]})}}),se=()=>{i&&Y.mutate(i)},B=(X,ae)=>{i&&r({...i,[X]:ae})};return R||!i?h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),h.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),h.jsxs(lt,{onClick:se,disabled:!a||Y.isPending,children:[Y.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):o?h.jsx(jp,{className:"w-4 h-4"}):h.jsx(P0,{className:"w-4 h-4"}),o?"Saved!":"Save"]})]}),Y.isError&&h.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: ",Y.error.message]}),h.jsxs("div",{className:"flex gap-8",children:[h.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Auto-archive prints"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.auto_archive,onChange:X=>B("auto_archive",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Save thumbnails"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.save_thumbnails,onChange:X=>B("save_thumbnails",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Capture finish photo"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.capture_finish_photo,onChange:X=>B("capture_finish_photo",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),i.capture_finish_photo&&F&&!F.installed&&h.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),h.jsxs("div",{className:"text-sm",children:[h.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),h.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",h.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",h.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),h.jsx("input",{type:"number",step:"0.01",min:"0",value:i.default_filament_cost,onChange:X=>B("default_filament_cost",parseFloat(X.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),h.jsxs("select",{value:i.currency,onChange:X=>B("currency",X.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:[h.jsx("option",{value:"USD",children:"USD ($)"}),h.jsx("option",{value:"EUR",children:"EUR (€)"}),h.jsx("option",{value:"GBP",children:"GBP (£)"}),h.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),h.jsx("option",{value:"JPY",children:"JPY (¥)"}),h.jsx("option",{value:"CNY",children:"CNY (¥)"}),h.jsx("option",{value:"CAD",children:"CAD ($)"}),h.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),h.jsx("input",{type:"number",step:"0.01",min:"0",value:i.energy_cost_per_kwh,onChange:X=>B("energy_cost_per_kwh",parseFloat(X.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"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),h.jsxs("select",{value:i.energy_tracking_mode||"total",onChange:X=>B("energy_tracking_mode",X.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:[h.jsx("option",{value:"print",children:"Prints Only"}),h.jsx("option",{value:"total",children:"Total Consumption"})]}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:e("settings.general")})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{children:[h.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[h.jsx(j_,{className:"w-4 h-4 inline mr-1"}),e("settings.language")]}),h.jsx("select",{value:n.language,onChange:X=>n.changeLanguage(X.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:x4.map(X=>h.jsxs("option",{value:X.code,children:[X.nativeName," (",X.name,")"]},X.code))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.languageDescription")})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("settings.defaultView")}),h.jsx("select",{value:x,onChange:X=>w(X.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:l_.map(X=>h.jsx("option",{value:X.to,children:e(X.labelKey)},X.id))}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.defaultViewDescription")})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Sidebar order"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:A,children:[h.jsx(XS,{className:"w-4 h-4"}),"Reset"]})]})]})]})]}),h.jsxs("div",{className:"space-y-6 flex-1 max-w-md",children:[h.jsx(UVe,{}),h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),h.jsxs(en,{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Check for updates"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),h.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:i.check_updates,onChange:X=>B("check_updates",X.target.checked),className:"sr-only peer"}),h.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"})]})]}),h.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[h.jsxs("div",{className:"flex items-center justify-between mb-2",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:"Current version"}),h.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",I?.version||"..."]})]}),h.jsxs(lt,{variant:"secondary",size:"sm",onClick:()=>O(),disabled:H,children:[H?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Zo,{className:"w-4 h-4"}),"Check now"]})]}),W?.update_available?h.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[h.jsxs("div",{className:"flex items-start justify-between",children:[h.jsxs("div",{children:[h.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",W.latest_version]}),W.release_name&&W.release_name!==W.latest_version&&h.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:W.release_name}),W.release_notes&&h.jsx("p",{className:"text-sm text-bambu-gray mt-2 whitespace-pre-line line-clamp-3",children:W.release_notes})]}),W.release_url&&h.jsx("a",{href:W.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:h.jsx(fc,{className:"w-4 h-4"})})]}),V?.status==="downloading"||V?.status==="installing"?h.jsxs("div",{className:"mt-3",children:[h.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[h.jsx(It,{className:"w-4 h-4 animate-spin"}),h.jsx("span",{children:V.message})]}),h.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:h.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${V.progress}%`}})})]}):V?.status==="complete"?h.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:V.message}):V?.status==="error"?h.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:V.error||V.message}):h.jsxs(lt,{className:"mt-3",onClick:()=>K.mutate(),disabled:K.isPending,children:[K.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Gu,{className:"w-4 h-4"}),"Install Update"]})]}):W?.error?h.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",W.error]}):W&&!W.update_available?h.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]})]}),h.jsx("div",{className:"w-80 flex-shrink-0",children:h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(AN,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),h.jsxs(lt,{size:"sm",onClick:()=>{m(null),u(!0)},children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add"]})]})}),h.jsxs(en,{children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),j?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})}):N&&N.length>0?h.jsx("div",{className:"space-y-4",children:N.map(X=>h.jsx(PVe,{plug:X,onEdit:ae=>{m(ae),u(!0)}},X.id))}):h.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[h.jsx(AN,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),h.jsx("p",{children:"No smart plugs configured"}),h.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})}),h.jsx("div",{className:"w-80 flex-shrink-0",children:h.jsxs(Xt,{children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(wN,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notifications"})]}),h.jsxs(lt,{size:"sm",onClick:()=>{v(null),b(!0)},children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add"]})]})}),h.jsxs(en,{children:[h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Get notified about print events via WhatsApp, Telegram, Email, and more."}),h.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary mb-4",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-white",children:e("settings.notificationLanguage")}),h.jsx("p",{className:"text-sm text-bambu-gray",children:e("settings.notificationLanguageDescription")})]}),h.jsx("select",{value:i.notification_language||"en",onChange:X=>B("notification_language",X.target.value),className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green",children:x4.map(X=>h.jsx("option",{value:X.code,children:X.nativeName},X.code))})]}),k?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-6 h-6 text-bambu-green animate-spin"})}):C&&C.length>0?h.jsx("div",{className:"space-y-4",children:C.map(X=>h.jsx(OVe,{provider:X,onEdit:ae=>{v(ae),b(!0)}},X.id))}):h.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[h.jsx(wN,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),h.jsx("p",{children:"No notification providers configured"}),h.jsx("p",{className:"text-sm mt-1",children:"Add a provider to get started"})]})]})]})})]}),c&&h.jsx(kVe,{plug:f,onClose:()=>{u(!1),m(null)}}),g&&h.jsx(LVe,{provider:y,onClose:()=>{b(!1),v(null)}})]})}const zJ=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},zVe=t=>t.startsWith("HH")?"HF":"S",BVe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},BJ=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const i of e)if(t.startsWith(i))return t.slice(i.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function lN({profile:t,onEdit:e}){const n=zVe(t.nozzle_id),i=t.nozzle_diameter,r=t.name||"Unnamed",a=BJ(t.name||"");return h.jsxs("button",{onClick:e,className:"w-full text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:zJ(t.k_value)}),h.jsx("span",{className:"text-white text-sm truncate flex-1",title:r,children:r}),h.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[n," ",i]})]}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 truncate",title:`Filament: ${a}`,children:["Filament: ",a||t.filament_id]})]})}function tG({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:i=[],isDualNozzle:r=!1,onClose:a,onSave:s}){const{showToast:o}=Mo(),l=Gn(),[c,u]=E.useState(t?.name||""),[f,m]=E.useState(t?.k_value?zJ(t.k_value):"0.020"),[g,b]=E.useState(t?.filament_id||""),[y,v]=E.useState(t?.nozzle_id?BVe(t.nozzle_id):"HH00"),[x,M]=E.useState(t?.nozzle_diameter||n),[w,A]=E.useState(t?[t.extruder_id]:r?[0,1]:[0]),[T,R]=E.useState(!1),[N,j]=E.useState({current:0,total:0}),C=ui.useMemo(()=>{const V=new Map;for(const $ of i)if($.filament_id&&!V.has($.filament_id)){const K=BJ($.name||"");V.set($.filament_id,{id:$.filament_id,name:K||$.filament_id})}return Array.from(V.values()).sort(($,K)=>$.name.localeCompare(K.name))},[i]),k=yt({mutationFn:V=>(console.log("[KProfile] Calling API..."),He.setKProfile(e,V)),onSuccess:V=>{console.log("[KProfile] Save success:",V),o("K-profile saved"),R(!0),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),s()},2500)},onError:V=>{console.error("[KProfile] Save error:",V),o(V.message,"error"),R(!1)}}),F=yt({mutationFn:V=>(console.log("[KProfile] Deleting profile..."),He.deleteKProfile(e,V)),onSuccess:V=>{console.log("[KProfile] Delete success:",V),o("K-profile deleted"),R(!0),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),a()},2500)},onError:V=>{console.error("[KProfile] Delete error:",V),o(V.message,"error"),R(!1)}}),[I,W]=E.useState(!1),O=()=>{t&&F.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async V=>{if(V.preventDefault(),r&&!t&&w.length===0){o("Please select at least one extruder","error");return}const $=parseFloat(f).toFixed(6),K=`${y}-${x}`;if(t||w.length===1){const Y={name:c,k_value:$,filament_id:g,nozzle_id:K,nozzle_diameter:x,extruder_id:t?t.extruder_id:w[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",Y),k.mutate(Y);return}R(!0),j({current:0,total:w.length});for(let Y=0;YsetTimeout(X,1500))}catch(X){console.error(`[KProfile] Failed to save for extruder ${se}:`,X),o(`Failed to save for ${se===1?"Left":"Right"} extruder`,"error"),R(!1),j({current:0,total:0});return}}o(`K-profile saved to ${w.length} extruders`),setTimeout(()=>{l.invalidateQueries({queryKey:["kprofiles",e]}),R(!1),j({current:0,total:0}),s()},2500)};return h.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[h.jsxs(Xt,{className:"w-full max-w-md relative",children:[T&&h.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),h.jsx("p",{className:"text-white font-medium",children:N.total>1?`Saving to extruder ${N.current}/${N.total}...`:"Syncing with printer..."}),h.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),h.jsxs(en,{className:"p-0",children:[h.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[h.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),h.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors",disabled:T,children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),h.jsx("input",{type:"text",value:c,onChange:V=>u(V.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!t})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),h.jsx("input",{type:"text",inputMode:"decimal",value:f,onChange:V=>{const $=V.target.value;($===""||/^\d*\.?\d*$/.test($))&&m($)},onBlur:V=>{const $=parseFloat(V.target.value);isNaN($)||m((Math.trunc($*1e3)/1e3).toFixed(3))},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 font-mono",placeholder:"0.020",required:!0}),h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),h.jsxs("select",{value:g,onChange:V=>{const $=V.target.value;if(b($),!t&&$&&!c){const K=C.find(Y=>Y.id===$);K&&u(`${y==="HH00"?"HF":"S"} ${K.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[h.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&h.jsx("option",{value:t.filament_id,children:C.find(V=>V.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&C.map(V=>h.jsx("option",{value:V.id,children:V.name},V.id))]}),!t&&C.length===0&&h.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),h.jsxs("select",{value:y,onChange:V=>{const $=V.target.value;if(v($),!t&&g&&!c){const K=C.find(Y=>Y.id===g);K&&u(`${$==="HH00"?"HF":"S"} ${K.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[h.jsx("option",{value:"HH00",children:"High Flow"}),h.jsx("option",{value:"HS00",children:"Standard"})]})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),h.jsxs("select",{value:x,onChange:V=>M(V.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[h.jsx("option",{value:"0.2",children:"0.2mm"}),h.jsx("option",{value:"0.4",children:"0.4mm"}),h.jsx("option",{value:"0.6",children:"0.6mm"}),h.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),r&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?h.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?"Left":"Right"}):h.jsxs("div",{className:"flex gap-4",children:[h.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:w.includes(1),onChange:V=>{V.target.checked?A([...w,1]):A(w.filter($=>$!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),h.jsx("span",{className:"text-white",children:"Left"})]}),h.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[h.jsx("input",{type:"checkbox",checked:w.includes(0),onChange:V=>{V.target.checked?A([...w,0]):A(w.filter($=>$!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),h.jsx("span",{className:"text-white",children:"Right"})]})]})]}),h.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&h.jsx(lt,{type:"button",variant:"secondary",onClick:()=>W(!0),disabled:F.isPending||T,className:"text-red-500 hover:bg-red-500/10",children:F.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(ia,{className:"w-4 h-4"})}),h.jsx(lt,{type:"button",variant:"secondary",onClick:a,disabled:T,className:"flex-1",children:"Cancel"}),h.jsxs(lt,{type:"submit",disabled:k.isPending||T,className:"flex-1",children:[k.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(PP,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),I&&h.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:h.jsx(Xt,{className:"w-full max-w-sm",children:h.jsxs(en,{className:"p-6",children:[h.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[h.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:h.jsx(ia,{className:"w-5 h-5 text-red-500"})}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),h.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",h.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),h.jsxs("div",{className:"flex gap-3",children:[h.jsx(lt,{variant:"secondary",onClick:()=>W(!1),className:"flex-1",children:"Cancel"}),h.jsxs(lt,{onClick:()=>{W(!1),O()},disabled:F.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[F.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(ia,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function HVe(){const[t,e]=E.useState(null),[n,i]=E.useState("0.4"),[r,a]=E.useState(null),[s,o]=E.useState(!1),[l,c]=E.useState(""),[u,f]=E.useState("all"),[m,g]=E.useState("all"),{data:b,isLoading:y}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:v,isLoading:x,error:M,refetch:w}=Ht({queryKey:["kprofiles",t,n],queryFn:()=>He.getKProfiles(t,n),enabled:!!t,retry:!1,staleTime:0,refetchOnMount:"always"}),A=M?.message?.includes("not connected");E.useEffect(()=>{if(!t&&b&&b.length>0){const C=b.find(k=>k.is_active);C&&e(C.id)}},[t,b]),E.useEffect(()=>{if(t){const C=setTimeout(()=>{w()},150);return()=>clearTimeout(C)}},[t,n]);const T=b?.filter(C=>C.is_active)||[],R=ui.useMemo(()=>v?.profiles?v.profiles.filter(C=>{const k=l.toLowerCase(),F=!k||C.name.toLowerCase().includes(k)||C.filament_id.toLowerCase().includes(k),I=u==="all"||u==="left"&&C.extruder_id===1||u==="right"&&C.extruder_id===0,W=m==="all"||m==="hf"&&C.nozzle_id.startsWith("HH")||m==="s"&&C.nozzle_id.startsWith("HS");return F&&I&&W}):[],[v?.profiles,l,u,m]),j=b?.find(C=>C.id===t)?.nozzle_count===2;return y?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!b||b.length===0?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(id,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),h.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):T.length===0?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(hc,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),h.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[h.jsxs("div",{className:"flex-1 min-w-48",children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),h.jsx("select",{value:t||"",onChange:C=>e(parseInt(C.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:T.map(C=>h.jsx("option",{value:C.id,children:C.name},C.id))})]}),h.jsxs("div",{className:"w-32",children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),h.jsxs("select",{value:n,onChange:C=>i(C.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:[h.jsx("option",{value:"0.2",children:"0.2mm"}),h.jsx("option",{value:"0.4",children:"0.4mm"}),h.jsx("option",{value:"0.6",children:"0.6mm"}),h.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),h.jsxs("div",{className:"flex items-end gap-2",children:[h.jsxs(lt,{variant:"secondary",onClick:()=>w(),disabled:x,children:[h.jsx(Zo,{className:`w-4 h-4 ${x?"animate-spin":""}`}),"Refresh"]}),h.jsxs(lt,{onClick:()=>o(!0),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add Profile"]})]})]}),h.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[h.jsxs("div",{className:"flex-1 min-w-48 relative",children:[h.jsx(z_,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),h.jsx("input",{type:"text",value:l,onChange:C=>c(C.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),j&&h.jsx("div",{className:"w-36",children:h.jsxs("select",{value:u,onChange:C=>f(C.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:[h.jsx("option",{value:"all",children:"All Extruders"}),h.jsx("option",{value:"left",children:"Left Only"}),h.jsx("option",{value:"right",children:"Right Only"})]})}),h.jsx("div",{className:"w-32",children:h.jsxs("select",{value:m,onChange:C=>g(C.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:[h.jsx("option",{value:"all",children:"All Flow"}),h.jsx("option",{value:"hf",children:"HF Only"}),h.jsx("option",{value:"s",children:"S Only"})]})})]}),x?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):A?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(Fp,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),h.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),h.jsxs(lt,{variant:"secondary",onClick:()=>w(),children:[h.jsx(Zo,{className:"w-4 h-4"}),"Retry"]})]})}):R.length>0?j?h.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),h.jsx("div",{className:"space-y-1",children:R.filter(C=>C.extruder_id===1).map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))})]}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),h.jsx("div",{className:"space-y-1",children:R.filter(C=>C.extruder_id===0).map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))})]})]}):h.jsx("div",{className:"space-y-1",children:R.map(C=>h.jsx(lN,{profile:C,onEdit:()=>a(C)},C.slot_id))}):l||u!=="all"||m!=="all"?h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(z_,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),h.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):h.jsx(Xt,{children:h.jsxs(en,{className:"py-12 text-center",children:[h.jsx(PP,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),h.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),h.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",n,"mm nozzle"]}),h.jsxs(lt,{onClick:()=>o(!0),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Create First Profile"]})]})}),r&&t&&h.jsx(tG,{profile:r,printerId:t,nozzleDiameter:n,existingProfiles:v?.profiles,isDualNozzle:j,onClose:()=>a(null),onSave:()=>a(null)}),s&&t&&h.jsx(tG,{printerId:t,nozzleDiameter:n,existingProfiles:v?.profiles,isDualNozzle:j,onClose:()=>o(!1),onSave:()=>o(!1)})]})}function VVe({onSuccess:t}){const{showToast:e}=Mo(),[n,i]=E.useState("email"),[r,a]=E.useState(""),[s,o]=E.useState(""),[l,c]=E.useState(""),[u,f]=E.useState(""),[m,g]=E.useState("global"),b=yt({mutationFn:()=>He.cloudLogin(r,s,m),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")}}),y=yt({mutationFn:()=>He.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),v=yt({mutationFn:()=>He.cloudSetToken(u),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),x=w=>{w.preventDefault(),n==="email"?b.mutate():n==="code"?y.mutate():n==="token"&&v.mutate()},M=b.isPending||y.isPending||v.isPending;return h.jsxs(Xt,{className:"max-w-md mx-auto",children:[h.jsx(Gl,{children:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(RP,{className:"w-5 h-5 text-bambu-green"}),h.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),h.jsx(en,{children:h.jsxs("form",{onSubmit:x,className:"space-y-4",children:[n==="email"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),h.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})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),h.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})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),h.jsxs("select",{value:m,onChange:w=>g(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:[h.jsx("option",{value:"global",children:"Global"}),h.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),h.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),h.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"&&h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),h.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),h.jsx("textarea",{value:u,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})]}),h.jsxs("div",{className:"flex gap-2",children:[n==="code"&&h.jsx(lt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),h.jsxs(lt,{type:"submit",disabled:M,className:"flex-1",children:[M?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(H4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&h.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:h.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[h.jsx(zse,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&h.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:h.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[h.jsx(H4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function $Ve({setting:t,onClick:e}){return h.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[h.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&h.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function GVe({setting:t,onClose:e}){const{data:n,isLoading:i}=Ht({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>He.getCloudSettingDetail(t.setting_id)});return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:h.jsx(Xt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:h.jsxs(en,{className:"p-0 flex flex-col h-full",children:[h.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{children:[h.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),h.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),h.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?h.jsx("div",{className:"flex justify-center py-8",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?h.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)}):h.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),h.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:h.jsx(lt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function WVe({settings:t}){const[e,n]=E.useState(new Set),[i,r]=E.useState(null),a=l=>[...l].sort((c,u)=>c.name.localeCompare(u.name)),s=l=>{n(c=>{const u=new Set(c);return u.has(l)?u.delete(l):u.add(l),u})},o=[{key:"filament",label:"Filament Presets",icon:WG,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:hc,items:a(t.printer)},{key:"process",label:"Process Presets",icon:OP,items:a(t.process)}];return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:u,items:f})=>h.jsxs(Xt,{children:[h.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(u,{className:"w-5 h-5 text-bambu-green"}),h.jsx("span",{className:"text-lg font-semibold text-white",children:c}),h.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?h.jsx(gm,{className:"w-5 h-5 text-bambu-gray"}):h.jsx(Bf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&h.jsx(en,{className:"pt-0",children:h.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(m=>h.jsx($Ve,{setting:m,onClick:()=>r(m)},m.setting_id))})}),e.has(l)&&f.length===0&&h.jsx(en,{className:"pt-0",children:h.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&h.jsx(GVe,{setting:i,onClose:()=>r(null)})]})}function qVe(){const t=Gn(),{showToast:e}=Mo(),[n,i]=E.useState("kprofiles"),{data:r,isLoading:a}=Ht({queryKey:["cloudStatus"],queryFn:He.getCloudStatus}),{data:s,isLoading:o,refetch:l}=Ht({queryKey:["cloudSettings"],queryFn:()=>He.getCloudSettings(),enabled:!!r?.is_authenticated,retry:!1,staleTime:1e3*60*5}),c=yt({mutationFn:He.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),u=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return a?h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),h.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),h.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[h.jsxs("button",{onClick:()=>i("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[h.jsx(RP,{className:"w-4 h-4"}),"Cloud Profiles"]}),h.jsxs("button",{onClick:()=>i("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[h.jsx(PP,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[h.jsx("p",{className:"text-bambu-gray",children:r?.is_authenticated?`Connected as ${r.email}`:"Connect to Bambu Cloud to access your slicer presets"}),r?.is_authenticated&&h.jsxs("div",{className:"flex gap-2",children:[h.jsxs(lt,{variant:"secondary",onClick:()=>l(),disabled:o,children:[h.jsx(Zo,{className:`w-4 h-4 ${o?"animate-spin":""}`}),"Refresh"]}),h.jsxs(lt,{variant:"secondary",onClick:()=>c.mutate(),disabled:c.isPending,children:[h.jsx(ioe,{className:"w-4 h-4"}),"Logout"]})]})]}),r?.is_authenticated?o?h.jsx("div",{className:"flex justify-center py-12",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s?h.jsx(WVe,{settings:s}):h.jsx(Xt,{children:h.jsxs(en,{className:"py-8 text-center",children:[h.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),h.jsx(lt,{className:"mt-4",onClick:()=>l(),children:"Retry"})]})}):h.jsx(VVe,{onSuccess:u})]}),n==="kprofiles"&&h.jsx(HVe,{})]})}const xP={Droplet:WG,Flame:XG,Ruler:Aoe,Sparkles:Uoe,Square:Up,Cable:kae,Wrench:zp};function N_(t){return t&&xP[t]||zp}function Dx(t){return t<1?`${Math.round(t*60)}m`:`${t.toFixed(1)}h`}function XVe(t){const e=Math.floor(t),n=Math.round((t-e)*60);return e===0?`${n} minutes`:n===0?`${e} hours`:`${e}h ${n}m`}function KVe({item:t,onPerform:e,onToggle:n}){const i=N_(t.maintenance_type_icon),r=Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100)),a=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-yellow-400":"text-bambu-green":"text-bambu-gray",s=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-yellow-500":"bg-bambu-green":"bg-bambu-gray/30",o=()=>t.enabled?t.is_due?`Overdue by ${Dx(Math.abs(t.hours_until_due))}`:t.is_warning?`Due in ${Dx(t.hours_until_due)}`:`${Dx(t.hours_until_due)} left`:"Disabled";return h.jsxs("div",{className:`flex items-center gap-4 p-3 rounded-lg ${t.is_due?"bg-red-500/10":t.is_warning?"bg-yellow-500/10":"bg-bambu-dark"}`,children:[h.jsxs("div",{className:"flex items-center gap-3 min-w-[180px]",children:[h.jsx(i,{className:`w-4 h-4 ${a()}`}),h.jsx("span",{className:`text-sm ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name})]}),h.jsx("div",{className:"flex-1 max-w-[200px]",children:h.jsx("div",{className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:h.jsx("div",{className:`h-full transition-all ${s()}`,style:{width:`${r}%`}})})}),h.jsxs("div",{className:`text-xs min-w-[120px] ${a()}`,children:[t.is_due&&h.jsx(va,{className:"w-3 h-3 inline mr-1"}),t.is_warning&&h.jsx(xa,{className:"w-3 h-3 inline mr-1"}),!t.is_due&&!t.is_warning&&t.enabled&&h.jsx(jp,{className:"w-3 h-3 inline mr-1"}),o()]}),h.jsx(is,{checked:t.enabled,onChange:l=>n(t.id,l)}),h.jsxs(lt,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled,className:"min-w-[70px]",children:[h.jsx(XS,{className:"w-3 h-3"}),"Done"]})]})}function YVe({overview:t,onPerform:e,onToggle:n,onSetHours:i}){const[r,a]=E.useState(!1),[s,o]=E.useState(!1),[l,c]=E.useState(t.total_print_hours.toFixed(1)),u=[...t.maintenance_items].sort((g,b)=>g.maintenance_type_id-b.maintenance_type_id),f=[...t.maintenance_items].filter(g=>g.enabled).sort((g,b)=>g.is_due&&!b.is_due?-1:!g.is_due&&b.is_due?1:g.is_warning&&!b.is_warning?-1:!g.is_warning&&b.is_warning?1:g.hours_until_due-b.hours_until_due)[0],m=()=>{const g=parseFloat(l);!isNaN(g)&&g>=0&&(i(t.printer_id,g),o(!1))};return h.jsxs(Xt,{children:[h.jsxs("div",{className:"p-4",children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:t.printer_name}),t.due_count>0&&h.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(va,{className:"w-3 h-3"}),t.due_count," overdue"]}),t.warning_count>0&&h.jsxs("span",{className:"px-2.5 py-1 bg-yellow-500/20 text-yellow-400 text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(xa,{className:"w-3 h-3"}),t.warning_count," due soon"]}),t.due_count===0&&t.warning_count===0&&h.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1",children:[h.jsx(jp,{className:"w-3 h-3"}),"All good"]})]}),h.jsx("button",{onClick:()=>a(!r),className:"flex items-center gap-1 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded transition-colors",children:r?h.jsxs(h.Fragment,{children:[h.jsx(NP,{className:"w-4 h-4"}),"Hide"]}):h.jsxs(h.Fragment,{children:[h.jsx(gm,{className:"w-4 h-4"}),"Details"]})})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-1 uppercase tracking-wide",children:"Total Print Time"}),s?h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{type:"number",value:l,onChange:g=>c(g.target.value),onKeyDown:g=>{g.key==="Enter"&&m(),g.key==="Escape"&&o(!1)},className:"w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-lg font-semibold",min:"0",step:"1",autoFocus:!0}),h.jsx("span",{className:"text-sm text-bambu-gray",children:"hours"}),h.jsxs("div",{className:"flex gap-1 ml-auto",children:[h.jsx(lt,{size:"sm",onClick:m,children:"Save"}),h.jsx(lt,{size:"sm",variant:"secondary",onClick:()=>o(!1),children:"✕"})]})]}):h.jsxs("button",{onClick:()=>{c(Math.round(t.total_print_hours).toString()),o(!0)},className:"flex items-center gap-2 group",title:"Click to edit total print hours",children:[h.jsx("span",{className:"text-xl font-semibold text-white group-hover:text-bambu-green transition-colors",children:XVe(t.total_print_hours)}),h.jsx(DP,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})]})]}),h.jsxs("div",{className:`p-3 rounded-lg ${f?.is_due?"bg-red-500/10":f?.is_warning?"bg-yellow-500/10":"bg-bambu-dark"}`,children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-1 uppercase tracking-wide",children:"Next Maintenance"}),f?h.jsxs("div",{children:[h.jsx("div",{className:`text-lg font-semibold ${f.is_due?"text-red-400":f.is_warning?"text-yellow-400":"text-white"}`,children:f.maintenance_type_name}),h.jsx("div",{className:`text-sm ${f.is_due?"text-red-400":f.is_warning?"text-yellow-400":"text-bambu-gray"}`,children:f.is_due?h.jsxs(h.Fragment,{children:["Overdue by ",Dx(Math.abs(f.hours_until_due))]}):h.jsxs(h.Fragment,{children:["Due in ",Dx(f.hours_until_due)]})})]}):h.jsx("div",{className:"text-white",children:"No tasks enabled"})]})]})]}),r&&h.jsx(en,{className:"pt-0 space-y-2 border-t border-bambu-dark-tertiary mt-4",children:h.jsx("div",{className:"pt-4",children:u.map(g=>h.jsx(KVe,{item:g,onPerform:e,onToggle:n},g.id))})})]})}function ZVe({overview:t,types:e,onUpdateInterval:n,onAddType:i,onDeleteType:r}){const[a,s]=E.useState(null),[o,l]=E.useState(""),[c,u]=E.useState(!1),[f,m]=E.useState(""),[g,b]=E.useState("100"),[y,v]=E.useState("Wrench"),x=(R,N)=>{const j=parseFloat(o);if(!isNaN(j)&&j>0){const C=Math.abs(j-N)<.01?null:j;n(R,C)}s(null)},M=R=>{R.preventDefault(),f.trim()&&parseFloat(g)>0&&(i({name:f.trim(),default_interval_hours:parseFloat(g),icon:y}),m(""),b("100"),u(!1))},w=t?.map(R=>({printerId:R.printer_id,printerName:R.printer_name,items:R.maintenance_items.sort((N,j)=>N.maintenance_type_id-j.maintenance_type_id)})).sort((R,N)=>R.printerName.localeCompare(N.printerName))||[],A=e.filter(R=>R.is_system),T=e.filter(R=>!R.is_system);return h.jsxs("div",{className:"space-y-8",children:[h.jsxs("div",{children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsx("h2",{className:"text-lg font-semibold text-white",children:"Maintenance Types"}),h.jsxs(lt,{size:"sm",variant:"secondary",onClick:()=>u(!c),children:[h.jsx(Yo,{className:"w-4 h-4"}),"Add Custom Type"]})]}),c&&h.jsx(Xt,{className:"mb-4",children:h.jsx("div",{className:"p-4",children:h.jsx("form",{onSubmit:M,children:h.jsxs("div",{className:"flex gap-3 items-end",children:[h.jsxs("div",{className:"flex-1",children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Name"}),h.jsx("input",{type:"text",value:f,onChange:R=>m(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",placeholder:"e.g., Replace HEPA Filter",autoFocus:!0})]}),h.jsxs("div",{className:"w-28",children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Interval (hours)"}),h.jsx("input",{type:"number",value:g,onChange:R=>b(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"1"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Icon"}),h.jsx("div",{className:"flex gap-1",children:Object.keys(xP).map(R=>{const N=xP[R];return h.jsx("button",{type:"button",onClick:()=>v(R),className:`p-2 rounded ${y===R?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:h.jsx(N,{className:"w-4 h-4"})},R)})})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(lt,{type:"submit",size:"sm",disabled:!f.trim(),children:"Add"}),h.jsx(lt,{type:"button",size:"sm",variant:"secondary",onClick:()=>u(!1),children:"Cancel"})]})]})})})}),h.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[A.map(R=>{const N=N_(R.icon);return h.jsx("div",{className:"bg-bambu-dark-secondary rounded-lg p-4 border border-bambu-dark-tertiary",children:h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"p-2 bg-bambu-dark rounded-lg",children:h.jsx(N,{className:"w-5 h-5 text-bambu-gray"})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm font-medium text-white truncate",children:R.name}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5",children:[R.default_interval_hours,"h interval"]})]})]})},R.id)}),T.map(R=>{const N=N_(R.icon);return h.jsx("div",{className:"bg-bambu-dark-secondary rounded-lg p-4 border border-bambu-green/30",children:h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"p-2 bg-bambu-green/20 rounded-lg",children:h.jsx(N,{className:"w-5 h-5 text-bambu-green"})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-sm font-medium text-white truncate",children:R.name}),h.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:"Custom"})]}),h.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5",children:[R.default_interval_hours,"h interval"]})]}),h.jsx("button",{onClick:()=>{confirm(`Delete "${R.name}"?`)&&r(R.id)},className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",children:h.jsx(ia,{className:"w-4 h-4"})})]})},R.id)})]})]}),w.length>0&&h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold text-white mb-2",children:"Interval Overrides"}),h.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Set custom intervals per printer."}),h.jsx("div",{className:"space-y-3",children:w.map(R=>h.jsx(Xt,{children:h.jsxs("div",{className:"p-4",children:[h.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:R.printerName}),h.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:R.items.map(N=>{const j=N_(N.maintenance_type_icon),k=e.find(I=>I.id===N.maintenance_type_id)?.default_interval_hours||N.interval_hours,F=a===N.id;return h.jsxs("div",{className:"flex items-center gap-2 p-2 bg-bambu-dark rounded-lg",children:[h.jsx(j,{className:"w-4 h-4 text-bambu-gray shrink-0"}),h.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:N.maintenance_type_name}),F?h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("input",{type:"number",value:o,onChange:I=>l(I.target.value),onKeyDown:I=>{I.key==="Enter"&&x(N.id,k),I.key==="Escape"&&s(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1",autoFocus:!0}),h.jsx(lt,{size:"sm",onClick:()=>x(N.id,k),children:"OK"})]}):h.jsxs("button",{onClick:()=>{s(N.id),l(N.interval_hours.toString())},className:"px-2 py-1 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green rounded text-xs font-medium text-white transition-colors",children:[N.interval_hours,"h",h.jsx(DP,{className:"w-3 h-3 inline ml-1.5 text-bambu-gray"})]})]},N.id)})})]})},R.printerId))})]}),w.length===0&&h.jsx(Xt,{children:h.jsxs(en,{className:"text-center py-12",children:[h.jsx(xa,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),h.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),h.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to configure maintenance intervals"})]})})]})}function QVe(){const t=Gn(),{showToast:e}=Mo(),[n,i]=E.useState("status"),{data:r,isLoading:a}=Ht({queryKey:["maintenanceOverview"],queryFn:He.getMaintenanceOverview}),{data:s}=Ht({queryKey:["maintenanceTypes"],queryFn:He.getMaintenanceTypes}),o=yt({mutationFn:({id:x,notes:M})=>He.performMaintenance(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Maintenance marked as done")},onError:x=>{e(x.message,"error")}}),l=yt({mutationFn:({id:x,data:M})=>He.updateMaintenanceItem(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:x=>{e(x.message,"error")}}),c=yt({mutationFn:He.createMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type added")},onError:x=>{e(x.message,"error")}}),u=yt({mutationFn:He.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type deleted")},onError:x=>{e(x.message,"error")}}),f=yt({mutationFn:({printerId:x,hours:M})=>He.setPrinterHours(x,M),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Print hours updated")},onError:x=>{e(x.message,"error")}}),m=x=>{o.mutate({id:x})},g=(x,M)=>{l.mutate({id:x,data:{enabled:M}})},b=(x,M)=>{f.mutate({printerId:x,hours:M})};if(a)return h.jsx("div",{className:"p-8 flex justify-center",children:h.jsx(It,{className:"w-8 h-8 text-bambu-green animate-spin"})});const y=r?.reduce((x,M)=>x+M.due_count,0)||0,v=r?.reduce((x,M)=>x+M.warning_count,0)||0;return h.jsxs("div",{className:"p-8",children:[h.jsxs("div",{className:"mb-6",children:[h.jsx("h1",{className:"text-2xl font-bold text-white",children:"Maintenance"}),h.jsx("p",{className:"text-bambu-gray text-sm",children:n==="status"?h.jsxs(h.Fragment,{children:[y>0&&h.jsxs("span",{className:"text-red-400",children:[y," tasks overdue"]}),y>0&&v>0&&" · ",v>0&&h.jsxs("span",{className:"text-yellow-400",children:[v," due soon"]}),y===0&&v===0&&"All maintenance up to date"]}):"Configure maintenance types and intervals"})]}),h.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[h.jsx("button",{onClick:()=>i("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Status"}),h.jsx("button",{onClick:()=>i("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Settings"})]}),n==="status"?h.jsx("div",{className:"space-y-4",children:r&&r.length>0?[...r].sort((x,M)=>x.printer_name.localeCompare(M.printer_name)).map(x=>h.jsx(YVe,{overview:x,onPerform:m,onToggle:g,onSetHours:b},x.printer_id)):h.jsx(Xt,{children:h.jsxs(en,{className:"text-center py-12",children:[h.jsx(zp,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),h.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),h.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to start tracking maintenance"})]})})}):h.jsx(ZVe,{overview:r,types:s||[],onUpdateInterval:(x,M)=>l.mutate({id:x,data:{custom_interval_hours:M}}),onAddType:x=>c.mutate(x),onDeleteType:x=>u.mutate(x)})]})}function JVe({printerId:t,isConnected:e}){const[n,i]=E.useState(!1),[r,a]=E.useState(!1),[s,o]=E.useState(null),l=E.useRef(null),c=He.getCameraStreamUrl(t,10),u=()=>{n?(i(!1),o(null)):(a(!0),o(null),i(!0))},f=()=>{a(!1),o(null)},m=()=>{a(!1),o("Failed to load camera stream")},g=()=>{l.current&&(document.fullscreenElement?document.exitFullscreen():l.current.requestFullscreen())},b=()=>{i(!1),setTimeout(()=>{a(!0),i(!0)},100)};return h.jsx("div",{className:"relative w-full h-full bg-black",children:n?h.jsxs(h.Fragment,{children:[r&&h.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:h.jsx(It,{className:"w-8 h-8 animate-spin text-bambu-green"})}),s?h.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-red-400",children:[h.jsx(jae,{className:"w-12 h-12 mb-2"}),h.jsx("span",{className:"text-sm",children:s}),h.jsx("button",{onClick:b,className:"mt-2 text-xs text-bambu-green hover:underline",children:"Retry"})]}):h.jsx("img",{ref:l,src:c,alt:"Camera stream",className:"w-full h-full object-contain",onLoad:f,onError:m}),h.jsxs("div",{className:"absolute top-2 right-2 flex gap-2",children:[h.jsx("button",{onClick:b,className:"p-2 rounded bg-black/50 hover:bg-black/70 text-white transition-colors",title:"Refresh stream",children:h.jsx(Zo,{className:"w-4 h-4"})}),h.jsx("button",{onClick:g,className:"p-2 rounded bg-black/50 hover:bg-black/70 text-white transition-colors",title:"Fullscreen",children:h.jsx(JG,{className:"w-4 h-4"})}),h.jsx("button",{onClick:u,className:"px-3 py-1.5 rounded bg-red-500/80 hover:bg-red-500 text-white text-sm transition-colors",children:"Stop"})]})]}):h.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-bambu-gray",children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 flex flex-col items-center",children:[h.jsx(I_,{className:"w-8 h-8 mb-2"}),h.jsx("span",{className:"text-sm mb-3",children:e?"Click Start to view camera":"Printer not connected"}),h.jsx("button",{onClick:u,disabled:!e,className:"px-4 py-1.5 rounded text-sm bg-bambu-green text-white hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed",children:"Start"})]})})})}function e$e(t){if(!t)return"N/A";const e=new Date;return new Date(e.getTime()+t*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function t$e({printerId:t,status:e}){const n=Gn(),[i,r]=E.useState(null),a=e?.connected??!1,s=e?.state==="RUNNING",o=e?.state==="PAUSE",l=e?.progress??0,c=yt({mutationFn:()=>He.pausePrint(t),onSuccess:()=>{n.invalidateQueries({queryKey:["printerStatuses"]})}}),u=yt({mutationFn:()=>He.resumePrint(t),onSuccess:()=>{n.invalidateQueries({queryKey:["printerStatuses"]})}}),f=yt({mutationFn:x=>He.stopPrint(t,x),onSuccess:x=>{Bx(x)?r({action:"stop",token:x.token,warning:x.warning}):n.invalidateQueries({queryKey:["printerStatuses"]})}}),m=()=>{s?c.mutate():o&&u.mutate()},g=()=>{f.mutate(void 0)},b=()=>{i&&(f.mutate(i.token),r(null))},y=c.isPending||u.isPending||f.isPending,v=a&&(s||o);return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"text-xs text-bambu-gray mb-3",children:"Printing Progress"}),h.jsxs("div",{className:"flex gap-4 items-center",children:[h.jsx("div",{className:"w-20 h-20 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg flex items-center justify-center flex-shrink-0 overflow-hidden",children:e?.subtask_name?h.jsx("img",{src:`/api/v1/archives/thumbnail/${encodeURIComponent(e.subtask_name)}`,alt:"",className:"w-full h-full object-contain",onError:x=>{x.target.style.display="none",x.target.parentElement.innerHTML='Bambu
Lab
'}}):h.jsxs("span",{className:"text-xs text-bambu-gray text-center",children:["Bambu",h.jsx("br",{}),"Lab"]})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"font-medium text-sm text-white truncate mb-0.5",children:e?.subtask_name||"N/A"}),h.jsx("div",{className:`text-sm mb-2 ${e?.state==="RUNNING"||e?.state==="PAUSE"?"text-bambu-green":"text-bambu-gray"}`,children:e?.state||"N/A"}),h.jsx("div",{className:"h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mb-2",children:h.jsx("div",{className:`h-full transition-all duration-300 ${e?.state==="PAUSE"?"bg-yellow-500":"bg-bambu-green"}`,style:{width:`${l}%`}})}),h.jsxs("div",{className:"text-xs text-bambu-gray mb-1",children:["Layer: ",e?.layer_num??"N/A"," / ",e?.total_layers??"N/A","    ",Math.round(l),"%"]}),h.jsxs("div",{className:"text-xs text-bambu-gray",children:["Estimated finish time: ",e$e(e?.remaining_time)]})]}),h.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[h.jsx("button",{onClick:m,disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:s?"Pause":"Resume",children:c.isPending||u.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(e9,{className:"w-4 h-4"})}),h.jsx("button",{onClick:g,disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Stop",children:f.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Up,{className:"w-4 h-4"})}),h.jsx("button",{disabled:!v||y,className:"w-8 h-8 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Skip Objects",children:h.jsx("img",{src:"/icons/skip-objects.svg",alt:"Skip Objects",className:"w-4 h-4 icon-theme"})})]})]}),(c.error||u.error||f.error)&&h.jsx("p",{className:"mt-2 text-xs text-red-500",children:(c.error||u.error||f.error)?.message}),i&&h.jsx(rr,{title:"Confirm Stop",message:i.warning,confirmText:"Stop Print",variant:"danger",onConfirm:b,onCancel:()=>r(null)})]})}function n$e({checked:t,onChange:e,disabled:n}){return h.jsx("button",{onClick:()=>!n&&e(!t),disabled:n,className:`w-11 h-6 rounded-full relative transition-all shadow-inner border ${t?"bg-bambu-green border-bambu-green":"bg-bambu-dark-tertiary border-bambu-dark-tertiary"} ${n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:h.jsx("div",{className:`w-5 h-5 rounded-full bg-white shadow-md absolute top-0.5 transition-transform ${t?"translate-x-5":"translate-x-0.5"}`})})}function cN({name:t,icon:e,speed:n,enabled:i,onToggle:r,onSpeedChange:a,disabled:s,showSpeedControl:o=!0}){const l=()=>{const u=Math.min(100,n+10);a(u)},c=()=>{const u=Math.max(0,n-10);a(u)};return h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-4 shadow-lg border border-bambu-dark-tertiary/50",children:[h.jsxs("div",{className:"flex items-center justify-between mb-4",children:[h.jsxs("div",{className:"flex items-center gap-2.5",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center",children:e}),h.jsx("span",{className:"text-white font-medium",children:t})]}),o&&h.jsx(n$e,{checked:i,onChange:r,disabled:s})]}),o?h.jsxs("div",{className:"flex items-center justify-between bg-bambu-dark-secondary rounded-lg p-2",children:[h.jsx("button",{onClick:c,disabled:s||!i,className:"w-9 h-9 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center text-white hover:bg-bambu-dark transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:h.jsx(loe,{className:"w-4 h-4"})}),h.jsx("div",{className:"flex-1 text-center",children:h.jsxs("span",{className:`text-xl font-semibold ${i?"text-white":"text-bambu-gray"}`,children:[n,"%"]})}),h.jsx("button",{onClick:l,disabled:s||!i,className:"w-9 h-9 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center text-white hover:bg-bambu-dark transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:h.jsx(Yo,{className:"w-4 h-4"})})]}):h.jsx("div",{className:"p-3 text-center",children:h.jsx("span",{className:"text-xl font-semibold text-bambu-green",children:i?"Auto":"Off"})})]})}function i$e({onConfirm:t,onCancel:e}){return h.jsx("div",{className:"absolute inset-0 bg-black/80 flex items-center justify-center z-10 rounded-2xl",children:h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-5 m-4 max-w-sm border border-bambu-dark-tertiary shadow-xl",children:[h.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[h.jsx("div",{className:"w-10 h-10 rounded-full bg-yellow-500/20 flex items-center justify-center flex-shrink-0",children:h.jsx(va,{className:"w-5 h-5 text-yellow-500"})}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-white font-semibold",children:"Print in Progress"}),h.jsx("p",{className:"text-sm text-bambu-gray",children:"The printer is currently controlling air conditioning."})]})]}),h.jsx("p",{className:"text-sm text-bambu-gray mb-5",children:"Changing these settings during a print may affect print quality. Are you sure you want to continue?"}),h.jsxs("div",{className:"flex gap-3",children:[h.jsx("button",{onClick:e,className:"flex-1 py-2.5 px-4 rounded-lg font-medium text-sm bg-bambu-dark-tertiary text-white hover:bg-bambu-dark transition-colors",children:"Cancel"}),h.jsx("button",{onClick:t,className:"flex-1 py-2.5 px-4 rounded-lg font-medium text-sm bg-yellow-600 text-white hover:bg-yellow-700 transition-colors",children:"Continue"})]})]})})}function r$e({printer:t,status:e,onClose:n}){const i=e?.connected??!1,r=e?.state==="RUNNING"||e?.state==="PRINTING",a=!i,s=(e?.airduct_mode??0)===1?"heating":"cooling",[o,l]=E.useState(s),[c,u]=E.useState(!1),[f,m]=E.useState(null),[g,b]=E.useState(!1),[y,v]=E.useState(0),[x,M]=E.useState(!1),[w,A]=E.useState(0),[T,R]=E.useState(!1),[N,j]=E.useState(0),C=yt({mutationFn:ee=>He.setAirductMode(t.id,ee)}),k=yt({mutationFn:ee=>He.setPartFan(t.id,ee)}),F=yt({mutationFn:ee=>He.setAuxFan(t.id,ee)}),I=yt({mutationFn:ee=>He.setChamberFan(t.id,ee)}),W=ee=>{r?(m(()=>ee),u(!0)):ee()},O=()=>{f&&(f(),m(null)),u(!1)},H=()=>{m(null),u(!1)},V=ee=>{ee!==o&&W(()=>{l(ee),C.mutate(ee)})},$=ee=>{W(()=>{b(ee),ee||(v(0),k.mutate(0))})},K=ee=>{W(()=>{v(ee),b(ee>0),k.mutate(ee)})},Y=ee=>{W(()=>{M(ee),ee||(A(0),F.mutate(0))})},se=ee=>{W(()=>{A(ee),M(ee>0),F.mutate(ee)})},B=ee=>{W(()=>{R(ee),ee||(j(0),I.mutate(0))})},X=ee=>{W(()=>{j(ee),R(ee>0),I.mutate(ee)})};E.useEffect(()=>{const ee=ve=>{ve.key==="Escape"&&(c?H():n())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[n,c]);const ae={cooling:"Suitable for PLA, PETG, TPU. Filters and cools the chamber air.",heating:"Suitable for ABS, ASA, PC, PA. Circulates and heats chamber air."},ce=()=>h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-theme"}),xe=()=>h.jsx("img",{src:"/icons/chamber.svg",alt:"",className:"w-5 h-5 icon-theme"});return h.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:n,children:h.jsxs("div",{className:"relative w-full max-w-lg bg-bambu-dark-secondary rounded-2xl shadow-2xl border border-bambu-dark-tertiary overflow-hidden",onClick:ee=>ee.stopPropagation(),children:[c&&h.jsx(i$e,{onConfirm:O,onCancel:H}),h.jsxs("div",{className:"flex items-center justify-between px-5 py-4 bg-bambu-dark border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-green"})}),h.jsx("span",{className:"text-base font-semibold text-white",children:"Air Condition"})]}),h.jsx("button",{onClick:n,className:"w-8 h-8 rounded-lg flex items-center justify-center text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("div",{className:"p-5 space-y-5",children:[r&&h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-yellow-500 flex-shrink-0"}),h.jsx("span",{className:"text-xs text-yellow-500",children:"Print in progress. Changes may affect print quality."})]}),h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-1.5 flex gap-1.5 shadow-inner",children:[h.jsxs("button",{onClick:()=>V("cooling"),disabled:a||C.isPending,className:`flex-1 py-3 px-4 rounded-lg flex items-center justify-center gap-2 font-medium transition-all disabled:opacity-50 ${o==="cooling"?"bg-bambu-green text-white shadow-lg":"text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:[h.jsx(vle,{className:"w-4 h-4"}),"Cooling"]}),h.jsxs("button",{onClick:()=>V("heating"),disabled:a||C.isPending,className:`flex-1 py-3 px-4 rounded-lg flex items-center justify-center gap-2 font-medium transition-all disabled:opacity-50 ${o==="heating"?"bg-bambu-green text-white shadow-lg":"text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:[h.jsx(XG,{className:"w-4 h-4"}),"Heating"]})]}),h.jsx("p",{className:"text-sm text-bambu-gray text-center px-2",children:ae[o]}),h.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),h.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[h.jsx(cN,{name:"Part",icon:h.jsx(ce,{}),speed:y,enabled:g,onToggle:$,onSpeedChange:K,disabled:a,showSpeedControl:!0}),h.jsx(cN,{name:"Aux",icon:h.jsx(ce,{}),speed:w,enabled:x,onToggle:Y,onSpeedChange:se,disabled:a,showSpeedControl:o==="cooling"}),h.jsx(cN,{name:"Exhaust",icon:h.jsx(ce,{}),speed:N,enabled:T,onToggle:B,onSpeedChange:X,disabled:a,showSpeedControl:o==="cooling"}),h.jsxs("div",{className:"bg-bambu-dark rounded-xl p-4 shadow-lg border border-bambu-dark-tertiary/50",children:[h.jsxs("div",{className:"flex items-center gap-2.5 mb-4",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-dark-tertiary flex items-center justify-center",children:h.jsx(xe,{})}),h.jsx("span",{className:"text-white font-medium",children:"Heat"})]}),h.jsx("div",{className:"p-3 text-center",children:h.jsx("span",{className:"text-xl font-semibold text-bambu-green",children:o==="heating"?"Auto":"Off"})})]})]})]})]})})}const a$e=[{mode:1,name:"Silent",description:"Quieter printing, slower speed",percentage:"50%"},{mode:2,name:"Standard",description:"Balanced speed and quality",percentage:"100%"},{mode:3,name:"Sport",description:"Faster printing, moderate noise",percentage:"124%"},{mode:4,name:"Ludicrous",description:"Maximum speed",percentage:"166%"}];function s$e({printer:t,status:e,onClose:n}){const i=e?.connected??!1,r=e?.state==="RUNNING"||e?.state==="PRINTING",a=!i||!r,s=e?.speed_level??2,[o,l]=E.useState(s),c=yt({mutationFn:f=>He.setPrintSpeed(t.id,f)}),u=f=>{f===o||a||(l(f),c.mutate(f))};return E.useEffect(()=>{const f=m=>{m.key==="Escape"&&n()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[n]),h.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:n,children:h.jsxs("div",{className:"relative w-full max-w-md bg-bambu-dark-secondary rounded-2xl shadow-2xl border border-bambu-dark-tertiary overflow-hidden",onClick:f=>f.stopPropagation(),children:[h.jsxs("div",{className:"flex items-center justify-between px-5 py-4 bg-bambu-dark border-b border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("div",{className:"w-8 h-8 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:h.jsx("img",{src:"/icons/speed.svg",alt:"",className:"w-5 h-5 icon-green"})}),h.jsx("span",{className:"text-base font-semibold text-white",children:"Print Speed"})]}),h.jsx("button",{onClick:n,className:"w-8 h-8 rounded-lg flex items-center justify-center text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white transition-colors",children:h.jsx(bn,{className:"w-5 h-5"})})]}),h.jsxs("div",{className:"p-5 space-y-4",children:[r?h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-yellow-500 flex-shrink-0"}),h.jsx("span",{className:"text-xs text-yellow-500",children:"Speed changes take effect immediately."})]}):h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg",children:[h.jsx(va,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),h.jsx("span",{className:"text-xs text-bambu-gray",children:"No print in progress. Speed can only be changed during printing."})]}),h.jsx("div",{className:"space-y-2",children:a$e.map(f=>h.jsxs("button",{onClick:()=>u(f.mode),disabled:a||c.isPending,className:`w-full p-4 rounded-xl flex items-center justify-between transition-all disabled:opacity-50 disabled:cursor-not-allowed ${o===f.mode?"bg-bambu-green text-white shadow-lg":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary"}`,children:[h.jsxs("div",{className:"flex flex-col items-start",children:[h.jsx("span",{className:"font-medium",children:f.name}),h.jsx("span",{className:`text-xs ${o===f.mode?"text-white/80":"text-bambu-gray"}`,children:f.description})]}),h.jsx("span",{className:`text-lg font-semibold ${o===f.mode?"text-white":"text-bambu-gray"}`,children:f.percentage})]},f.mode))})]})]})})}function o$e({printer:t,status:e,disabled:n=!1}){const i=e?.temperatures??{},r=t.nozzle_count>1,a=(e?.connected??!1)&&!n,[s,o]=E.useState(null),[l,c]=E.useState(""),[u,f]=E.useState(!1),[m,g]=E.useState(!1),b=yt({mutationFn:I=>He.setBedTemperature(t.id,I)}),y=yt({mutationFn:({target:I,nozzle:W})=>He.setNozzleTemperature(t.id,I,W)}),v=yt({mutationFn:I=>He.setChamberTemperature(t.id,I)}),x=yt({mutationFn:I=>He.setChamberLight(t.id,I)}),M=(I,W)=>{a&&(o(I),c(String(Math.round(W))))},w=()=>{o(null),c("")},A=()=>{const I=parseInt(l,10);if(isNaN(I)||I<0){w();return}s==="bed"?b.mutate(I):s==="nozzle"?y.mutate({target:I,nozzle:r?1:0}):s==="nozzle_2"?y.mutate({target:I,nozzle:0}):s==="chamber"&&v.mutate(I),w()},T=I=>{I.key==="Enter"?A():I.key==="Escape"&&w()},R=!a,N=i.nozzle_heating??!1,j=i.nozzle_2_heating??!1,C=i.bed_heating??!1,k=i.chamber_heating??!1,F=(I,W)=>s===I?h.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",value:l,onChange:O=>{const H=O.target.value.replace(/[^0-9]/g,"");c(H)},onBlur:A,onKeyDown:T,autoFocus:!0,className:"w-12 text-sm bg-bambu-dark border border-bambu-green rounded px-1 py-0.5 text-white text-center [appearance:textfield]"}):h.jsxs("button",{onClick:()=>M(I,W),disabled:R,className:"text-sm text-bambu-gray hover:text-bambu-green disabled:hover:text-bambu-gray disabled:cursor-not-allowed",title:R?"Printer not connected":"Click to set target temperature",children:["/",Math.round(W)," °C"]});return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col justify-evenly min-w-[150px] pr-5 border-r border-bambu-dark-tertiary",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/hotend.svg",alt:"",className:`w-5 ${N?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"text-[11px] font-semibold text-bambu-green bg-bambu-green/20 px-1.5 py-0.5 rounded min-w-[18px] text-center flex-shrink-0",children:"L"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.nozzle??0)}),F("nozzle",i.nozzle_target??0)]}),r&&h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/hotend.svg",alt:"",className:`w-5 ${j?"icon-heating":"icon-theme"}`})}),h.jsx("span",{className:"text-[11px] font-semibold text-bambu-green bg-bambu-green/20 px-1.5 py-0.5 rounded min-w-[18px] text-center flex-shrink-0",children:"R"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.nozzle_2??0)}),F("nozzle_2",i.nozzle_2_target??0)]}),h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/heatbed.svg",alt:"",className:`w-5 ${C?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"min-w-[18px] flex-shrink-0"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.bed??0)}),F("bed",i.bed_target??0)]}),h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:h.jsx("img",{src:"/icons/chamber.svg",alt:"",className:`w-5 ${k?"icon-heating":"icon-theme"}`})}),r&&h.jsx("span",{className:"min-w-[18px] flex-shrink-0"}),h.jsx("span",{className:"text-lg font-medium text-white",children:Math.round(i.chamber??0)}),F("chamber",i.chamber_target??0)]}),h.jsxs("button",{onClick:()=>f(!0),disabled:R,className:"flex items-center justify-between w-full px-3 py-4 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("img",{src:"/icons/ventilation.svg",alt:"",className:"w-5 h-5 icon-theme"}),h.jsx("span",{className:"text-xs text-bambu-gray",children:"A/C"})]}),h.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${e?.airduct_mode===1?"bg-orange-500/20 text-orange-400":"bg-blue-500/20 text-blue-400"}`,children:e?.airduct_mode===1?"Heat":"Cool"})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("button",{onClick:()=>g(!0),disabled:R,className:"flex-1 flex flex-col items-center py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsx("img",{src:"/icons/speed.svg",alt:"",className:"w-5 h-5 icon-theme"}),h.jsx("span",{className:"text-[10px] text-bambu-gray mt-0.5",children:e?.speed_level===1?"50%":e?.speed_level===3?"124%":e?.speed_level===4?"166%":"100%"})]}),h.jsxs("button",{onClick:()=>x.mutate(!(e?.chamber_light??!1)),disabled:R||x.isPending,className:"flex-1 flex flex-col items-center py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed",children:[h.jsx("img",{src:"/icons/lamp.svg",alt:"",className:`w-5 h-5 ${e?.chamber_light?"icon-green":"icon-theme"}`}),h.jsx("span",{className:"text-[10px] text-bambu-gray mt-0.5",children:"Lamp"})]})]})]}),u&&h.jsx(r$e,{printer:t,status:e,onClose:()=>f(!1)}),m&&h.jsx(s$e,{printer:t,status:e,onClose:()=>g(!1)})]})}function l$e({printerId:t,status:e,disabled:n=!1}){const i=(e?.connected??!1)&&!n,[r,a]=E.useState(null),s=yt({mutationFn:({axes:g,token:b})=>He.homeAxes(t,g,b),onSuccess:g=>{Bx(g)&&a({action:"home",token:g.token,warning:g.warning,onConfirm:()=>s.mutate({axes:"XY",token:g.token})})}}),o=yt({mutationFn:({axis:g,distance:b,token:y})=>He.moveAxis(t,g,b,3e3,y),onSuccess:(g,b)=>{Bx(g)&&a({action:"move",token:g.token,warning:g.warning,onConfirm:()=>o.mutate({axis:b.axis,distance:b.distance,token:g.token})})}}),l=()=>{s.mutate({axes:"XY"})},c=(g,b)=>{o.mutate({axis:g,distance:b})},u=()=>{r&&(r.onConfirm(),a(null))},f=s.isPending||o.isPending,m=!i||f;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"relative w-[220px] h-[220px] mb-3.5",children:[h.jsx("img",{src:"/icons/jogpad.svg",alt:"Jog Pad",className:"w-full h-full jogpad-theme"}),h.jsx("button",{onClick:()=>c("Y",10),disabled:m,className:"absolute top-[8px] left-1/2 -translate-x-1/2 w-[40px] h-[30px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y+10"}),h.jsx("button",{onClick:()=>c("Y",-10),disabled:m,className:"absolute bottom-[8px] left-1/2 -translate-x-1/2 w-[40px] h-[30px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y-10"}),h.jsx("button",{onClick:()=>c("X",-10),disabled:m,className:"absolute left-[8px] top-1/2 -translate-y-1/2 w-[30px] h-[40px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X-10"}),h.jsx("button",{onClick:()=>c("X",10),disabled:m,className:"absolute right-[8px] top-1/2 -translate-y-1/2 w-[30px] h-[40px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X+10"}),h.jsx("button",{onClick:()=>c("Y",1),disabled:m,className:"absolute top-[42px] left-1/2 -translate-x-1/2 w-[35px] h-[25px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y+1"}),h.jsx("button",{onClick:()=>c("Y",-1),disabled:m,className:"absolute bottom-[42px] left-1/2 -translate-x-1/2 w-[35px] h-[25px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Y-1"}),h.jsx("button",{onClick:()=>c("X",-1),disabled:m,className:"absolute left-[42px] top-1/2 -translate-y-1/2 w-[25px] h-[35px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X-1"}),h.jsx("button",{onClick:()=>c("X",1),disabled:m,className:"absolute right-[42px] top-1/2 -translate-y-1/2 w-[25px] h-[35px] opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"X+1"}),h.jsx("button",{onClick:l,disabled:m,className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[50px] h-[50px] rounded-full opacity-0 hover:opacity-10 hover:bg-white disabled:cursor-not-allowed",title:"Home XY"})]}),r&&h.jsx(rr,{title:"Confirm Action",message:r.warning,confirmText:"Continue",variant:"warning",onConfirm:u,onCancel:()=>a(null)})]})}function c$e({printerId:t,status:e,disabled:n=!1}){const i=(e?.connected??!1)&&!n,[r,a]=E.useState(null),s=yt({mutationFn:({distance:u,token:f})=>He.moveAxis(t,"Z",u,1e3,f),onSuccess:(u,f)=>{Bx(u)&&a({token:u.token,warning:u.warning,distance:f.distance})}}),o=u=>{s.mutate({distance:u})},l=()=>{r&&(s.mutate({distance:r.distance,token:r.token}),a(null))},c=!i||s.isPending;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("button",{onClick:()=>o(10),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z+10",children:"↑10"}),h.jsx("button",{onClick:()=>o(1),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z+1",children:"↑1"}),h.jsx("span",{className:"px-2 py-2 text-sm text-bambu-gray",children:"Bed"}),h.jsx("button",{onClick:()=>o(-1),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z-1",children:"↓1"}),h.jsx("button",{onClick:()=>o(-10),disabled:c,className:"px-3.5 py-2 rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Z-10",children:"↓10"})]}),r&&h.jsx(rr,{title:"Confirm Bed Movement",message:r.warning,confirmText:"Continue",variant:"warning",onConfirm:l,onCancel:()=>a(null)})]})}function u$e({printerId:t,status:e,nozzleCount:n,disabled:i=!1}){const r=(e?.connected??!1)&&!i,a=e?.state==="RUNNING"||e?.state==="PAUSE",s=n>1,[o,l]=E.useState("left"),[c,u]=E.useState(null),f=yt({mutationFn:({distance:y,token:v})=>{const M=`${s?`T${o==="left"?0:1} `:""}G91 G1 E${y} F300 G90`;return He.sendGcode(t,M,v)},onSuccess:(y,v)=>{Bx(y)&&u({token:y.token,warning:y.warning,distance:v.distance})}}),m=y=>{f.mutate({distance:y})},g=()=>{c&&(f.mutate({distance:c.distance,token:c.token}),u(null))},b=!r||a||f.isPending;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col items-center gap-1.5 justify-center",children:[s&&h.jsxs("div",{className:`flex rounded-md overflow-hidden border border-bambu-dark-tertiary mb-1 flex-shrink-0 ${b?"opacity-50":""}`,children:[h.jsx("button",{onClick:()=>l("left"),disabled:b,className:`px-3 py-1.5 text-sm border-r border-bambu-dark-tertiary transition-colors disabled:cursor-not-allowed ${o==="left"?"bg-bambu-green text-white":"bg-bambu-dark-secondary text-bambu-gray hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark-secondary"}`,children:"Left"}),h.jsx("button",{onClick:()=>l("right"),disabled:b,className:`px-3 py-1.5 text-sm transition-colors disabled:cursor-not-allowed ${o==="right"?"bg-bambu-green text-white":"bg-bambu-dark-secondary text-bambu-gray hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark-secondary"}`,children:"Right"})]}),h.jsx("button",{onClick:()=>m(5),disabled:b,className:"w-9 h-[30px] rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Extrude 5mm",children:h.jsx(NP,{className:"w-4 h-4"})}),h.jsx("div",{className:"h-[120px] flex items-center justify-center",children:h.jsx("img",{src:s?"/icons/dual-extruder.png":"/icons/single-extruder1.png",alt:s?"Dual Extruder":"Single Extruder",className:"h-full object-contain",onError:y=>{y.target.style.display="none"}})}),h.jsx("button",{onClick:()=>m(-5),disabled:b,className:"w-9 h-[30px] rounded-md bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary flex items-center justify-center text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",title:"Retract 5mm",children:h.jsx(gm,{className:"w-4 h-4"})}),h.jsx("span",{className:"text-xs text-bambu-gray mt-0.5",children:"Extruder"})]}),c&&h.jsx(rr,{title:"Confirm Extrusion",message:c.warning,confirmText:"Continue",variant:"warning",onConfirm:g,onCancel:()=>u(null)})]})}function nG(t){if(!t)return"rgb(128, 128, 128)";const e=t.replace("#","").substring(0,6),n=parseInt(e.substring(0,2),16)||128,i=parseInt(e.substring(2,4),16)||128,r=parseInt(e.substring(4,6),16)||128;return`rgb(${n}, ${i}, ${r})`}function d$e(t){if(!t)return!1;const e=t.replace("#","").substring(0,6),n=parseInt(e.substring(0,2),16)||0,i=parseInt(e.substring(2,4),16)||0,r=parseInt(e.substring(4,6),16)||0;return(.299*n+.587*i+.114*r)/255>.5}function iG({units:t,side:e,isPrinting:n,selectedAmsIndex:i,onSelectAms:r,selectedTray:a,onSelectTray:s}){const o=t[i],l=e==="left"?"A":"B";return h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-center text-[11px] font-semibold text-bambu-gray uppercase mb-2",children:e==="left"?"Left Nozzle":"Right Nozzle"}),h.jsx("div",{className:"flex gap-1.5 mb-2.5 p-1.5 bg-bambu-dark/50 rounded-lg w-fit",children:t.map((c,u)=>h.jsx("button",{onClick:()=>r(u),className:`flex items-center p-1.5 rounded border-2 transition-colors bg-bambu-dark ${i===u?"border-bambu-green":"border-transparent hover:border-bambu-gray"}`,children:h.jsx("div",{className:"flex gap-0.5",children:c.tray.map(f=>h.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:f.tray_color?nG(f.tray_color):"#808080"}},f.id))})},c.id))}),o&&h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-[10px] p-2.5",children:[h.jsxs("div",{className:"flex items-center gap-2.5 text-xs text-bambu-gray mb-2",children:[o.humidity!==null&&h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("img",{src:"/icons/water.svg",alt:"",className:"w-3.5 icon-theme"}),o.humidity," %"]}),o.temp!==null&&h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("img",{src:"/icons/temperature.svg",alt:"",className:"w-3.5 icon-theme"}),o.temp,"°C"]}),h.jsx("span",{className:"text-yellow-500 text-sm",children:"☀"})]}),h.jsx("div",{className:"flex justify-center gap-1.5 mb-1.5",children:o.tray.map((c,u)=>h.jsxs("div",{className:"w-12 flex items-center justify-center gap-0.5 text-[10px] text-bambu-gray px-1.5 py-[3px] bg-bambu-dark rounded-full border border-bambu-dark-tertiary",children:[l,u+1,h.jsx("img",{src:"/icons/reload.svg",alt:"",className:"w-2.5 h-2.5 icon-theme"})]},c.id))}),h.jsx("div",{className:"flex justify-center gap-1.5",children:o.tray.map(c=>{const u=o.id*4+c.id,f=a===u,m=!c.tray_type||c.tray_type===""||c.tray_type==="NONE",g=d$e(c.tray_color);return h.jsx("button",{onClick:()=>!m&&s(f?null:u),disabled:m||n,className:`w-12 h-[70px] rounded-md border-2 overflow-hidden transition-all bg-bambu-dark ${f?"border-[#d4a84b]":"border-bambu-dark-tertiary hover:border-bambu-gray"} ${m?"opacity-50":""} disabled:cursor-not-allowed`,children:h.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-end pb-[5px]",style:{backgroundColor:m?void 0:nG(c.tray_color)},children:[h.jsx("span",{className:`text-[11px] font-semibold mb-1 ${g?"text-gray-800":"text-white"} ${g?"":"drop-shadow-sm"}`,children:m?"--":c.tray_type}),!m&&h.jsx("img",{src:"/icons/eye.svg",alt:"",className:`w-3.5 h-3.5 ${g?"":"invert"}`,style:{opacity:.8}})]})},c.id)})})]}),t.length===0&&h.jsxs("div",{className:"bg-bambu-dark-secondary rounded-[10px] p-6 text-center text-bambu-gray text-sm",children:["No AMS connected to ",e," nozzle"]})]})}function f$e({isDualNozzle:t}){return t?h.jsxs("div",{className:"relative w-full",style:{height:"120px"},children:[h.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 600 120",preserveAspectRatio:"xMidYMid meet",children:[h.jsx("line",{x1:"68",y1:"0",x2:"68",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"122",y1:"0",x2:"122",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"176",y1:"0",x2:"176",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"230",y1:"0",x2:"230",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"68",y1:"14",x2:"230",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("rect",{x:"135",y:"8",width:"28",height:"14",rx:"2",fill:"#c0c0c0",stroke:"#909090",strokeWidth:"1"}),h.jsx("line",{x1:"149",y1:"22",x2:"149",y2:"36",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"149",y1:"36",x2:"288",y2:"36",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"288",y1:"36",x2:"288",y2:"85",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"370",y1:"0",x2:"370",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"424",y1:"0",x2:"424",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"478",y1:"0",x2:"478",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"532",y1:"0",x2:"532",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"370",y1:"14",x2:"532",y2:"14",stroke:"#909090",strokeWidth:"2"}),h.jsx("rect",{x:"437",y:"8",width:"28",height:"14",rx:"2",fill:"#c0c0c0",stroke:"#909090",strokeWidth:"1"}),h.jsx("line",{x1:"451",y1:"22",x2:"451",y2:"36",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"312",y1:"36",x2:"451",y2:"36",stroke:"#909090",strokeWidth:"2"}),h.jsx("line",{x1:"312",y1:"36",x2:"312",y2:"85",stroke:"#909090",strokeWidth:"2"})]}),h.jsx("img",{src:"/icons/extruder-left-right.png",alt:"Extruder",className:"absolute left-1/2 -translate-x-1/2 bottom-0 h-[50px]"})]}):null}function h$e({printerId:t,status:e,nozzleCount:n}){const i=e?.connected??!1,r=e?.state==="RUNNING",a=n>1,s=e?.ams??[],o=a?s.filter((A,T)=>T%2===0):s,l=a?s.filter((A,T)=>T%2===1):[],[c,u]=E.useState(0),[f,m]=E.useState(0),[g,b]=E.useState(null),y=yt({mutationFn:A=>He.amsLoadFilament(t,A)}),v=yt({mutationFn:()=>He.amsUnloadFilament(t)}),x=()=>{g!==null&&y.mutate(g)},M=()=>{v.mutate()},w=y.isPending||v.isPending;return h.jsxs("div",{className:"bg-bambu-dark-tertiary rounded-[10px] p-3",children:[h.jsxs("div",{className:"flex gap-5",children:[h.jsx(iG,{units:o,side:"left",isPrinting:r,selectedAmsIndex:c,onSelectAms:u,selectedTray:g,onSelectTray:b}),a&&h.jsx(iG,{units:l,side:"right",isPrinting:r,selectedAmsIndex:f,onSelectAms:m,selectedTray:g,onSelectTray:b})]}),h.jsx(f$e,{isDualNozzle:a}),h.jsxs("div",{className:"flex items-start -mt-[50px]",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("button",{className:"w-10 h-10 rounded-lg bg-bambu-dark-secondary hover:bg-bambu-dark border border-bambu-dark-tertiary flex items-center justify-center",children:h.jsx("img",{src:"/icons/ams-settings.svg",alt:"Settings",className:"w-5 icon-theme"})}),h.jsx("button",{className:"px-[18px] py-2.5 rounded-lg bg-bambu-dark-secondary hover:bg-bambu-dark border border-bambu-dark-tertiary text-sm text-bambu-gray flex items-center gap-1.5",children:"Auto-refill"})]}),h.jsx("div",{className:"flex-1"}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("button",{onClick:M,disabled:!i||r||w,className:"px-7 py-2.5 rounded-lg bg-bambu-dark hover:bg-bambu-dark-secondary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",children:v.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):"Unload"}),h.jsx("button",{onClick:x,disabled:!i||r||g===null||w,className:"px-7 py-2.5 rounded-lg bg-bambu-dark hover:bg-bambu-dark-secondary text-sm text-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed",children:y.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):"Load"})]})]}),(y.error||v.error)&&h.jsx("p",{className:"mt-2 text-sm text-red-500 text-center",children:(y.error||v.error)?.message})]})}function p$e({printerId:t,status:e,onClose:n}){const i=Gn(),r=e?.connected??!1;E.useEffect(()=>{const c=u=>{u.key==="Escape"&&n()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[n]);const a=yt({mutationFn:c=>He.setTimelapse(t,c),onSuccess:c=>{console.log("Timelapse mutation success:",c),i.invalidateQueries({queryKey:["printerStatuses"]})},onError:c=>{console.error("Timelapse mutation error:",c)}}),s=yt({mutationFn:c=>He.setLiveview(t,c),onSuccess:c=>{console.log("Liveview mutation success:",c),i.invalidateQueries({queryKey:["printerStatuses"]})},onError:c=>{console.error("Liveview mutation error:",c)}});console.log("CameraSettingsModal render - isConnected:",r,"status:",e);const o=()=>{console.log("Timelapse toggle clicked, current:",e?.timelapse,"setting to:",!e?.timelapse),a.mutate(!e?.timelapse)},l=()=>{console.log("Liveview toggle clicked, current:",e?.ipcam,"setting to:",!e?.ipcam),s.mutate(!e?.ipcam)};return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:n,children:h.jsx(Xt,{className:"w-full max-w-sm",onClick:c=>c.stopPropagation(),children:h.jsxs(en,{className:"p-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary",children:[h.jsx("span",{className:"text-sm font-medium text-white",children:"Camera Settings"}),h.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:h.jsx(bn,{className:"w-4 h-4"})})]}),h.jsxs("div",{className:"p-4 space-y-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("span",{className:"text-sm text-white",children:"Auto-record Monitoring"}),h.jsx("button",{onClick:l,disabled:!r||s.isPending,className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e?.ipcam?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:s.isPending?h.jsx(It,{className:"absolute inset-0 m-auto w-4 h-4 animate-spin text-white"}):h.jsx("span",{className:`absolute top-1 w-4 h-4 rounded-full bg-white transition-transform ${e?.ipcam?"left-7":"left-1"}`})})]}),h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("span",{className:"text-sm text-white",children:"Go Live"}),h.jsx("button",{onClick:o,disabled:!r||a.isPending,className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e?.timelapse?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:a.isPending?h.jsx(It,{className:"absolute inset-0 m-auto w-4 h-4 animate-spin text-white"}):h.jsx("span",{className:`absolute top-1 w-4 h-4 rounded-full bg-white transition-transform ${e?.timelapse?"left-7":"left-1"}`})})]})]})]})})})}function rG(t){const e=t.toUpperCase();if(e.startsWith("HH")||e.startsWith("HS"))return"Hardened Steel";if(e.startsWith("SS"))return"Stainless Steel";switch(t){case"hardened_steel":return"Hardened Steel";case"stainless_steel":return"Stainless Steel";default:return t||"Unknown"}}function aG(t){return t.toUpperCase().startsWith("HH")?"High flow":"Standard"}function m$e({printer:t,status:e,onClose:n}){const i=Gn(),r=t.nozzle_count>1;E.useEffect(()=>{const u=f=>{f.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n]);const a=e?.nozzles?.[0],s=e?.nozzles?.[1],o=s?.nozzle_type||s?.nozzle_diameter?s:a,l=yt({mutationFn:()=>He.refreshStatus(t.id),onSuccess:()=>{i.invalidateQueries({queryKey:["printerStatuses"]})}}),c=()=>{l.mutate()};return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:n,children:h.jsx(Xt,{className:"w-full max-w-2xl",onClick:u=>u.stopPropagation(),children:h.jsxs(en,{className:"p-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary",children:[h.jsx("span",{className:"text-sm font-medium text-white",children:"Printer Parts"}),h.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:h.jsx(bn,{className:"w-4 h-4"})})]}),h.jsxs("div",{className:"p-6 space-y-6",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"text-base font-semibold text-white mb-3",children:r?"Left Nozzle":"Nozzle"}),h.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Type"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:rG(a?.nozzle_type||"")})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Diameter"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:a?.nozzle_diameter||"—"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Flow"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:aG(a?.nozzle_type||"")})]})]})]}),r&&h.jsxs("div",{children:[h.jsx("h3",{className:"text-base font-semibold text-white mb-3",children:"Right Nozzle"}),h.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Type"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:rG(o?.nozzle_type||"")})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Diameter"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:o?.nozzle_diameter||"—"})]}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-sm text-bambu-gray mb-1.5",children:"Flow"}),h.jsx("div",{className:"px-3 py-2 bg-bambu-dark rounded border border-bambu-dark-tertiary text-sm text-bambu-gray",children:aG(o?.nozzle_type||"")})]})]})]}),h.jsxs("p",{className:"text-sm text-bambu-gray",children:["Please change the nozzle settings on the printer."," ",h.jsx("a",{href:"https://wiki.bambulab.com",target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline",children:"View wiki"})]})]}),h.jsx("div",{className:"flex justify-end px-4 py-3 border-t border-bambu-dark-tertiary",children:h.jsxs("button",{onClick:c,disabled:l.isPending,className:"flex items-center gap-2 px-4 py-2 bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 text-white text-sm font-medium rounded",children:[l.isPending?h.jsx(It,{className:"w-4 h-4 animate-spin"}):h.jsx(Zo,{className:"w-4 h-4"}),"Refresh"]})})]})})})}function Fd({checked:t,onChange:e,disabled:n,loading:i}){return h.jsx("button",{onClick:()=>!n&&!i&&e(!t),disabled:n||i,className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${t?"bg-bambu-green border-bambu-green":"bg-transparent border-bambu-gray"} ${n||i?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:i?h.jsx(It,{className:"w-3 h-3 animate-spin text-white"}):t?h.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:h.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):null})}function r_({value:t,onChange:e,disabled:n,loading:i}){const[r,a]=E.useState(!1),s=["Low","Medium","High"],o=t.charAt(0).toUpperCase()+t.slice(1).toLowerCase(),l=n||i;return h.jsxs("div",{className:"relative",children:[h.jsxs("button",{onClick:()=>!l&&a(!r),disabled:l,className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white min-w-[100px] justify-between ${l?"opacity-50 cursor-not-allowed":"cursor-pointer hover:border-bambu-gray"}`,children:[i?h.jsx(It,{className:"w-4 h-4 animate-spin text-bambu-green"}):h.jsx("span",{children:o}),h.jsx(gm,{className:"w-4 h-4 text-bambu-gray"})]}),r&&!l&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>a(!1)}),h.jsx("div",{className:"absolute top-full left-0 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded shadow-lg z-20",children:s.map(c=>h.jsx("button",{onClick:()=>{e(c.toLowerCase()),a(!1)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.toLowerCase()===c.toLowerCase()?"text-bambu-green":"text-white"}`,children:c},c))})]})]})}function g$e({printer:t,status:e,onClose:n}){const i=Gn(),r=e?.print_options,a=e?.connected??!1;E.useEffect(()=>{const f=m=>{m.key==="Escape"&&n()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[n]);const s=yt({mutationFn:({apiModuleName:f,enabled:m,printHalt:g,sensitivity:b})=>He.setPrintOption(t.id,f,m,g,b),onSuccess:()=>{i.invalidateQueries({queryKey:["printerStatuses"]})}}),o=(f,m,g)=>{const b=m&&g!==void 0&&g!=="never_halt";s.mutate({uiModuleName:f,apiModuleName:f,enabled:m,printHalt:b,sensitivity:g??"medium"})},l=(f,m)=>{let g=f;f==="pileup_detector"&&(g="spaghetti_detector"),s.mutate({uiModuleName:f,apiModuleName:g,enabled:!0,printHalt:!0,sensitivity:m})},c=f=>s.isPending&&s.variables?.uiModuleName===f,u=f=>{if(!s.isPending||!s.variables?.sensitivity)return!1;const m=s.variables.uiModuleName;return m===f||m==="spaghetti_detector"&&f==="pileup_detector"||m==="pileup_detector"&&f==="spaghetti_detector"};return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:n,children:h.jsx(Xt,{className:"w-full max-w-xl max-h-[90vh] flex flex-col",onClick:f=>f.stopPropagation(),children:h.jsxs(en,{className:"p-0 flex flex-col h-full",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary",children:[h.jsx("span",{className:"text-sm font-medium text-white",children:"Print Options"}),h.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:h.jsx(bn,{className:"w-4 h-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[!a&&h.jsxs("div",{className:"flex items-center gap-2 p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400",children:[h.jsx(va,{className:"w-4 h-4"}),h.jsx("span",{className:"text-sm",children:"Printer not connected. Options cannot be changed."})]}),r?h.jsxs(h.Fragment,{children:[h.jsxs("div",{children:[h.jsx("h3",{className:"text-base font-semibold text-white mb-1",children:"AI Detections"}),h.jsx("p",{className:"text-xs text-bambu-gray mb-4",children:"Printer will send assistant message or pause printing if any of the following problem is detected."}),h.jsxs("div",{className:"space-y-5",children:[h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.spaghetti_detector,onChange:f=>o("spaghetti_detector",f,r.halt_print_sensitivity),disabled:!a,loading:c("spaghetti_detector")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Spaghetti Detection"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Detects spaghetti failure (scattered loose filament)."}),h.jsxs("div",{className:"flex items-center gap-3 ml-8",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Pausing Sensitivity:"}),h.jsx(r_,{value:r.halt_print_sensitivity||"medium",onChange:f=>l("spaghetti_detector",f),disabled:!a||!r.spaghetti_detector,loading:u("spaghetti_detector")})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.pileup_detector,onChange:f=>o("pileup_detector",f,r.pileup_sensitivity),disabled:!a,loading:c("pileup_detector")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Purge Chute Pile-Up Detection"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Monitors if the waste is piled up in the purge chute."}),h.jsxs("div",{className:"flex items-center gap-3 ml-8",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Pausing Sensitivity:"}),h.jsx(r_,{value:r.pileup_sensitivity||"medium",onChange:f=>l("pileup_detector",f),disabled:!a||!r.pileup_detector,loading:u("pileup_detector")})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.nozzle_clumping_detector,onChange:f=>o("clump_detector",f,r.nozzle_clumping_sensitivity),disabled:!a,loading:c("clump_detector")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Nozzle Clumping Detection"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Checks if the nozzle is clumping by filaments or other foreign objects."}),h.jsxs("div",{className:"flex items-center gap-3 ml-8",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Pausing Sensitivity:"}),h.jsx(r_,{value:r.nozzle_clumping_sensitivity||"medium",onChange:f=>l("clump_detector",f),disabled:!a||!r.nozzle_clumping_detector,loading:u("clump_detector")})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.airprint_detector,onChange:f=>o("airprint_detector",f,r.airprint_sensitivity),disabled:!a,loading:c("airprint_detector")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Air Printing Detection"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Detects air printing caused by nozzle clogging or filament grinding."}),h.jsxs("div",{className:"flex items-center gap-3 ml-8",children:[h.jsx("span",{className:"text-xs text-bambu-gray",children:"Pausing Sensitivity:"}),h.jsx(r_,{value:r.airprint_sensitivity||"medium",onChange:f=>l("airprint_detector",f),disabled:!a||!r.airprint_detector,loading:u("airprint_detector")})]})]})]})]}),h.jsx("hr",{className:"border-bambu-dark-tertiary"}),h.jsxs("div",{children:[h.jsx("h3",{className:"text-base font-semibold text-white mb-1",children:"Build Plate Detection"}),h.jsx("p",{className:"text-xs text-bambu-gray mb-4",children:"Ensures the build plate type and placement are correct."}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.buildplate_marker_detector,onChange:f=>o("buildplate_marker_detector",f),disabled:!a,loading:c("buildplate_marker_detector")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Type Detection"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Pauses printing when the detected build plate type does not match the selected one."})]})]}),h.jsx("hr",{className:"border-bambu-dark-tertiary"}),h.jsxs("div",{className:"space-y-5",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:r.auto_recovery_step_loss,onChange:f=>o("auto_recovery_step_loss",f),disabled:!a,loading:c("auto_recovery_step_loss")}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Auto-recover from step loss"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(Fd,{checked:e?.store_to_sdcard??!1,onChange:()=>{},disabled:!0}),h.jsx("span",{className:"text-sm font-medium text-white",children:"Store Sent Files on External Storage"}),h.jsx("span",{className:"text-xs text-bambu-gray italic",children:"(read-only)"})]}),h.jsx("p",{className:"text-xs text-bambu-gray ml-8",children:"Save the printing files initiated from Bambu Studio, Bambu Handy and MakerWorld on External Storage. This option can only be changed on the printer's touchscreen."})]})]})]}):h.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[h.jsx(va,{className:"w-4 h-4"}),h.jsx("span",{className:"text-sm",children:"Print options not available. Try refreshing."})]})]})]})})})}const x$e=new Set([1,3,13,25,39,40,47,48,50]);function ex({checked:t,onChange:e,disabled:n}){return h.jsx("button",{onClick:()=>!n&&e(!t),disabled:n,className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${t?"bg-bambu-green border-bambu-green":"bg-transparent border-bambu-gray"} ${n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:t&&h.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:h.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})})}function v$e({step:t,name:e,isActive:n,isComplete:i,isLast:r}){return h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsxs("div",{className:"flex flex-col items-center",children:[h.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs font-medium flex-shrink-0 bg-bambu-green text-white",children:t}),!r&&h.jsx("div",{className:`w-0.5 h-6 ${i?"bg-bambu-green":"bg-bambu-gray/30"}`})]}),h.jsx("span",{className:`text-sm pt-0.5 ${n?"text-white font-semibold":"text-bambu-gray"}`,children:e})]})}function b$e({printer:t,status:e,onClose:n}){const i=e?.connected??!1,r=t.nozzle_count===2,a=e?.stg_cur??-1,[s,o]=E.useState(!1),[l,c]=E.useState(!1),[u,f]=E.useState(!1),m=`calibration_options_${t.id}`,g=typeof window<"u"?localStorage.getItem(m):null,b=g?JSON.parse(g):null,[y,v]=E.useState(b?.bedLeveling??!0),[x,M]=E.useState(b?.vibration??!0),[w,A]=E.useState(b?.motorNoise??!0),[T,R]=E.useState(b?.nozzleOffset??r),[N,j]=E.useState(b?.highTempHeatbed??!1),[C,k]=E.useState(!1),F=e?.state,I=x$e.has(a)&&F==="RUNNING";E.useEffect(()=>{!C&&I?(c(!0),o(!0),k(!0)):!C&&!I&&k(!0)},[C,I]),E.useEffect(()=>{I&&!l&&(c(!0),f(!1))},[I,l]),E.useEffect(()=>{I&&!s&&o(!0)},[I,s]),E.useEffect(()=>{l&&!I&&!u&&f(!0)},[l,I,u]);const W=()=>{localStorage.removeItem(m),o(!1),c(!1),f(!1),v(!0),M(!0),A(!0),R(r),j(!1)};E.useEffect(()=>{const Y=se=>{se.key==="Escape"&&n()};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[n]);const O=yt({mutationFn:()=>He.startCalibration(t.id,{bed_leveling:y,vibration:x,motor_noise:w,nozzle_offset:T,high_temp_heatbed:N}),onSuccess:()=>{localStorage.setItem(m,JSON.stringify({bedLeveling:y,vibration:x,motorNoise:w,nozzleOffset:T,highTempHeatbed:N})),o(!0)}}),H=y||x||w||T||N,V=i&&H&&!O.isPending&&!I&&!u,$=[];$.push({name:"Homing toolhead",stages:[13]}),(y||N)&&$.push({name:"Cooling heatbed",stages:[50]}),y&&$.push({name:"Auto bed leveling - phase 1",stages:[1,47]}),w&&$.push({name:"Motor noise cancellation",stages:[25]}),x&&$.push({name:"Vibration compensation",stages:[3]}),y&&$.push({name:"Auto bed leveling - phase 2",stages:[48]}),r&&T&&$.push({name:"Nozzle offset calibration",stages:[39]}),N&&$.push({name:"High-temp heatbed calibration",stages:[40]});const K=$.findIndex(Y=>Y.stages.includes(a));return h.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:n,children:h.jsx(Xt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col",onClick:Y=>Y.stopPropagation(),children:h.jsxs(en,{className:"p-0 flex flex-col h-full",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary",children:[h.jsx("span",{className:"text-sm font-medium text-white",children:"Calibration"}),h.jsx("button",{onClick:n,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white",children:h.jsx(bn,{className:"w-4 h-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[!i&&h.jsxs("div",{className:"flex items-center gap-2 p-3 mb-4 bg-red-500/20 border border-red-500/50 rounded text-red-400",children:[h.jsx(va,{className:"w-4 h-4"}),h.jsx("span",{className:"text-sm",children:"Printer not connected. Calibration cannot be started."})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-8",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"text-base font-semibold text-white mb-4",children:"Calibration step selection"}),h.jsxs("div",{className:"space-y-4",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(ex,{checked:y,onChange:v,disabled:!i||I}),h.jsx("span",{className:"text-sm text-white",children:"Bed leveling"})]}),h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(ex,{checked:x,onChange:M,disabled:!i||I}),h.jsx("span",{className:"text-sm text-white",children:"Vibration compensation"})]}),h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(ex,{checked:w,onChange:A,disabled:!i||I}),h.jsx("span",{className:"text-sm text-white",children:"Motor noise cancellation"})]}),r&&h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(ex,{checked:T,onChange:R,disabled:!i||I}),h.jsx("span",{className:"text-sm text-white",children:"Nozzle offset calibration"})]}),h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx(ex,{checked:N,onChange:j,disabled:!i||I}),h.jsx("span",{className:"text-sm text-white whitespace-nowrap",children:"High-temperature Heatbed Calibration"})]})]}),h.jsxs("div",{className:"mt-6",children:[h.jsx("h4",{className:"text-sm font-semibold text-white mb-2",children:"Calibration program"}),h.jsx("p",{className:"text-xs text-bambu-gray",children:"The calibration program detects the status of your device automatically to minimize deviation. It keeps the device performing optimally."})]})]}),h.jsxs("div",{className:"flex flex-col",children:[h.jsx("h3",{className:"text-base font-semibold text-bambu-green mb-4 text-center border-b border-bambu-dark-tertiary pb-2",children:"Calibration Flow"}),h.jsx("div",{className:"flex-1 py-4 pl-4",children:H?h.jsxs("div",{className:"space-y-0",children:[$.map((Y,se)=>{const B=s&&!u&&Y.stages.includes(a),X=u||s&&K>se;return h.jsx(v$e,{step:se+1,name:Y.name,isActive:B,isComplete:X,isLast:se===$.length-1},Y.name)}),a>=0&&K===-1&&e?.stg_cur_name&&h.jsxs("div",{className:"mt-4 text-xs text-bambu-gray",children:["Current: ",e.stg_cur_name]})]}):h.jsx("div",{className:"flex items-center justify-center h-full text-sm text-bambu-gray italic",children:"Select calibration steps"})}),u?h.jsxs("div",{className:"space-y-2",children:[h.jsxs("button",{disabled:!0,className:"w-full py-2.5 px-4 rounded-lg font-medium text-sm flex items-center justify-center gap-2 bg-bambu-green text-white cursor-default",children:[h.jsx(jp,{className:"w-4 h-4"}),"Completed"]}),h.jsx("button",{onClick:W,className:"w-full py-2 px-4 rounded-lg font-medium text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors",children:"New Calibration"})]}):h.jsx("button",{onClick:()=>O.mutate(),disabled:!V,className:`w-full py-2.5 px-4 rounded-lg font-medium text-sm flex items-center justify-center gap-2 transition-colors ${I?"bg-bambu-gray/50 text-white cursor-not-allowed":V?"bg-bambu-green hover:bg-bambu-green/90 text-white":"bg-bambu-dark-tertiary text-bambu-gray cursor-not-allowed"}`,children:I?h.jsxs(h.Fragment,{children:[h.jsx(It,{className:"w-4 h-4 animate-spin"}),"Calibrating"]}):O.isPending?h.jsxs(h.Fragment,{children:[h.jsx(It,{className:"w-4 h-4 animate-spin"}),"Starting..."]}):"Start Calibration"}),O.isError&&h.jsx("div",{className:"mt-2 text-xs text-red-400 text-center",children:O.error?.message||"Failed to start calibration"})]})]})]})]})})})}function y$e(){const[t,e]=Are(),[n,i]=E.useState(null),[r,a]=E.useState(!1),[s,o]=E.useState(!1),[l,c]=E.useState(!1),[u,f]=E.useState(!1),{data:m,isLoading:g}=Ht({queryKey:["printers"],queryFn:He.getPrinters}),{data:b}=Ht({queryKey:["printerStatuses"],queryFn:async()=>{if(!m)return{};const A={};return await Promise.all(m.map(async T=>{try{A[T.id]=await He.getPrinterStatus(T.id)}catch{}})),A},enabled:!!m&&m.length>0,refetchInterval:2e3});E.useEffect(()=>{const A=t.get("printer");if(A){const T=parseInt(A,10);if(!isNaN(T)){i(T);return}}m&&m.length>0&&!n&&i(m[0].id)},[m,t,n]);const y=A=>{i(A),e({printer:String(A)})},v=m?.find(A=>A.id===n),x=n?b?.[n]:null,w=x?new Set([1,3,13,25,39,40,47,48,50]).has(x.stg_cur):!1;return g?h.jsx("div",{className:"flex items-center justify-center h-screen",children:h.jsx(It,{className:"w-8 h-8 animate-spin text-bambu-green"})}):!m||m.length===0?h.jsxs("div",{className:"flex flex-col items-center justify-center h-screen text-bambu-gray",children:[h.jsx(Fp,{className:"w-16 h-16 mb-4"}),h.jsx("p",{className:"text-xl",children:"No printers configured"}),h.jsx("p",{className:"text-sm mt-2",children:"Add a printer in the Printers page first"})]}):h.jsxs("div",{className:"h-screen flex flex-col bg-bambu-dark",children:[h.jsx("div",{className:"bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:h.jsx("div",{className:"flex overflow-x-auto",children:m.filter(A=>b?.[A.id]?.connected).map(A=>{const T=b?.[A.id],R=A.id===n;return h.jsxs("button",{onClick:()=>y(A.id),className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors whitespace-nowrap border-b-2 ${R?"border-bambu-green text-bambu-green bg-bambu-dark":"border-transparent text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:[h.jsx("span",{className:"w-2 h-2 rounded-full bg-bambu-green"}),A.name,T?.state&&T.state!=="IDLE"&&h.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary",children:T.state})]},A.id)})})}),v&&h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsxs("div",{className:"flex-1 flex flex-col bg-bambu-dark",children:[h.jsxs("div",{className:"flex items-center justify-end gap-2 px-3 py-2.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary min-h-[44px]",children:[h.jsx("button",{className:`p-1.5 rounded hover:bg-bambu-dark-tertiary ${x?.sdcard?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:h.jsx("img",{src:"/icons/micro-sd.svg",alt:"SD Card",className:`w-4 h-4 ${x?.sdcard?"icon-green":"icon-theme"}`})}),h.jsx("button",{className:`p-1.5 rounded hover:bg-bambu-dark-tertiary ${x?.timelapse?"text-red-500":"text-bambu-gray hover:text-white"}`,children:h.jsx(fle,{className:"w-4 h-4"})}),h.jsx("button",{className:`p-1.5 rounded hover:bg-bambu-dark-tertiary ${x?.ipcam?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:h.jsx(ple,{className:"w-4 h-4"})}),h.jsx("button",{onClick:()=>a(!0),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:h.jsx(r9,{className:"w-4 h-4"})})]}),h.jsx("div",{className:"flex-1 bg-black",children:h.jsx(JVe,{printerId:v.id,isConnected:x?.connected??!1})}),h.jsx("div",{className:"h-1 bg-bambu-green"}),h.jsx("div",{className:"bg-bambu-dark-secondary p-4 px-5",children:h.jsx(t$e,{printerId:v.id,status:x})})]}),h.jsxs("div",{className:"w-[680px] flex flex-col bg-bambu-dark-secondary border-l border-bambu-dark-tertiary overflow-y-auto",children:[h.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 border-b border-bambu-dark-tertiary min-h-[44px]",children:[h.jsx("span",{className:"text-sm text-bambu-gray",children:"Control"}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx("button",{onClick:()=>o(!0),className:"px-4 py-1.5 text-xs rounded bg-bambu-green text-white hover:bg-bambu-green-dark",children:"Printer Parts"}),h.jsx("button",{onClick:()=>c(!0),className:"px-4 py-1.5 text-xs rounded bg-bambu-green text-white hover:bg-bambu-green-dark",children:"Print Options"}),h.jsx("button",{onClick:()=>f(!0),className:"px-4 py-1.5 text-xs rounded bg-bambu-green text-white hover:bg-bambu-green-dark",children:"Calibration"})]})]}),!x?.connected&&h.jsxs("div",{className:"m-3 p-3 bg-red-500/20 border border-red-500/50 rounded-lg flex items-center gap-3",children:[h.jsx(Fp,{className:"w-4 h-4 text-red-500"}),h.jsx("span",{className:"text-sm text-red-400",children:"Printer is not connected. Controls are disabled."})]}),h.jsxs("div",{className:"flex-1 p-4 bg-bambu-dark",children:[h.jsx("div",{className:"mb-4 bg-bambu-dark-tertiary rounded-[10px] p-3",children:h.jsxs("div",{className:"flex gap-4 bg-bambu-dark-secondary rounded-[8px] p-4 overflow-hidden",style:{minHeight:"300px"},children:[h.jsx(o$e,{printer:v,status:x,disabled:w}),h.jsxs("div",{className:"flex-1 flex gap-6 items-center justify-center",children:[h.jsxs("div",{className:"flex flex-col items-center",children:[h.jsx(l$e,{printerId:v.id,status:x,disabled:w}),h.jsx(c$e,{printerId:v.id,status:x,disabled:w})]}),h.jsx(u$e,{printerId:v.id,status:x,nozzleCount:v.nozzle_count,disabled:w})]})]})}),h.jsx(h$e,{printerId:v.id,status:x,nozzleCount:v.nozzle_count})]})]})]}),r&&v&&h.jsx(p$e,{printerId:v.id,status:x,onClose:()=>a(!1)}),s&&v&&h.jsx(m$e,{printer:v,status:x,onClose:()=>o(!1)}),l&&v&&h.jsx(g$e,{printer:v,status:x,onClose:()=>c(!1)}),u&&v&&h.jsx(b$e,{printer:v,status:x,onClose:()=>f(!1)})]})}function _$e(){const t=E.useRef(null),e=E.useRef(null),n=Gn(),[i,r]=E.useState(!1),a=E.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,u=new WebSocket(c);let f=null;u.onopen=()=>{console.log("[WebSocket] Connected"),r(!0),f=window.setInterval(()=>{u.readyState===WebSocket.OPEN&&u.send(JSON.stringify({type:"ping"}))},3e4)},u.onmessage=m=>{try{const g=JSON.parse(m.data);s(g)}catch{}},u.onclose=m=>{console.log("[WebSocket] Closed",m.code,m.reason),f&&(clearInterval(f),f=null),r(!1),t.current=null,e.current=window.setTimeout(()=>{a()},3e3)},u.onerror=m=>{console.error("[WebSocket] Error",m),u.close()},t.current=u},[]),s=E.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]);E.useEffect(()=>(a(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[a]);const o=E.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:i,sendMessage:o}}const S$e=new tae({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function w$e({children:t}){return _$e(),h.jsx(h.Fragment,{children:t})}function M$e(){return h.jsx(Ale,{children:h.jsx(Ile,{children:h.jsx(nae,{client:S$e,children:h.jsx(w$e,{children:h.jsx(Sre,{children:h.jsx(Qie,{children:h.jsxs(Lo,{path:"/",element:h.jsx(Dle,{}),children:[h.jsx(Lo,{index:!0,element:h.jsx(Qle,{})}),h.jsx(Lo,{path:"archives",element:h.jsx(M2e,{})}),h.jsx(Lo,{path:"queue",element:h.jsx(T2e,{})}),h.jsx(Lo,{path:"stats",element:h.jsx(RVe,{})}),h.jsx(Lo,{path:"profiles",element:h.jsx(qVe,{})}),h.jsx(Lo,{path:"maintenance",element:h.jsx(QVe,{})}),h.jsx(Lo,{path:"control",element:h.jsx(y$e,{})}),h.jsx(Lo,{path:"settings",element:h.jsx(FVe,{})})]})})})})})})})}nne.createRoot(document.getElementById("root")).render(h.jsx(E.StrictMode,{children:h.jsx(M$e,{})})); diff --git a/static/index.html b/static/index.html index cf6ad6d48..d54d3424d 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ - +