diff --git a/CHANGELOG.md b/CHANGELOG.md index 7876cc272..e703ae6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to Bambuddy will be documented in this file. - **Spool Assignment Changes Sync Across Tabs** — Assigning or unassigning a spool now broadcasts a WebSocket event to all connected clients. Other open browser tabs and the SpoolBuddy frontend update automatically without requiring a page reload. - **SpoolBuddy Auto-Navigate on Tag Scan** — When an NFC tag is detected while the SpoolBuddy UI is on a non-dashboard page (Settings, AMS, Write Tag, etc.), the frontend automatically navigates back to the main dashboard to show the scanned spool. Also wakes the screen if the display was blanked. - **SpoolBuddy Swipe to Switch Printers** — Swiping left/right on the SpoolBuddy touchscreen now cycles through online printers instead of triggering browser back/forward navigation. The selected printer updates in the top bar dropdown. Requires at least two online printers; single-printer setups are unaffected. +- **SpoolBuddy Virtual Keyboard No Longer Overlays Input Fields** — The virtual keyboard now adds temporary scroll padding to the content area when it opens, ensuring the focused input field scrolls above the keyboard instead of being hidden behind it. Fixes text entry on the SpoolBuddy Settings device tab (backend URL, API token fields). - **SpoolBuddy System Tab** — Added a "System" tab to SpoolBuddy Settings showing live OS stats from the Raspberry Pi: CPU temperature, core count, load average, memory usage, disk usage, OS distro/kernel/architecture, Python version, and system uptime. Stats are collected by the daemon every heartbeat (10s) using stdlib-only reads from `/proc` and `/sys` — no additional dependencies required. Usage bars turn amber at 70% and red at 90%; CPU temperature is color-coded green/amber/red. ### Fixed diff --git a/frontend/src/components/VirtualKeyboard.tsx b/frontend/src/components/VirtualKeyboard.tsx index f884764fb..b0da85ee2 100644 --- a/frontend/src/components/VirtualKeyboard.tsx +++ b/frontend/src/components/VirtualKeyboard.tsx @@ -26,6 +26,30 @@ export function VirtualKeyboard() { const keyboardRef = useRef | null>(null); const containerRef = useRef(null); + // Add bottom padding to the scrollable ancestor so inputs can scroll above the keyboard + const paddedParentRef = useRef(null); + + const addScrollPadding = useCallback((target: HTMLElement) => { + // Find nearest scrollable ancestor + let el: HTMLElement | null = target.parentElement; + while (el) { + const style = getComputedStyle(el); + if (style.overflowY === 'auto' || style.overflowY === 'scroll') break; + el = el.parentElement; + } + if (!el) return; + paddedParentRef.current = el; + // Keyboard is ~260px tall; add generous padding + el.style.paddingBottom = '280px'; + }, []); + + const removeScrollPadding = useCallback(() => { + if (paddedParentRef.current) { + paddedParentRef.current.style.paddingBottom = ''; + paddedParentRef.current = null; + } + }, []); + const handleFocusIn = useCallback((e: FocusEvent) => { if (closingRef.current) return; const target = e.target as HTMLElement; @@ -47,11 +71,12 @@ export function VirtualKeyboard() { // eslint-disable-next-line @typescript-eslint/no-explicit-any (keyboardRef.current as any)?.setInput?.(activeInput.current.value); - // Scroll input into view above the keyboard + // Add scroll padding then scroll input into view above the keyboard + addScrollPadding(target); setTimeout(() => { target.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 100); - }, []); + }, [addScrollPadding]); const handleFocusOut = useCallback(() => { // Delay to allow click on keyboard buttons to register @@ -64,10 +89,11 @@ export function VirtualKeyboard() { ) { return; } + removeScrollPadding(); setVisible(false); activeInput.current = null; }, 150); - }, []); + }, [removeScrollPadding]); useEffect(() => { document.addEventListener('focusin', handleFocusIn); @@ -83,6 +109,7 @@ export function VirtualKeyboard() { const dismiss = useCallback(() => { closingRef.current = true; setClosing(true); + removeScrollPadding(); activeInput.current?.blur(); activeInput.current = null; setTimeout(() => { @@ -90,7 +117,7 @@ export function VirtualKeyboard() { setClosing(false); closingRef.current = false; }, 400); - }, []); + }, [removeScrollPadding]); const onKeyPress = useCallback((button: string) => { const input = activeInput.current; diff --git a/static/assets/index-B2-uBp6-.js b/static/assets/index-C7t_l7cK.js similarity index 99% rename from static/assets/index-B2-uBp6-.js rename to static/assets/index-C7t_l7cK.js index 466988657..40cc83368 100644 --- a/static/assets/index-B2-uBp6-.js +++ b/static/assets/index-C7t_l7cK.js @@ -8726,7 +8726,7 @@ Difference: ${l}g (mismatch!)`;return i.jsxs("div",{className:`flex items-center In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function f(B,X){if(B){if(typeof B=="string")return y(B,X);var D={}.toString.call(B).slice(8,-1);return D==="Object"&&B.constructor&&(D=B.constructor.name),D==="Map"||D==="Set"?Array.from(B):D==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(D)?y(B,X):void 0}}function y(B,X){(X==null||X>B.length)&&(X=B.length);for(var D=0,M=Array(X);D"u"||"remove"in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<"u"&&"document"in self&&((!("classList"in document.createElement("_"))||document.createElementNS&&!("classList"in document.createElementNS("http://www.w3.org/2000/svg","g")))&&(function(B){if("Element"in B){var X="classList",D="prototype",M=B.Element[D],U=Object,W=String[D].trim||function(){return this.replace(/^\s+|\s+$/g,"")},H=Array[D].indexOf||function(oe){for(var me=0,fe=this.length;me2&&arguments[2]!==void 0&&arguments[2]?Object.assign({},this.getDefaultDiplay(),U):U||this.getDefaultDiplay())[M]||M}},{key:"getUpdatedInput",value:function(M,U,W){var H=arguments.length>3&&arguments[3]!==void 0?arguments[3]:W,re=arguments.length>4&&arguments[4]!==void 0&&arguments[4],O=this.getOptions(),q=[W,H,re],Y=U;return(M==="{bksp}"||M==="{backspace}")&&Y.length>0?Y=this.removeAt.apply(this,[Y].concat(q)):(M==="{delete}"||M==="{forwarddelete}")&&Y.length>0?Y=this.removeForwardsAt.apply(this,[Y].concat(q)):M==="{space}"?Y=this.addStringAt.apply(this,[Y," "].concat(q)):M!=="{tab}"||typeof O.tabCharOnTab=="boolean"&&O.tabCharOnTab===!1?M!=="{enter}"&&M!=="{numpadenter}"||!O.newLineOnEnter?M.includes("numpad")&&Number.isInteger(Number(M[M.length-2]))?Y=this.addStringAt.apply(this,[Y,M[M.length-2]].concat(q)):M==="{numpaddivide}"?Y=this.addStringAt.apply(this,[Y,"/"].concat(q)):M==="{numpadmultiply}"?Y=this.addStringAt.apply(this,[Y,"*"].concat(q)):M==="{numpadsubtract}"?Y=this.addStringAt.apply(this,[Y,"-"].concat(q)):M==="{numpadadd}"?Y=this.addStringAt.apply(this,[Y,"+"].concat(q)):M==="{numpaddecimal}"?Y=this.addStringAt.apply(this,[Y,"."].concat(q)):M==="{"||M==="}"?Y=this.addStringAt.apply(this,[Y,M].concat(q)):M.includes("{")||M.includes("}")||(Y=this.addStringAt.apply(this,[Y,M].concat(q))):Y=this.addStringAt.apply(this,[Y,` `].concat(q)):Y=this.addStringAt.apply(this,[Y," "].concat(q)),O.debug&&console.log("Input will be: "+Y),Y}},{key:"updateCaretPos",value:function(M){var U=arguments.length>1&&arguments[1]!==void 0&&arguments[1],W=this.updateCaretPosAction(M,U);this.dispatch((function(H){H.setCaretPosition(W)}))}},{key:"updateCaretPosAction",value:function(M){var U=arguments.length>1&&arguments[1]!==void 0&&arguments[1],W=this.getOptions(),H=this.getCaretPosition();return H!=null&&(U?H>0&&(H-=M):H+=M),W.debug&&console.log("Caret at:",H),H}},{key:"addStringAt",value:function(M,U){var W,H=arguments.length>2&&arguments[2]!==void 0?arguments[2]:M.length,re=arguments.length>3&&arguments[3]!==void 0?arguments[3]:M.length,O=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return H||H===0?(W=[M.slice(0,H),U,M.slice(re)].join(""),this.isMaxLengthReached()||O&&this.updateCaretPos(U.length)):W=M+U,W}},{key:"removeAt",value:function(M){var U,W=arguments.length>1&&arguments[1]!==void 0?arguments[1]:M.length,H=arguments.length>2&&arguments[2]!==void 0?arguments[2]:M.length,re=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(W===0&&H===0)return M;if(W===H){var O=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;W&&W>=0?M.substring(W-2,W).match(O)?(U=M.substr(0,W-2)+M.substr(W),re&&this.updateCaretPos(2,!0)):(U=M.substr(0,W-1)+M.substr(W),re&&this.updateCaretPos(1,!0)):M.slice(-2).match(O)?(U=M.slice(0,-2),re&&this.updateCaretPos(2,!0)):(U=M.slice(0,-1),re&&this.updateCaretPos(1,!0))}else U=M.slice(0,W)+M.slice(H),re&&this.dispatch((function(q){q.setCaretPosition(W)}));return U}},{key:"removeForwardsAt",value:function(M){var U,W=arguments.length>1&&arguments[1]!==void 0?arguments[1]:M.length,H=arguments.length>2&&arguments[2]!==void 0?arguments[2]:M.length,re=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return M!=null&&M.length&&W!==null?(W===H?U=M.substring(W,W+2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?M.substr(0,W)+M.substr(W+2):M.substr(0,W)+M.substr(W+1):(U=M.slice(0,W)+M.slice(H),re&&this.dispatch((function(O){O.setCaretPosition(W)}))),U):M}},{key:"handleMaxLength",value:function(M,U){var W=this.getOptions(),H=W.maxLength,re=M[W.inputName||"default"],O=U.length-1>=H;if(U.length<=re.length)return!1;if(Number.isInteger(H))return W.debug&&console.log("maxLength (num) reached:",O),O?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if(v(H)==="object"){var q=U.length-1>=H[W.inputName||"default"];return W.debug&&console.log("maxLength (obj) reached:",q),q?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:"isMaxLengthReached",value:function(){return!!this.maxLengthReached}},{key:"isTouchDevice",value:function(){return"ontouchstart"in window||navigator.maxTouchPoints}},{key:"pointerEventsSupported",value:function(){return!!window.PointerEvent}},{key:"camelCase",value:function(M){return M?M.toLowerCase().trim().split(/[.\-_\s]/g).reduce((function(U,W){return W.length?U+W[0].toUpperCase()+W.slice(1):U})):""}},{key:"chunkArray",value:function(M,U){return p(Array(Math.ceil(M.length/U))).map((function(W,H){return M.slice(U*H,U+U*H)}))}},{key:"escapeRegex",value:function(M){return M.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}},{key:"getRtlOffset",value:function(M,U){var W=M,H=U.indexOf("‫");return H=O.length?{done:!0}:{done:!1,value:O[V++]}},e:function(ie){throw ie},f:ee}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var oe,me=!0,fe=!1;return{s:function(){Y=Y.call(O)},n:function(){var ie=Y.next();return me=ie.done,ie},e:function(ie){fe=!0,oe=ie},f:function(){try{me||Y.return==null||Y.return()}finally{if(fe)throw oe}}}})(Object.getOwnPropertyNames(M.prototype));try{for(H.s();!(W=H.n()).done;){var re=W.value;re==="constructor"||re==="bindMethods"||(U[re]=U[re].bind(U))}}catch(O){H.e(O)}finally{H.f()}}}],X&&b(B.prototype,X),D&&b(B,D),Object.defineProperty(B,"prototype",{writable:!1}),B;var B,X,D})();g(N,"noop",(function(){}));var C=N;function k(B){return k=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(X){return typeof X}:function(X){return X&&typeof Symbol=="function"&&X.constructor===Symbol&&X!==Symbol.prototype?"symbol":typeof X},k(B)}function P(B,X){for(var D=0;D1?(U=W)===null||U===void 0?void 0:U.toLowerCase():W}},{key:"keyCodeToKey",value:function(M){return{8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",91:"Meta",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9",106:"NumpadMultiply",107:"NumpadAdd",109:"NumpadSubtract",110:"NumpadDecimal",111:"NumpadDivide",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"}[M]||""}}],X&&P(B.prototype,X),D&&P(B,D),Object.defineProperty(B,"prototype",{writable:!1}),B;var B,X,D})();function F(B){return F=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(X){return typeof X}:function(X){return X&&typeof Symbol=="function"&&X.constructor===Symbol&&X!==Symbol.prototype?"symbol":typeof X},F(B)}function G(B,X){for(var D=0;D0&&arguments[0]!==void 0?arguments[0]:ve();return Y(R,be)},V.appendChild(ye)}));var ee=O>0,oe=document.createElement("div");oe.classList.add("hg-candidate-box-prev"),ee&&oe.classList.add("hg-candidate-box-btn-active");var me=function(){ee&&W.renderPage({candidateListPages:H,targetElement:re,pageIndex:O-1,nbPages:q,onItemSelected:Y})};this.options.useTouchEvents?oe.ontouchstart=me:oe.onclick=me,this.candidateBoxElement.appendChild(oe),this.candidateBoxElement.appendChild(V);var fe=OB.length)&&(X=B.length);for(var D=0,M=Array(X);D1&&arguments[1]!==void 0?arguments[1]:M;this.caretPosition=M,this.caretPositionEnd=U}},{key:"getInputCandidates",value:function(M){var U=this,W=this.options,H=W.layoutCandidates,re=W.layoutCandidatesCaseSensitiveMatch;if(!H||de(H)!=="object")return{};var O=Object.keys(H).filter((function(V){var ee=M.substring(0,U.getCaretPositionEnd()||0)||M,oe=new RegExp("".concat(U.utilities.escapeRegex(V),"$"),re?"g":"gi");return!!ae(ee.matchAll(oe)).length}));if(O.length>1){var q=O.sort((function(V,ee){return ee.length-V.length}))[0];return{candidateKey:q,candidateValue:H[q]}}if(O.length){var Y=O[0];return{candidateKey:Y,candidateValue:H[Y]}}return{}}},{key:"showCandidatesBox",value:function(M,U,W){var H=this;this.candidateBox&&this.candidateBox.show({candidateValue:U,targetElement:W,onSelect:function(re,O){var q=H.options,Y=q.layoutCandidatesCaseSensitiveMatch,V=q.disableCandidateNormalization,ee=q.enableLayoutCandidatesKeyPress,oe=re;V||(oe=re.normalize("NFD")),typeof H.options.beforeInputUpdate=="function"&&H.options.beforeInputUpdate(H);var me=H.getInput(H.options.inputName,!0),fe=H.getCaretPositionEnd()||0,ie=me.substring(0,fe||0)||me,L=new RegExp("".concat(H.utilities.escapeRegex(M),"$"),Y?"g":"gi"),R=ie.replace(L,oe),ne=me.replace(ie,R),ye=R.length-ie.length,ve=(fe||me.length)+ye;ve<0&&(ve=0),H.setInput(ne,H.options.inputName,!0),H.setCaretPosition(ve),ee&&typeof H.options.onKeyPress=="function"&&H.options.onKeyPress(re,O),typeof H.options.onChange=="function"&&H.options.onChange(H.getInput(H.options.inputName,!0),O),typeof H.options.onChangeAll=="function"&&H.options.onChangeAll(H.getAllInputs(),O)}})}},{key:"handleButtonClicked",value:function(M,U){var W=this.options,H=W.inputName,re=H===void 0?this.defaultName:H,O=W.debug;if(M!=="{//}"){this.input[re]||(this.input[re]=""),typeof this.options.beforeInputUpdate=="function"&&this.options.beforeInputUpdate(this);var q=this.utilities.getUpdatedInput(M,this.input[re],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(M)&&this.activeInputElement&&this.input[re]&&this.input[re]===q&&this.caretPosition===0&&this.caretPositionEnd===q.length)return this.setInput("",this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value="",this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(M,U);if(typeof this.options.onKeyPress=="function"&&this.options.onKeyPress(M,U),this.input[re]!==q&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(q))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,q))return;var Y=this.utilities.getUpdatedInput(M,this.input[re],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(Y,this.options.inputName,!0),O&&console.log("Input changed:",this.getAllInputs()),this.options.debug&&console.log("Caret at: ",this.getCaretPosition(),this.getCaretPositionEnd(),"(".concat(this.keyboardDOMClass,")"),U?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange=="function"&&this.options.onChange(this.getInput(this.options.inputName,!0),U),typeof this.options.onChangeAll=="function"&&this.options.onChangeAll(this.getAllInputs(),U),U!=null&&U.target&&this.options.enableLayoutCandidates){var V,ee=this.getInputCandidates(q),oe=ee.candidateKey,me=ee.candidateValue;oe&&me?this.showCandidatesBox(oe,me,this.keyboardDOM):(V=this.candidateBox)===null||V===void 0||V.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log("Caret position aligned",this.caretPosition)),O&&console.log("Key pressed:",M)}}},{key:"getMouseHold",value:function(){return this.isMouseHold}},{key:"setMouseHold",value:function(M){this.options.syncInstanceInputs?this.dispatch((function(U){U.isMouseHold=M})):this.isMouseHold=M}},{key:"handleButtonMouseDown",value:function(M,U){var W=this;U&&(this.options.preventMouseDownDefault&&U.preventDefault(),this.options.stopMouseDownPropagation&&U.stopPropagation(),U.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(W.getMouseHold()&&(!M.includes("{")&&!M.includes("}")||M==="{delete}"||M==="{backspace}"||M==="{bksp}"||M==="{space}"||M==="{tab}")||M==="{arrowright}"||M==="{arrowleft}"||M==="{arrowup}"||M==="{arrowdown}")&&(W.options.debug&&console.log("Button held:",M),W.handleButtonHold(M)),clearTimeout(W.holdTimeout)}),500))}},{key:"handleButtonMouseUp",value:function(M,U){var W=this;U&&(this.options.preventMouseUpDefault&&U.preventDefault&&U.preventDefault(),this.options.stopMouseUpPropagation&&U.stopPropagation&&U.stopPropagation(),!(U.target===this.keyboardDOM||U.target&&this.keyboardDOM.contains(U.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(U.target===this.candidateBox.candidateBoxElement||U.target&&this.candidateBox.candidateBoxElement.contains(U.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(H){H.classList.remove(W.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),M&&typeof this.options.onKeyReleased=="function"&&this.options.onKeyReleased(M,U)}},{key:"handleKeyboardContainerMouseDown",value:function(M){this.options.preventMouseDownDefault&&M.preventDefault()}},{key:"handleButtonHold",value:function(M){var U=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){U.getMouseHold()?(U.handleButtonClicked(M),U.handleButtonHold(M)):clearTimeout(U.holdInteractionTimeout)}),100)}},{key:"syncInstanceInputs",value:function(){var M=this;this.dispatch((function(U){U.replaceInput(M.input),U.setCaretPosition(M.caretPosition,M.caretPositionEnd)}))}},{key:"clearInput",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[M]="",this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"getInput",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,U=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!U&&this.syncInstanceInputs(),this.options.rtl?"‫"+this.input[M].replace("‫","").replace("‬","")+"‬":this.input[M]}},{key:"getAllInputs",value:function(){var M=this,U={};return Object.keys(this.input).forEach((function(W){U[W]=M.getInput(W,!0)})),U}},{key:"setInput",value:function(M){var U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,W=arguments.length>2?arguments[2]:void 0;this.input[U]=M,!W&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"replaceInput",value:function(M){this.input=M}},{key:"setOptions",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},U=this.changedOptions(M);this.options=Object.assign(this.options,M),U.length&&(this.options.debug&&console.log("changedOptions",U),this.onSetOptions(U),this.render())}},{key:"changedOptions",value:function(M){var U=this;return Object.keys(M).filter((function(W){return JSON.stringify(M[W])!==JSON.stringify(U.options[W])}))}},{key:"onSetOptions",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];M.includes("layoutName")&&this.candidateBox&&this.candidateBox.destroy(),(M.includes("layoutCandidatesPageSize")||M.includes("layoutCandidates"))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new te({utilities:this.utilities,options:this.options}))}},{key:"resetRows",value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute("data-skInstance",this.currentInstanceName),this.buttonElements={}}},{key:"dispatch",value:function(M){if(!window.SimpleKeyboardInstances)throw console.warn("SimpleKeyboardInstances is not defined. Dispatch cannot be called."),new Error("INSTANCES_VAR_ERROR");return Object.keys(window.SimpleKeyboardInstances).forEach((function(U){M(window.SimpleKeyboardInstances[U],U)}))}},{key:"addButtonTheme",value:function(M,U){var W=this;U&&M&&(M.split(" ").forEach((function(H){U.split(" ").forEach((function(re){W.options.buttonTheme||(W.options.buttonTheme=[]);var O=!1;W.options.buttonTheme.map((function(q){if(q!=null&&q.class.split(" ").includes(re)){O=!0;var Y=q.buttons.split(" ");Y.includes(H)||(O=!0,Y.push(H),q.buttons=Y.join(" "))}return q})),O||W.options.buttonTheme.push({class:re,buttons:M})}))})),this.render())}},{key:"removeButtonTheme",value:function(M,U){var W=this;if(!M&&!U)return this.options.buttonTheme=[],void this.render();M&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(M.split(" ").forEach((function(H){var re;(re=W.options)===null||re===void 0||(re=re.buttonTheme)===null||re===void 0||re.map((function(O,q){if(O&&U&&U.includes(O.class)||!U){var Y,V,ee=(Y=O)===null||Y===void 0?void 0:Y.buttons.split(" ").filter((function(oe){return oe!==H}));O&&ee!=null&&ee.length?O.buttons=ee.join(" "):((V=W.options.buttonTheme)===null||V===void 0||V.splice(q,1),O=null)}return O}))})),this.render())}},{key:"getButtonElement",value:function(M){var U,W=this.buttonElements[M];return W&&(U=W.length>1?W:W[0]),U}},{key:"inputPatternIsValid",value:function(M){var U,W=this.options.inputPattern;if((U=W instanceof RegExp?W:W[this.options.inputName||this.defaultName])&&M){var H=U.test(M);return this.options.debug&&console.log('inputPattern ("'.concat(U,'"): ').concat(H?"passed":"did not pass!")),H}return!0}},{key:"setEventListeners",value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log("Caret handling started (".concat(this.keyboardDOMClass,")"));var M=this.options.physicalKeyboardHighlightPreventDefault,U=M!==void 0&&M;document.addEventListener("keyup",this.handleKeyUp,U),document.addEventListener("keydown",this.handleKeyDown,U),document.addEventListener("mouseup",this.handleMouseUp),document.addEventListener("touchend",this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener("selectionchange",this.handleSelectionChange),document.addEventListener("select",this.handleSelect)}}},{key:"handleKeyUp",value:function(M){this.caretEventHandler(M),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(M)}},{key:"handleKeyDown",value:function(M){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(M)}},{key:"handleMouseUp",value:function(M){this.caretEventHandler(M)}},{key:"handleTouchEnd",value:function(M){this.caretEventHandler(M)}},{key:"handleSelect",value:function(M){this.caretEventHandler(M)}},{key:"handleSelectionChange",value:function(M){navigator.userAgent.includes("Firefox")||this.caretEventHandler(M)}},{key:"caretEventHandler",value:function(M){var U,W=this;M.target.tagName&&(U=M.target.tagName.toLowerCase()),this.dispatch((function(H){var re=M.target===H.keyboardDOM||M.target&&H.keyboardDOM.contains(M.target);if(W.options.syncInstanceInputs&&Array.isArray(M.path)&&(re=M.path.some((function(Y){var V;return Y==null||(V=Y.hasAttribute)===null||V===void 0?void 0:V.call(Y,"data-skInstance")}))),(U==="textarea"||U==="input"&&["text","search","url","tel","password"].includes(M.target.type))&&!H.options.disableCaretPositioning){var O=M.target.selectionStart,q=M.target.selectionEnd;H.options.rtl&&(O=H.utilities.getRtlOffset(O,H.getInput()),q=H.utilities.getRtlOffset(q,H.getInput())),H.setCaretPosition(O,q),H.activeInputElement=M.target,H.options.debug&&console.log("Caret at: ",H.getCaretPosition(),H.getCaretPositionEnd(),M&&M.target.tagName.toLowerCase(),"(".concat(H.keyboardDOMClass,")"),M?.type)}else!H.options.disableCaretPositioning&&re||M?.type==="selectionchange"||(H.setCaretPosition(null),H.activeInputElement=null,H.options.debug&&console.log('Caret position reset due to "'.concat(M?.type,'" event'),M))}))}},{key:"recurseButtons",value:function(M){var U=this;M&&Object.keys(this.buttonElements).forEach((function(W){return U.buttonElements[W].forEach(M)}))}},{key:"destroy",value:function(){this.options.debug&&console.log("Destroying simple-keyboard instance: ".concat(this.currentInstanceName));var M=this.options.physicalKeyboardHighlightPreventDefault,U=M!==void 0&&M;document.removeEventListener("keyup",this.handleKeyUp,U),document.removeEventListener("keydown",this.handleKeyDown,U),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("touchend",this.handleTouchEnd),document.removeEventListener("select",this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener("selectionchange",this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(W){W&&(W.onpointerdown=null,W.onpointerup=null,W.onpointercancel=null,W.ontouchstart=null,W.ontouchend=null,W.ontouchcancel=null,W.onclick=null,W.onmousedown=null,W.onmouseup=null,W.remove(),W=null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=null),this.activeInputElement=null,this.keyboardDOM.removeAttribute("data-skInstance"),this.keyboardDOM.innerHTML="",window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:"getButtonThemeClasses",value:function(M){var U=this.options.buttonTheme,W=[];return Array.isArray(U)&&U.forEach((function(H){if(H&&H.class&&typeof H.class=="string"&&H.buttons&&typeof H.buttons=="string"){var re=H.class.split(" ");H.buttons.split(" ").includes(M)&&(W=[].concat(ae(W),ae(re)))}else console.warn('Incorrect "buttonTheme". Please check the documentation.',H)})),W}},{key:"setDOMButtonAttributes",value:function(M,U){var W=this.options.buttonAttributes;Array.isArray(W)&&W.forEach((function(H){H.attribute&&typeof H.attribute=="string"&&H.value&&typeof H.value=="string"?H.buttons&&typeof H.buttons=="string"?H.buttons.split(" ").includes(M)&&U(H.attribute,H.value):U(H.attribute,H.value):console.warn('Incorrect "buttonAttributes". Please check the documentation.',H)}))}},{key:"onTouchDeviceDetected",value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:"disableContextualWindow",value:function(){window.oncontextmenu=function(M){var U;if((U=M.target.classList)!==null&&U!==void 0&&U.contains("hg-button"))return M.preventDefault(),M.stopPropagation(),!1}}},{key:"processAutoTouchEvents",value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log("autoUseTouchEvents: Touch device detected, useTouchEvents enabled."))}},{key:"onInit",value:function(){this.options.debug&&console.log("".concat(this.keyboardDOMClass," Initialized")),this.setEventListeners(),typeof this.options.onInit=="function"&&this.options.onInit(this)}},{key:"beforeFirstRender",value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender=="function"&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log("Using PointerEvents as it is supported by this browser"),this.options.useTouchEvents&&this.options.debug&&console.log("useTouchEvents has been enabled. Only touch events will be used.")}},{key:"beforeRender",value:function(){typeof this.options.beforeRender=="function"&&this.options.beforeRender(this)}},{key:"onRender",value:function(){typeof this.options.onRender=="function"&&this.options.onRender(this)}},{key:"onModulesLoaded",value:function(){typeof this.options.onModulesLoaded=="function"&&this.options.onModulesLoaded(this)}},{key:"loadModules",value:function(){var M=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(U){var W=M.utilities.isConstructor(U)?new U(M):U(M);W.init&&W.init(M)})),this.keyboardPluginClasses="modules-loaded",this.render(),this.onModulesLoaded())}},{key:"getModuleProp",value:function(M,U){return!!this.modules[M]&&this.modules[M][U]}},{key:"getModulesList",value:function(){return Object.keys(this.modules)}},{key:"parseRowDOMContainers",value:function(M,U,W,H){var re=this,O=Array.from(M.children),q=0;return O.length&&W.forEach((function(Y,V){var ee=H[V];if(!(ee&&ee>Y))return!1;var oe=Y-q,me=ee-q,fe=document.createElement("div");fe.className+="hg-button-container";var ie="".concat(re.options.layoutName,"-r").concat(U,"c").concat(V);fe.setAttribute("data-skUID",ie);var L=O.splice(oe,me-oe+1);q+=me-oe,L.forEach((function(R){return fe.appendChild(R)})),O.splice(oe,0,fe),M.innerHTML="",O.forEach((function(R){return M.appendChild(R)})),re.options.debug&&console.log("rowDOMContainer",L,oe,me,q+1)})),M}},{key:"render",value:function(){var M=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var U="hg-layout-".concat(this.options.layoutName),W=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p [ ] \\","{lock} a s d f g h j k l ; ' {enter}","{shift} z x c v b n m , . / {shift}",".com @ {space}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W E R T Y U I O P { } |",'{lock} A S D F G H J K L : " {enter}',"{shift} Z X C V B N M < > ? {shift}",".com @ {space}"]},H=this.options.useTouchEvents||!1,re=H?"hg-touch-events":"",O=this.options.useMouseEvents||!1,q=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,U,this.keyboardPluginClasses,re),this.keyboardDOM.setAttribute("data-skInstance",this.currentInstanceName),this.keyboardRowsDOM=document.createElement("div"),this.keyboardRowsDOM.className="hg-rows",W[this.options.layoutName||this.defaultName].forEach((function(Y,V){var ee=Y.split(" ");M.options.excludeFromLayout&&M.options.excludeFromLayout[M.options.layoutName||M.defaultName]&&(ee=ee.filter((function(ie){return M.options.excludeFromLayout&&!M.options.excludeFromLayout[M.options.layoutName||M.defaultName].includes(ie)})));var oe=document.createElement("div");oe.className+="hg-row";var me=[],fe=[];ee.forEach((function(ie,L){var R,ne=!q&&typeof ie=="string"&&ie.length>1&&ie.indexOf("[")===0,ye=!q&&typeof ie=="string"&&ie.length>1&&ie.indexOf("]")===ie.length-1;ne&&(me.push(L),ie=ie.replace(/\[/g,"")),ye&&(fe.push(L),ie=ie.replace(/\]/g,""));var ve=M.utilities.getButtonClass(ie),be=M.utilities.getButtonDisplayName(ie,M.options.display,M.options.mergeDisplay),Be=M.options.useButtonTag?"button":"div",we=document.createElement(Be);we.className+="hg-button ".concat(ve),(R=we.classList).add.apply(R,ae(M.getButtonThemeClasses(ie))),M.setDOMButtonAttributes(ie,(function(Ee,Ne){we.setAttribute(Ee,Ne)})),M.activeButtonClass="hg-activeButton",!M.utilities.pointerEventsSupported()||H||O?H?(we.ontouchstart=function(Ee){M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.ontouchend=function(Ee){M.handleButtonMouseUp(ie,Ee)},we.ontouchcancel=function(Ee){M.handleButtonMouseUp(ie,Ee)}):(we.onclick=function(Ee){M.setMouseHold(!1),typeof M.options.onKeyReleased=="function"||M.options.useMouseEvents&&M.options.clickOnMouseDown||M.handleButtonClicked(ie,Ee)},we.onmousedown=function(Ee){(typeof M.options.onKeyReleased=="function"||M.options.useMouseEvents&&M.options.clickOnMouseDown)&&!M.isMouseHold&&M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.onmouseup=function(Ee){M.handleButtonMouseUp(ie,Ee)}):(we.onpointerdown=function(Ee){M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.onpointerup=function(Ee){M.handleButtonMouseUp(ie,Ee)},we.onpointercancel=function(Ee){M.handleButtonMouseUp(ie,Ee)}),we.setAttribute("data-skBtn",ie);var Ae="".concat(M.options.layoutName,"-r").concat(V,"b").concat(L);we.setAttribute("data-skBtnUID",Ae);var Le=document.createElement("span");Le.innerHTML=be,we.appendChild(Le),M.buttonElements[ie]||(M.buttonElements[ie]=[]),M.buttonElements[ie].push(we),oe.appendChild(we)})),oe=M.parseRowDOMContainers(oe,V,me,fe),M.keyboardRowsDOM.appendChild(oe)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||H||O?H?(document.ontouchend=function(Y){return M.handleButtonMouseUp(void 0,Y)},document.ontouchcancel=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.ontouchstart=function(Y){return M.handleKeyboardContainerMouseDown(Y)}):H||(document.onmouseup=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.onmousedown=function(Y){return M.handleKeyboardContainerMouseDown(Y)}):(document.onpointerup=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.onpointerdown=function(Y){return M.handleKeyboardContainerMouseDown(Y)}),this.onInit())}}],X&&he(B.prototype,X),D&&he(B,D),Object.defineProperty(B,"prototype",{writable:!1}),B;var B,X,D})(),pe=ce,Se=pe;return m})()},442:function(l){l.exports=n}},a={};function s(l){var c=a[l];if(c!==void 0)return c.exports;var d=a[l]={exports:{}};return r[l].call(d.exports,d,d.exports,s),d.exports}s.n=function(l){var c=l&&l.__esModule?function(){return l.default}:function(){return l};return s.d(c,{a:c}),c},s.d=function(l,c){for(var d in c)s.o(c,d)&&!s.o(l,d)&&Object.defineProperty(l,d,{enumerable:!0,get:c[d]})},s.o=function(l,c){return Object.prototype.hasOwnProperty.call(l,c)},s.r=function(l){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(l,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(l,"__esModule",{value:!0})};var o={};return(function(){s.r(o),s.d(o,{KeyboardReact:function(){return v},default:function(){return b}}),s(981);var l=s(442),c=s(548),d=s.n(c);function u(g){return u=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(_){return typeof _}:function(_){return _&&typeof Symbol=="function"&&_.constructor===Symbol&&_!==Symbol.prototype?"symbol":typeof _},u(g)}function m(g,_){var N=Object.keys(g);if(Object.getOwnPropertySymbols){var C=Object.getOwnPropertySymbols(g);_&&(C=C.filter((function(k){return Object.getOwnPropertyDescriptor(g,k).enumerable}))),N.push.apply(N,C)}return N}function p(g){for(var _=1;_{if(a.current)return;const v=y.target;if(!v.closest('[data-vkb="false"]')){if(v instanceof HTMLInputElement){if(!Ont.has(v.type))return}else if(!(v instanceof HTMLTextAreaElement))return;l.current=v,e(!0),o("default"),c.current?.setInput?.(l.current.value),setTimeout(()=>{v.scrollIntoView({behavior:"smooth",block:"center"})},100)}},[]),m=w.useCallback(()=>{setTimeout(()=>{const y=document.activeElement;y&&(d.current?.contains(y)||y===l.current)||(e(!1),l.current=null)},150)},[]);w.useEffect(()=>(document.addEventListener("focusin",u),document.addEventListener("focusout",m),()=>{document.removeEventListener("focusin",u),document.removeEventListener("focusout",m)}),[u,m]);const p=w.useCallback(()=>{a.current=!0,r(!0),l.current?.blur(),l.current=null,setTimeout(()=>{e(!1),r(!1),a.current=!1},400)},[]),f=w.useCallback(y=>{const v=l.current;if(v){if(y==="{shift}"){o(b=>b==="default"?"shift":"default");return}if(y==="{lock}"){o(b=>b==="default"?"shift":"default");return}if(y==="{close}"){p();return}y==="{bksp}"?a3(v,v.value.slice(0,-1)):y==="{space}"?a3(v,v.value+" "):(a3(v,v.value+y),s==="shift"&&o("default")),v.focus(),c.current?.setInput?.(v.value)}},[s,p]);return t?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-[9998] bg-transparent",onMouseDown:y=>{y.preventDefault(),y.stopPropagation(),n||p()},onTouchStart:y=>{y.preventDefault(),y.stopPropagation(),n||p()},onClick:y=>{y.preventDefault(),y.stopPropagation()}}),!n&&i.jsx("div",{ref:d,className:"fixed bottom-0 left-0 right-0 z-[9999]",onMouseDown:y=>y.preventDefault(),onTouchStart:y=>{y.target.closest(".hg-button")||y.preventDefault()},children:i.jsx(Lnt,{keyboardRef:y=>{c.current=y},layoutName:s,onKeyPress:f,theme:"simple-keyboard vkb-theme",layout:{default:["1 2 3 4 5 6 7 8 9 0 {bksp}","q w e r t y u i o p","{lock} a s d f g h j k l","{shift} z x c v b n m . @","{space} {close}"],shift:["! @ # $ % ^ & * ( ) {bksp}","Q W E R T Y U I O P","{lock} A S D F G H J K L","{shift} Z X C V B N M , _","{space} {close}"]},display:{"{bksp}":"⌫","{close}":"✕ Close","{shift}":"⇧","{lock}":"⇪","{space}":" "}})})]}):null}function znt(){const[t,e]=w.useState(null),[n,r]=w.useState(null),[a,s]=w.useState(!1),[o,l]=w.useState(100),[c,d]=w.useState(0),u=w.useRef(Date.now()),{i18n:m}=jt(),p=Po(),f=Fc(),y=jnt(),{data:v}=et({queryKey:["settings"],queryFn:ge.getSettings});w.useEffect(()=>{v?.language&&v.language!==m.language&&m.changeLanguage(v.language)},[v?.language,m]);const{data:b=[]}=et({queryKey:["spoolbuddy-devices"],queryFn:()=>zi.getDevices(),refetchInterval:3e4}),g=b[0],_=y.deviceOnline||!!g?.online,N=w.useMemo(()=>({...y,deviceOnline:_}),[y,_]),C=w.useRef(!1);w.useEffect(()=>{g&&!C.current&&(l(g.display_brightness),d(g.display_blank_timeout),C.current=!0)},[g]),w.useEffect(()=>{const ue=document.documentElement,he=ue.classList.contains("dark");return ue.classList.add("dark"),()=>{he||ue.classList.remove("dark")}},[]);const{data:k}=et({queryKey:["spoolbuddy-update-check",g?.device_id],queryFn:()=>g?zi.checkDaemonUpdate(g.device_id):Promise.resolve(null),enabled:!!g,refetchInterval:300*1e3,staleTime:0});w.useEffect(()=>{_?k?.update_available&&k.latest_version?r({type:"info",message:`Update available: v${k.latest_version}`}):r(null):r({type:"warning",message:"SpoolBuddy device disconnected"})},[_,k?.update_available,k?.latest_version]);const P=w.useCallback(()=>{u.current=Date.now(),s(!1)},[]);w.useEffect(()=>(window.addEventListener("pointerdown",P),window.addEventListener("keydown",P),()=>{window.removeEventListener("pointerdown",P),window.removeEventListener("keydown",P)}),[P]);const A=!!(y.matchedSpool||y.unknownTagUid),j=w.useRef(!1);w.useEffect(()=>{A&&!j.current&&(P(),f.pathname!=="/spoolbuddy"&&p("/spoolbuddy")),j.current=A},[A,f.pathname,p,P]),w.useEffect(()=>{if(c<=0)return;const ue=setInterval(()=>{Date.now()-u.current>=c*1e3&&s(!0)},1e3);return()=>clearInterval(ue)},[c]);const{data:T=[]}=et({queryKey:["printers"],queryFn:()=>ge.getPrinters()}),F=Jh({queries:T.map(ue=>({queryKey:["printerStatus",ue.id],queryFn:()=>ge.getPrinterStatus(ue.id),refetchInterval:1e4}))}),G=w.useMemo(()=>T.filter((ue,he)=>F[he]?.data?.connected),[T,F]),z=w.useRef(null),J=w.useRef(!1),I=50,te=w.useRef(null),ae=w.useCallback(ue=>{z.current={x:ue.touches[0].clientX,y:ue.touches[0].clientY},J.current=!1},[]),Z=w.useCallback(ue=>{if(!z.current||G.length<2)return;const he=ue.changedTouches[0].clientX-z.current.x,K=ue.changedTouches[0].clientY-z.current.y;if(z.current=null,J.current=!1,Math.abs(he)Math.abs(he))return;const se=G.findIndex(pe=>pe.id===t),ce=he<0?(se+1)%G.length:(se-1+G.length)%G.length;e(G[ce].id)},[G,t,e]);w.useEffect(()=>{const ue=te.current;if(!ue)return;const he=K=>{if(!z.current)return;const se=Math.abs(K.touches[0].clientX-z.current.x),ce=Math.abs(K.touches[0].clientY-z.current.y);if(J.current){K.preventDefault();return}se>10&&se>ce&&(J.current=!0,K.preventDefault())};return ue.addEventListener("touchmove",he,{passive:!1}),()=>ue.removeEventListener("touchmove",he)},[]);const de=o<100?{filter:`brightness(${o/100})`}:void 0;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{ref:te,className:"w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden",style:{...de,overscrollBehaviorX:"none"},onTouchStart:ae,onTouchEnd:Z,children:[i.jsx(Cnt,{selectedPrinterId:t,onPrinterChange:e,deviceOnline:_}),i.jsx("main",{className:"flex-1 overflow-y-auto",children:i.jsx(TX,{context:{selectedPrinterId:t,setSelectedPrinterId:e,sbState:N,setAlert:r,displayBrightness:o,setDisplayBrightness:l,displayBlankTimeout:c,setDisplayBlankTimeout:d}})}),i.jsx(Pnt,{alert:n}),i.jsx(Ant,{}),i.jsx(Int,{})]}),a&&i.jsx("div",{className:"fixed inset-0 bg-black z-[9999]",onPointerDown:ue=>{ue.stopPropagation(),P()}})]})}function O5({color:t,isEmpty:e,size:n=32}){return e?i.jsx("div",{className:"rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center",style:{width:n,height:n},children:i.jsx("div",{className:"w-2 h-2 rounded-full bg-zinc-600"})}):i.jsxs("svg",{width:n,height:n,viewBox:"0 0 32 32",children:[i.jsx("circle",{cx:"16",cy:"16",r:"14",fill:t,stroke:"white",strokeWidth:"1.5",strokeOpacity:"0.7"}),i.jsx("circle",{cx:"16",cy:"16",r:"11",fill:t,style:{filter:"brightness(0.85)"}})]})}const Unt="spoolbuddy-default-core-weight";function yle(){try{const t=localStorage.getItem(Unt);if(t){const e=parseInt(t,10);if(e>=0&&e<=500)return e}}catch{}return 250}function Bnt({spool:t,scaleWeight:e,onClose:n,onSyncWeight:r,onAssignToAms:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(!1),u=t.rgba?`#${t.rgba.slice(0,6)}`:"#808080",m=t.core_weight&&t.core_weight>0?t.core_weight:yle(),p=e!==null?Math.round(Math.max(0,e)):null,f=p!==null?Math.round(Math.max(0,p-m)):null,y=Math.round(t.label_weight||1e3),v=f!==null?Math.min(100,Math.round(f/y*100)):null,b=v!==null?v>50?"#22c55e":v>20?"#eab308":"#ef4444":"#808080",_=Math.max(0,(t.label_weight||0)-(t.weight_used||0))+m,N=p!==null?p-_:null,C=N!==null?Math.abs(N)<=50:null,k=async()=>{if(e!==null){l(!0);try{await zi.updateSpoolWeight(t.id,Math.round(e)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(P){console.error("Failed to sync weight:",P)}finally{l(!1)}}};return i.jsxs("div",{className:"flex flex-col items-center space-y-4 max-w-md",children:[i.jsxs("div",{className:"flex items-start gap-5",children:[i.jsxs("div",{className:"relative shrink-0",children:[i.jsx(O5,{color:u,isEmpty:!1,size:100}),v!==null&&i.jsxs("div",{className:"absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg",style:{backgroundColor:b},children:[v,"%"]})]}),i.jsxs("div",{className:"flex-1 min-w-0 pt-1",children:[i.jsx("h3",{className:"text-lg font-semibold text-zinc-100",children:t.color_name||"Unknown color"}),i.jsxs("p",{className:"text-sm text-zinc-400",children:[t.brand," • ",t.material,t.subtype&&` ${t.subtype}`]}),f!==null&&i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsxs("span",{className:"text-3xl font-bold font-mono text-zinc-100",children:[f,"g"]}),i.jsxs("span",{className:"text-sm text-zinc-500",children:["/ ",y,"g"]})]}),i.jsx("p",{className:"text-xs text-zinc-500 mt-0.5",children:s("spoolbuddy.spool.remaining","Remaining")}),i.jsx("div",{className:"mt-2 max-w-xs",children:i.jsx("div",{className:"h-2 bg-zinc-700 rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${v}%`,backgroundColor:b}})})})]})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.grossWeight","Gross weight")}),i.jsx("span",{className:"font-mono text-zinc-300",children:p!==null?`${p}g`:"—"})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.spool.coreWeight","Core")}),i.jsxs("span",{className:"font-mono text-zinc-300",children:[m,"g"]})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.spoolSize","Spool size")}),i.jsxs("span",{className:"font-mono text-zinc-300",children:[y,"g"]})]}),i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.spool.scaleWeight","Scale")}),p!==null?i.jsxs("span",{className:`flex items-center gap-1 font-mono ${C?"text-green-500":"text-yellow-500"}`,children:[p,"g",C?i.jsx(Zr,{className:"w-3.5 h-3.5"}):i.jsxs(i.Fragment,{children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsx("button",{onClick:k,className:"p-1 hover:bg-green-500/20 rounded transition-colors text-green-500",title:s("spoolbuddy.dashboard.syncWeight","Sync Weight"),children:i.jsx(vr,{className:"w-4 h-4"})})]})]}):i.jsx("span",{className:"text-zinc-500",children:"—"})]}),i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.tagId","Tag")}),i.jsx("span",{className:"font-mono text-xs text-zinc-400 truncate max-w-[120px]",title:t.tag_uid||"",children:t.tag_uid?t.tag_uid.slice(-8):"—"})]})]}),i.jsxs("div",{className:"flex gap-2 justify-center",children:[a&&i.jsx("button",{onClick:a,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:s("spoolbuddy.modal.assignToAms","Assign to AMS")}),i.jsx("button",{onClick:k,disabled:e===null||o,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${c?"bg-green-600/20 text-green-400":a?"bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed":"bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed"}`,children:o?"...":c?s("spoolbuddy.dashboard.weightSynced","Synced!"):s("spoolbuddy.dashboard.syncWeight","Sync Weight")}),n&&i.jsx("button",{onClick:n,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:s("spoolbuddy.dashboard.close","Close")})]})]})}function Hnt({tagUid:t,scaleWeight:e,coreWeight:n,onLinkSpool:r,onAddToInventory:a,onClose:s}){const{t:o}=jt(),l=n??yle(),c=e!==null?Math.round(Math.max(0,e)):null,d=c!==null?Math.round(Math.max(0,c-l)):null;return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-5",children:[i.jsx("div",{className:"w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center",children:i.jsx("svg",{className:"w-10 h-10 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z"})})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-zinc-100",children:o("spoolbuddy.dashboard.newTag","New Tag Detected")}),i.jsx("p",{className:"text-sm text-zinc-500 font-mono mt-1",children:t})]}),c!==null&&i.jsxs("div",{className:"text-sm text-zinc-400",children:[i.jsxs("span",{className:"font-mono font-semibold",children:[c,"g"]})," ",o("spoolbuddy.dashboard.onScale","on scale"),d!==null&&d>0&&i.jsxs("span",{className:"text-zinc-500",children:[" • ~",d,"g filament"]})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 justify-center",children:[a&&i.jsx("button",{onClick:a,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:o("spoolbuddy.modal.addToInventory","Add to Inventory")}),r&&i.jsxs("button",{onClick:r,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:[i.jsx("svg",{className:"w-4 h-4 inline-block mr-1.5 -mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),o("spoolbuddy.dashboard.linkSpool","Link to Spool")]}),s&&i.jsx("button",{onClick:s,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:o("spoolbuddy.dashboard.close","Close")})]})]})}function $nt(t){return t?`#${t.slice(0,6)}`:"#808080"}function vle(t){return!t.tray_type||t.tray_type===""}function qnt(t){return t<=3?`AMS ${String.fromCharCode(65+t)}`:t>=128&&t<=135?`AMS HT ${String.fromCharCode(65+t-128)}`:`AMS ${t}`}function Vnt({className:t}){return i.jsx("svg",{className:t,viewBox:"0 0 36 54",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{d:"M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z",fill:"#C3C2C1"})})}function Gnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 35 53",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z",fill:"#C3C2C1"}),i.jsx("path",{d:"M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z",fill:"#1F8FEB"})]})}function Wnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 36 54",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z",fill:"#1F8FEB"}),i.jsx("path",{d:"M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z",fill:"#C3C2C1"})]})}function Knt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"}),i.jsx("circle",{cx:"6",cy:"15",r:"2.5",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function Ynt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"4.5",y:"8",width:"3",height:"4.5",fill:"#d4a017",rx:"0.5"}),i.jsx("circle",{cx:"6",cy:"15",r:"2",fill:"#d4a017"}),i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function Xnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"4.5",y:"3",width:"3",height:"9.5",fill:"#c62828",rx:"0.5"}),i.jsx("circle",{cx:"6",cy:"15",r:"2",fill:"#c62828"}),i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function wle({humidity:t,goodThreshold:e=40,fairThreshold:n=60}){let r,a;return t<=e?(r="#22a352",a=Vnt):t<=n?(r="#d4a017",a=Gnt):(r="#c62828",a=Wnt),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx(a,{className:"w-3 h-3.5"}),i.jsxs("span",{className:"font-medium tabular-nums text-xs",style:{color:r},children:[t,"%"]})]})}function Sle({temp:t,goodThreshold:e=28,fairThreshold:n=35}){let r,a;return t<=e?(r="#22a352",a=Knt):t<=n?(r="#d4a017",a=Ynt):(r="#c62828",a=Xnt),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx(a,{className:"w-3 h-3.5"}),i.jsxs("span",{className:"font-medium tabular-nums text-xs",style:{color:r},children:[t,"°C"]})]})}function I5({side:t}){return i.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded",style:{backgroundColor:"#1a4d2e",color:"#00ae42"},children:t})}function Qnt({tray:t,slotIndex:e,isActive:n,fillOverride:r,spoolmanFill:a,onClick:s}){const o=vle(t),l=$nt(t.tray_color),c=t.remain!==null&&t.remain!==void 0&&t.remain>=0?t.remain:null,d=r===0&&c!==null&&c>0?null:r,u=a??d??c;return i.jsxs("div",{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?"ring-2 ring-bambu-green":""} ${s?"cursor-pointer hover:bg-white/5":""}`,onClick:s,children:[i.jsxs("div",{className:"relative w-16 h-16 mb-1",children:[o?i.jsx("div",{className:"w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center",children:i.jsx("div",{className:"w-3 h-3 rounded-full bg-gray-600"})}):i.jsxs("svg",{viewBox:"0 0 56 56",className:"w-full h-full",children:[i.jsx("circle",{cx:"28",cy:"28",r:"26",fill:l}),i.jsx("circle",{cx:"28",cy:"28",r:"20",fill:l,style:{filter:"brightness(0.85)"}}),i.jsx("ellipse",{cx:"20",cy:"20",rx:"6",ry:"4",fill:"white",opacity:"0.3"}),i.jsx("circle",{cx:"28",cy:"28",r:"8",fill:"#2d2d2d"}),i.jsx("circle",{cx:"28",cy:"28",r:"5",fill:"#1a1a1a"})]}),n&&i.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full"})]}),i.jsx("span",{className:"text-sm text-white/70 truncate max-w-full",children:o?"Empty":t.tray_type||"Unknown"}),!o&&u!==null&&u>=0&&i.jsx("div",{className:"w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1",children:i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${u}%`,backgroundColor:sx(u)}})}),i.jsx("span",{className:"absolute top-1 right-1 text-xs text-white/30",children:e+1})]})}function _le({unit:t,activeSlot:e,onConfigureSlot:n,isDualNozzle:r,nozzleSide:a,thresholds:s,fillOverrides:o,spoolmanFillOverrides:l}){const c=t.tray||[],d=t.is_ams_ht,u=d?1:4;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-white font-medium text-base",children:qnt(t.id)}),r&&a&&i.jsx(I5,{side:a})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.temp!=null&&i.jsx(Sle,{temp:t.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair}),t.humidity!=null&&i.jsx(wle,{humidity:t.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair})]})]}),i.jsx("div",{className:`grid ${d?"grid-cols-1 max-w-[100px] mx-auto":"grid-cols-4"} gap-2`,children:Array.from({length:u}).map((m,p)=>{const f=c[p]||{id:p,tray_color:null,tray_type:"",tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return i.jsx(Qnt,{tray:f,slotIndex:p,isActive:e===p,fillOverride:o?.[`${t.id}-${p}`]??null,spoolmanFill:l?.[`${t.id}-${p}`]??null,onClick:n?()=>n(t.id,p,vle(f)?null:f):void 0},p)})})]})}function s3(t){return t<=3?`AMS ${String.fromCharCode(65+t)}`:t>=128&&t<=135?`AMS HT ${String.fromCharCode(65+t-128)}`:`AMS ${t}`}function o3(t){return!t.tray_type||t.tray_type===""}function Znt(t){return t?`#${t.slice(0,6)}`:"#808080"}const tT=t=>(t??"").trim().toUpperCase();function Jnt(t,e){const n=tT(t),r=tT(e);return!n||!r?"none":n===r?"exact":r.includes(n)||n.includes(r)?"partial":"none"}function ert(t,e){const n=tT(t),r=tT(e);return!n||!r?!1:n===r}function trt({isOpen:t,onClose:e,spool:n,printerId:r}){const{t:a}=jt(),s=cn(),[o,l]=w.useState(null),[c,d]=w.useState(null),[u,m]=w.useState(!1),[p,f]=w.useState(null),[y,v]=w.useState(null);w.useEffect(()=>{t&&(l(null),d(null),m(!1),f(null),v(null))},[t]);const b=w.useCallback(Se=>{Se.key==="Escape"&&e()},[e]);w.useEffect(()=>(t&&document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)),[t,b]);const{data:g}=et({queryKey:["printerStatus",r],queryFn:()=>ge.getPrinterStatus(r),enabled:t&&r!==null,refetchInterval:5e3}),{data:_}=et({queryKey:["printer",r],queryFn:()=>ge.getPrinter(r),enabled:t&&r!==null}),{data:N}=et({queryKey:["settings"],queryFn:()=>ge.getSettings(),enabled:t,staleTime:300*1e3}),{data:C}=et({queryKey:["spool-assignments",r],queryFn:()=>ge.getAssignments(r),enabled:t&&r!==null,staleTime:30*1e3}),k=w.useMemo(()=>{const Se={};if(!C)return Se;for(const B of C){const X=B.spool;if(X&&X.label_weight>0&&X.weight_used!=null){const D=Math.round(Math.max(0,X.label_weight-X.weight_used)/X.label_weight*100);Se[`${B.ams_id}-${B.tray_id}`]=D}}return Se},[C]),P=N?{humidityGood:Number(N.ams_humidity_good)||40,humidityFair:Number(N.ams_humidity_fair)||60,tempGood:Number(N.ams_temp_good)||28,tempFair:Number(N.ams_temp_fair)||35}:void 0,A=g?.connected??!1,j=w.useMemo(()=>g?.ams??[],[g?.ams]),T=w.useMemo(()=>j.filter(Se=>!Se.is_ams_ht),[j]),F=w.useMemo(()=>j.filter(Se=>Se.is_ams_ht),[j]),G=w.useMemo(()=>[...g?.vt_tray??[]].sort((Se,B)=>(Se.id??254)-(B.id??254)),[g?.vt_tray]),z=_?.nozzle_count===2||g?.temperatures?.nozzle_2!==void 0,J=w.useRef({});w.useEffect(()=>{g?.ams_extruder_map&&Object.keys(g.ams_extruder_map).length>0&&(J.current=g.ams_extruder_map)},[g?.ams_extruder_map]);const I=g?.ams_extruder_map&&Object.keys(g.ams_extruder_map).length>0?g.ams_extruder_map:J.current,te=w.useCallback(Se=>{if(!z)return null;const B=I[String(Se)],X=Se>=128?Se-128:Se;return(B!==void 0?B:X)===1?"L":"R"},[z,I]),ae=ht({mutationFn:async({amsId:Se,trayId:B})=>{if(!r)throw new Error("No printer selected");await ge.assignSpool({spool_id:n.id,printer_id:r,ams_id:Se,tray_id:B})},onSuccess:()=>{d("success"),l(a("spoolbuddy.modal.assignSuccess","Assigned!")),s.invalidateQueries({queryKey:["slotPresets"]}),setTimeout(()=>e(),1500)},onError:Se=>{d("error"),l(Se instanceof Error?Se.message:a("spoolbuddy.modal.assignError","Failed to assign spool."))}}),Z=ae.isPending,de=w.useCallback((Se,B)=>{if(Se===254||Se===255){const D=Se===254?254:254+B;return G.find(M=>(M.id??254)===D)||null}return j.find(D=>D.id===Se)?.tray?.find(D=>D.id===B)||null},[j,G]),ue=w.useCallback((Se,B)=>Se<=3?`${s3(Se)} ${a("ams.slot","Slot")} ${B+1}`:Se>=128&&Se<=135?s3(Se):Se===254?a("printers.extL","Ext-L"):z?a("printers.extR","Ext-R"):a("printers.ext","Ext"),[a,z]),he=w.useCallback((Se,B)=>{d("info"),l(a("spoolbuddy.modal.assigning","Configuring slot...")),ae.mutate({amsId:Se,trayId:B})},[ae,a]),K=w.useCallback((Se,B)=>{if(!Z){if(!N?.disable_filament_warnings){const X=de(Se,B);if(X&&!o3(X)){const D=X.tray_sub_brands||X.tray_type||"",M=Jnt(n.material,D),U=n.slicer_filament_name||n.slicer_filament,W=X.tray_type||"",H=ert(U,W);if(M!=="exact"||!H){let re="profile";M==="none"&&!H?re="material_profile":M==="partial"&&!H?re="partial_profile":M==="none"?re="material":M==="partial"&&(re="partial");const O=ue(Se,B);v({amsId:Se,trayId:B}),f({type:re,spoolMaterial:n.material||"",trayMaterial:D||"",spoolProfile:U||void 0,trayProfile:W||void 0,location:O}),m(!0);return}}}he(Se,B)}},[Z,N?.disable_filament_warnings,n,de,ue,he]),se=w.useCallback(()=>{y&&(m(!1),f(null),he(y.amsId,y.trayId),v(null))},[y,he]),ce=w.useMemo(()=>{const Se=[];for(const B of F){const X=B.tray?.[0]||{id:0,tray_color:null,tray_type:"",tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},D=k[`${B.id}-0`]??null,M=X.remain!=null&&X.remain>=0?X.remain:null,U=D===0&&M!==null&&M>0?null:D;Se.push({key:`ht-${B.id}`,label:s3(B.id),amsId:B.id,trayId:0,tray:X,isEmpty:o3(X),nozzleSide:te(B.id),effectiveFill:U??M})}for(const B of G){const X=B.id??254,D=X-254,M=k[`255-${D}`]??null,U=B.remain!=null&&B.remain>=0?B.remain:null,W=M===0&&U!==null&&U>0?null:M;Se.push({key:`ext-${X}`,label:z?X===254?a("printers.extL","Ext-L"):a("printers.extR","Ext-R"):a("printers.ext","Ext"),amsId:255,trayId:D,tray:B,isEmpty:o3(B),nozzleSide:z?X===254?"L":"R":null,effectiveFill:W??U})}return Se},[F,G,z,a,te,k]);if(!t)return null;const pe=n.rgba?`#${n.rgba.slice(0,6)}`:"#808080";return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"fixed inset-0 z-[60] bg-bambu-dark flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("div",{className:"w-7 h-7 rounded-full shrink-0",style:{backgroundColor:pe}}),i.jsx("div",{className:"min-w-0",children:i.jsxs("h2",{className:"text-sm font-semibold text-zinc-100 truncate",children:[a("spoolbuddy.modal.assignToAmsTitle","Assign to AMS"),i.jsxs("span",{className:"font-normal text-zinc-500 ml-2",children:[n.color_name||"Unknown"," • ",n.brand," ",n.material,n.subtype&&` ${n.subtype}`]})]})})]}),i.jsx("button",{onClick:e,disabled:Z,className:"p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50",children:i.jsx(qt,{className:"w-5 h-5"})})]}),o&&i.jsxs("div",{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${c==="info"?"bg-blue-500/10 border-blue-500/40":c==="success"?"bg-green-500/10 border-green-500/40":"bg-red-500/10 border-red-500/40"}`,children:[c==="info"&&i.jsx(ft,{className:"w-4 h-4 text-blue-400 animate-spin shrink-0"}),c==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-400 shrink-0"}),c==="error"&&i.jsx(Wi,{className:"w-4 h-4 text-red-400 shrink-0"}),i.jsx("span",{className:`text-sm ${c==="info"?"text-blue-300":c==="success"?"text-green-300":"text-red-300"}`,children:o})]}),i.jsx("div",{className:"flex-1 flex flex-col gap-3 p-4 min-h-0",children:!A&&r?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsx("div",{className:"text-center text-white/50",children:i.jsx("p",{className:"text-lg mb-2",children:a("spoolbuddy.ams.printerDisconnected","Printer disconnected")})})}):j.length===0&&G.length===0?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"text-center text-white/50",children:[i.jsx(Ki,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-lg mb-2",children:a("spoolbuddy.ams.noData","No AMS detected")}),i.jsx("p",{className:"text-sm",children:a("spoolbuddy.ams.connectAms","Connect an AMS to see filament slots")})]})}):i.jsxs(i.Fragment,{children:[T.length>0&&i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0",children:T.map(Se=>i.jsx(_le,{unit:Se,activeSlot:null,onConfigureSlot:(B,X)=>K(Se.id,X),isDualNozzle:z,nozzleSide:te(Se.id),thresholds:P,fillOverrides:k},Se.id))}),ce.length>0&&i.jsx("div",{className:"flex gap-2 shrink-0",children:ce.map(({key:Se,label:B,amsId:X,trayId:D,tray:M,isEmpty:U,nozzleSide:W,effectiveFill:H})=>{const re=Znt(M.tray_color);return i.jsxs("div",{onClick:()=>K(X,D),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${Z?"opacity-50 pointer-events-none":""}`,children:[i.jsx("div",{className:"relative w-10 h-10 shrink-0",children:U?i.jsx("div",{className:"w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center",children:i.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-gray-600"})}):i.jsxs("svg",{viewBox:"0 0 56 56",className:"w-full h-full",children:[i.jsx("circle",{cx:"28",cy:"28",r:"26",fill:re}),i.jsx("circle",{cx:"28",cy:"28",r:"20",fill:re,style:{filter:"brightness(0.85)"}}),i.jsx("ellipse",{cx:"20",cy:"20",rx:"6",ry:"4",fill:"white",opacity:"0.3"}),i.jsx("circle",{cx:"28",cy:"28",r:"8",fill:"#2d2d2d"}),i.jsx("circle",{cx:"28",cy:"28",r:"5",fill:"#1a1a1a"})]})}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"text-xs text-white/50 font-medium",children:B}),W&&i.jsx(I5,{side:W})]}),i.jsx("div",{className:"text-sm text-white/80 truncate",children:U?"Empty":M.tray_type||"?"})]}),!U&&H!=null&&H>=0&&i.jsx("div",{className:"w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse",children:i.jsx("div",{className:"w-full rounded-full",style:{height:`${H}%`,backgroundColor:sx(H)}})})]},Se)})})]})}),i.jsx("div",{className:"flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0",children:i.jsx("button",{onClick:e,disabled:Z,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50",children:c==="success"?a("spoolbuddy.dashboard.close","Close"):a("spoolbuddy.modal.cancel","Cancel")})})]}),u&&p&&(()=>{let Se="";return p.type==="material"?Se=a("inventory.assignMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type==="partial"?Se=a("inventory.assignPartialMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type==="material_profile"?Se=`${a("inventory.assignMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})} +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function Z(B,X){(X==null||X>B.length)&&(X=B.length);for(var D=0,M=Array(X);D1&&arguments[1]!==void 0?arguments[1]:M;this.caretPosition=M,this.caretPositionEnd=U}},{key:"getInputCandidates",value:function(M){var U=this,W=this.options,H=W.layoutCandidates,re=W.layoutCandidatesCaseSensitiveMatch;if(!H||de(H)!=="object")return{};var O=Object.keys(H).filter((function(V){var ee=M.substring(0,U.getCaretPositionEnd()||0)||M,oe=new RegExp("".concat(U.utilities.escapeRegex(V),"$"),re?"g":"gi");return!!ae(ee.matchAll(oe)).length}));if(O.length>1){var q=O.sort((function(V,ee){return ee.length-V.length}))[0];return{candidateKey:q,candidateValue:H[q]}}if(O.length){var Y=O[0];return{candidateKey:Y,candidateValue:H[Y]}}return{}}},{key:"showCandidatesBox",value:function(M,U,W){var H=this;this.candidateBox&&this.candidateBox.show({candidateValue:U,targetElement:W,onSelect:function(re,O){var q=H.options,Y=q.layoutCandidatesCaseSensitiveMatch,V=q.disableCandidateNormalization,ee=q.enableLayoutCandidatesKeyPress,oe=re;V||(oe=re.normalize("NFD")),typeof H.options.beforeInputUpdate=="function"&&H.options.beforeInputUpdate(H);var me=H.getInput(H.options.inputName,!0),fe=H.getCaretPositionEnd()||0,ie=me.substring(0,fe||0)||me,L=new RegExp("".concat(H.utilities.escapeRegex(M),"$"),Y?"g":"gi"),R=ie.replace(L,oe),ne=me.replace(ie,R),ye=R.length-ie.length,ve=(fe||me.length)+ye;ve<0&&(ve=0),H.setInput(ne,H.options.inputName,!0),H.setCaretPosition(ve),ee&&typeof H.options.onKeyPress=="function"&&H.options.onKeyPress(re,O),typeof H.options.onChange=="function"&&H.options.onChange(H.getInput(H.options.inputName,!0),O),typeof H.options.onChangeAll=="function"&&H.options.onChangeAll(H.getAllInputs(),O)}})}},{key:"handleButtonClicked",value:function(M,U){var W=this.options,H=W.inputName,re=H===void 0?this.defaultName:H,O=W.debug;if(M!=="{//}"){this.input[re]||(this.input[re]=""),typeof this.options.beforeInputUpdate=="function"&&this.options.beforeInputUpdate(this);var q=this.utilities.getUpdatedInput(M,this.input[re],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(M)&&this.activeInputElement&&this.input[re]&&this.input[re]===q&&this.caretPosition===0&&this.caretPositionEnd===q.length)return this.setInput("",this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value="",this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(M,U);if(typeof this.options.onKeyPress=="function"&&this.options.onKeyPress(M,U),this.input[re]!==q&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(q))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,q))return;var Y=this.utilities.getUpdatedInput(M,this.input[re],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(Y,this.options.inputName,!0),O&&console.log("Input changed:",this.getAllInputs()),this.options.debug&&console.log("Caret at: ",this.getCaretPosition(),this.getCaretPositionEnd(),"(".concat(this.keyboardDOMClass,")"),U?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange=="function"&&this.options.onChange(this.getInput(this.options.inputName,!0),U),typeof this.options.onChangeAll=="function"&&this.options.onChangeAll(this.getAllInputs(),U),U!=null&&U.target&&this.options.enableLayoutCandidates){var V,ee=this.getInputCandidates(q),oe=ee.candidateKey,me=ee.candidateValue;oe&&me?this.showCandidatesBox(oe,me,this.keyboardDOM):(V=this.candidateBox)===null||V===void 0||V.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log("Caret position aligned",this.caretPosition)),O&&console.log("Key pressed:",M)}}},{key:"getMouseHold",value:function(){return this.isMouseHold}},{key:"setMouseHold",value:function(M){this.options.syncInstanceInputs?this.dispatch((function(U){U.isMouseHold=M})):this.isMouseHold=M}},{key:"handleButtonMouseDown",value:function(M,U){var W=this;U&&(this.options.preventMouseDownDefault&&U.preventDefault(),this.options.stopMouseDownPropagation&&U.stopPropagation(),U.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(W.getMouseHold()&&(!M.includes("{")&&!M.includes("}")||M==="{delete}"||M==="{backspace}"||M==="{bksp}"||M==="{space}"||M==="{tab}")||M==="{arrowright}"||M==="{arrowleft}"||M==="{arrowup}"||M==="{arrowdown}")&&(W.options.debug&&console.log("Button held:",M),W.handleButtonHold(M)),clearTimeout(W.holdTimeout)}),500))}},{key:"handleButtonMouseUp",value:function(M,U){var W=this;U&&(this.options.preventMouseUpDefault&&U.preventDefault&&U.preventDefault(),this.options.stopMouseUpPropagation&&U.stopPropagation&&U.stopPropagation(),!(U.target===this.keyboardDOM||U.target&&this.keyboardDOM.contains(U.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(U.target===this.candidateBox.candidateBoxElement||U.target&&this.candidateBox.candidateBoxElement.contains(U.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(H){H.classList.remove(W.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),M&&typeof this.options.onKeyReleased=="function"&&this.options.onKeyReleased(M,U)}},{key:"handleKeyboardContainerMouseDown",value:function(M){this.options.preventMouseDownDefault&&M.preventDefault()}},{key:"handleButtonHold",value:function(M){var U=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){U.getMouseHold()?(U.handleButtonClicked(M),U.handleButtonHold(M)):clearTimeout(U.holdInteractionTimeout)}),100)}},{key:"syncInstanceInputs",value:function(){var M=this;this.dispatch((function(U){U.replaceInput(M.input),U.setCaretPosition(M.caretPosition,M.caretPositionEnd)}))}},{key:"clearInput",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[M]="",this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"getInput",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,U=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!U&&this.syncInstanceInputs(),this.options.rtl?"‫"+this.input[M].replace("‫","").replace("‬","")+"‬":this.input[M]}},{key:"getAllInputs",value:function(){var M=this,U={};return Object.keys(this.input).forEach((function(W){U[W]=M.getInput(W,!0)})),U}},{key:"setInput",value:function(M){var U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,W=arguments.length>2?arguments[2]:void 0;this.input[U]=M,!W&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:"replaceInput",value:function(M){this.input=M}},{key:"setOptions",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},U=this.changedOptions(M);this.options=Object.assign(this.options,M),U.length&&(this.options.debug&&console.log("changedOptions",U),this.onSetOptions(U),this.render())}},{key:"changedOptions",value:function(M){var U=this;return Object.keys(M).filter((function(W){return JSON.stringify(M[W])!==JSON.stringify(U.options[W])}))}},{key:"onSetOptions",value:function(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];M.includes("layoutName")&&this.candidateBox&&this.candidateBox.destroy(),(M.includes("layoutCandidatesPageSize")||M.includes("layoutCandidates"))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new te({utilities:this.utilities,options:this.options}))}},{key:"resetRows",value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute("data-skInstance",this.currentInstanceName),this.buttonElements={}}},{key:"dispatch",value:function(M){if(!window.SimpleKeyboardInstances)throw console.warn("SimpleKeyboardInstances is not defined. Dispatch cannot be called."),new Error("INSTANCES_VAR_ERROR");return Object.keys(window.SimpleKeyboardInstances).forEach((function(U){M(window.SimpleKeyboardInstances[U],U)}))}},{key:"addButtonTheme",value:function(M,U){var W=this;U&&M&&(M.split(" ").forEach((function(H){U.split(" ").forEach((function(re){W.options.buttonTheme||(W.options.buttonTheme=[]);var O=!1;W.options.buttonTheme.map((function(q){if(q!=null&&q.class.split(" ").includes(re)){O=!0;var Y=q.buttons.split(" ");Y.includes(H)||(O=!0,Y.push(H),q.buttons=Y.join(" "))}return q})),O||W.options.buttonTheme.push({class:re,buttons:M})}))})),this.render())}},{key:"removeButtonTheme",value:function(M,U){var W=this;if(!M&&!U)return this.options.buttonTheme=[],void this.render();M&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(M.split(" ").forEach((function(H){var re;(re=W.options)===null||re===void 0||(re=re.buttonTheme)===null||re===void 0||re.map((function(O,q){if(O&&U&&U.includes(O.class)||!U){var Y,V,ee=(Y=O)===null||Y===void 0?void 0:Y.buttons.split(" ").filter((function(oe){return oe!==H}));O&&ee!=null&&ee.length?O.buttons=ee.join(" "):((V=W.options.buttonTheme)===null||V===void 0||V.splice(q,1),O=null)}return O}))})),this.render())}},{key:"getButtonElement",value:function(M){var U,W=this.buttonElements[M];return W&&(U=W.length>1?W:W[0]),U}},{key:"inputPatternIsValid",value:function(M){var U,W=this.options.inputPattern;if((U=W instanceof RegExp?W:W[this.options.inputName||this.defaultName])&&M){var H=U.test(M);return this.options.debug&&console.log('inputPattern ("'.concat(U,'"): ').concat(H?"passed":"did not pass!")),H}return!0}},{key:"setEventListeners",value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log("Caret handling started (".concat(this.keyboardDOMClass,")"));var M=this.options.physicalKeyboardHighlightPreventDefault,U=M!==void 0&&M;document.addEventListener("keyup",this.handleKeyUp,U),document.addEventListener("keydown",this.handleKeyDown,U),document.addEventListener("mouseup",this.handleMouseUp),document.addEventListener("touchend",this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener("selectionchange",this.handleSelectionChange),document.addEventListener("select",this.handleSelect)}}},{key:"handleKeyUp",value:function(M){this.caretEventHandler(M),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(M)}},{key:"handleKeyDown",value:function(M){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(M)}},{key:"handleMouseUp",value:function(M){this.caretEventHandler(M)}},{key:"handleTouchEnd",value:function(M){this.caretEventHandler(M)}},{key:"handleSelect",value:function(M){this.caretEventHandler(M)}},{key:"handleSelectionChange",value:function(M){navigator.userAgent.includes("Firefox")||this.caretEventHandler(M)}},{key:"caretEventHandler",value:function(M){var U,W=this;M.target.tagName&&(U=M.target.tagName.toLowerCase()),this.dispatch((function(H){var re=M.target===H.keyboardDOM||M.target&&H.keyboardDOM.contains(M.target);if(W.options.syncInstanceInputs&&Array.isArray(M.path)&&(re=M.path.some((function(Y){var V;return Y==null||(V=Y.hasAttribute)===null||V===void 0?void 0:V.call(Y,"data-skInstance")}))),(U==="textarea"||U==="input"&&["text","search","url","tel","password"].includes(M.target.type))&&!H.options.disableCaretPositioning){var O=M.target.selectionStart,q=M.target.selectionEnd;H.options.rtl&&(O=H.utilities.getRtlOffset(O,H.getInput()),q=H.utilities.getRtlOffset(q,H.getInput())),H.setCaretPosition(O,q),H.activeInputElement=M.target,H.options.debug&&console.log("Caret at: ",H.getCaretPosition(),H.getCaretPositionEnd(),M&&M.target.tagName.toLowerCase(),"(".concat(H.keyboardDOMClass,")"),M?.type)}else!H.options.disableCaretPositioning&&re||M?.type==="selectionchange"||(H.setCaretPosition(null),H.activeInputElement=null,H.options.debug&&console.log('Caret position reset due to "'.concat(M?.type,'" event'),M))}))}},{key:"recurseButtons",value:function(M){var U=this;M&&Object.keys(this.buttonElements).forEach((function(W){return U.buttonElements[W].forEach(M)}))}},{key:"destroy",value:function(){this.options.debug&&console.log("Destroying simple-keyboard instance: ".concat(this.currentInstanceName));var M=this.options.physicalKeyboardHighlightPreventDefault,U=M!==void 0&&M;document.removeEventListener("keyup",this.handleKeyUp,U),document.removeEventListener("keydown",this.handleKeyDown,U),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("touchend",this.handleTouchEnd),document.removeEventListener("select",this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener("selectionchange",this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(W){W&&(W.onpointerdown=null,W.onpointerup=null,W.onpointercancel=null,W.ontouchstart=null,W.ontouchend=null,W.ontouchcancel=null,W.onclick=null,W.onmousedown=null,W.onmouseup=null,W.remove(),W=null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=null),this.activeInputElement=null,this.keyboardDOM.removeAttribute("data-skInstance"),this.keyboardDOM.innerHTML="",window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:"getButtonThemeClasses",value:function(M){var U=this.options.buttonTheme,W=[];return Array.isArray(U)&&U.forEach((function(H){if(H&&H.class&&typeof H.class=="string"&&H.buttons&&typeof H.buttons=="string"){var re=H.class.split(" ");H.buttons.split(" ").includes(M)&&(W=[].concat(ae(W),ae(re)))}else console.warn('Incorrect "buttonTheme". Please check the documentation.',H)})),W}},{key:"setDOMButtonAttributes",value:function(M,U){var W=this.options.buttonAttributes;Array.isArray(W)&&W.forEach((function(H){H.attribute&&typeof H.attribute=="string"&&H.value&&typeof H.value=="string"?H.buttons&&typeof H.buttons=="string"?H.buttons.split(" ").includes(M)&&U(H.attribute,H.value):U(H.attribute,H.value):console.warn('Incorrect "buttonAttributes". Please check the documentation.',H)}))}},{key:"onTouchDeviceDetected",value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:"disableContextualWindow",value:function(){window.oncontextmenu=function(M){var U;if((U=M.target.classList)!==null&&U!==void 0&&U.contains("hg-button"))return M.preventDefault(),M.stopPropagation(),!1}}},{key:"processAutoTouchEvents",value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log("autoUseTouchEvents: Touch device detected, useTouchEvents enabled."))}},{key:"onInit",value:function(){this.options.debug&&console.log("".concat(this.keyboardDOMClass," Initialized")),this.setEventListeners(),typeof this.options.onInit=="function"&&this.options.onInit(this)}},{key:"beforeFirstRender",value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender=="function"&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log("Using PointerEvents as it is supported by this browser"),this.options.useTouchEvents&&this.options.debug&&console.log("useTouchEvents has been enabled. Only touch events will be used.")}},{key:"beforeRender",value:function(){typeof this.options.beforeRender=="function"&&this.options.beforeRender(this)}},{key:"onRender",value:function(){typeof this.options.onRender=="function"&&this.options.onRender(this)}},{key:"onModulesLoaded",value:function(){typeof this.options.onModulesLoaded=="function"&&this.options.onModulesLoaded(this)}},{key:"loadModules",value:function(){var M=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(U){var W=M.utilities.isConstructor(U)?new U(M):U(M);W.init&&W.init(M)})),this.keyboardPluginClasses="modules-loaded",this.render(),this.onModulesLoaded())}},{key:"getModuleProp",value:function(M,U){return!!this.modules[M]&&this.modules[M][U]}},{key:"getModulesList",value:function(){return Object.keys(this.modules)}},{key:"parseRowDOMContainers",value:function(M,U,W,H){var re=this,O=Array.from(M.children),q=0;return O.length&&W.forEach((function(Y,V){var ee=H[V];if(!(ee&&ee>Y))return!1;var oe=Y-q,me=ee-q,fe=document.createElement("div");fe.className+="hg-button-container";var ie="".concat(re.options.layoutName,"-r").concat(U,"c").concat(V);fe.setAttribute("data-skUID",ie);var L=O.splice(oe,me-oe+1);q+=me-oe,L.forEach((function(R){return fe.appendChild(R)})),O.splice(oe,0,fe),M.innerHTML="",O.forEach((function(R){return M.appendChild(R)})),re.options.debug&&console.log("rowDOMContainer",L,oe,me,q+1)})),M}},{key:"render",value:function(){var M=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var U="hg-layout-".concat(this.options.layoutName),W=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p [ ] \\","{lock} a s d f g h j k l ; ' {enter}","{shift} z x c v b n m , . / {shift}",".com @ {space}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W E R T Y U I O P { } |",'{lock} A S D F G H J K L : " {enter}',"{shift} Z X C V B N M < > ? {shift}",".com @ {space}"]},H=this.options.useTouchEvents||!1,re=H?"hg-touch-events":"",O=this.options.useMouseEvents||!1,q=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,U,this.keyboardPluginClasses,re),this.keyboardDOM.setAttribute("data-skInstance",this.currentInstanceName),this.keyboardRowsDOM=document.createElement("div"),this.keyboardRowsDOM.className="hg-rows",W[this.options.layoutName||this.defaultName].forEach((function(Y,V){var ee=Y.split(" ");M.options.excludeFromLayout&&M.options.excludeFromLayout[M.options.layoutName||M.defaultName]&&(ee=ee.filter((function(ie){return M.options.excludeFromLayout&&!M.options.excludeFromLayout[M.options.layoutName||M.defaultName].includes(ie)})));var oe=document.createElement("div");oe.className+="hg-row";var me=[],fe=[];ee.forEach((function(ie,L){var R,ne=!q&&typeof ie=="string"&&ie.length>1&&ie.indexOf("[")===0,ye=!q&&typeof ie=="string"&&ie.length>1&&ie.indexOf("]")===ie.length-1;ne&&(me.push(L),ie=ie.replace(/\[/g,"")),ye&&(fe.push(L),ie=ie.replace(/\]/g,""));var ve=M.utilities.getButtonClass(ie),be=M.utilities.getButtonDisplayName(ie,M.options.display,M.options.mergeDisplay),Be=M.options.useButtonTag?"button":"div",we=document.createElement(Be);we.className+="hg-button ".concat(ve),(R=we.classList).add.apply(R,ae(M.getButtonThemeClasses(ie))),M.setDOMButtonAttributes(ie,(function(Ee,Ne){we.setAttribute(Ee,Ne)})),M.activeButtonClass="hg-activeButton",!M.utilities.pointerEventsSupported()||H||O?H?(we.ontouchstart=function(Ee){M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.ontouchend=function(Ee){M.handleButtonMouseUp(ie,Ee)},we.ontouchcancel=function(Ee){M.handleButtonMouseUp(ie,Ee)}):(we.onclick=function(Ee){M.setMouseHold(!1),typeof M.options.onKeyReleased=="function"||M.options.useMouseEvents&&M.options.clickOnMouseDown||M.handleButtonClicked(ie,Ee)},we.onmousedown=function(Ee){(typeof M.options.onKeyReleased=="function"||M.options.useMouseEvents&&M.options.clickOnMouseDown)&&!M.isMouseHold&&M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.onmouseup=function(Ee){M.handleButtonMouseUp(ie,Ee)}):(we.onpointerdown=function(Ee){M.handleButtonClicked(ie,Ee),M.handleButtonMouseDown(ie,Ee)},we.onpointerup=function(Ee){M.handleButtonMouseUp(ie,Ee)},we.onpointercancel=function(Ee){M.handleButtonMouseUp(ie,Ee)}),we.setAttribute("data-skBtn",ie);var Ae="".concat(M.options.layoutName,"-r").concat(V,"b").concat(L);we.setAttribute("data-skBtnUID",Ae);var Le=document.createElement("span");Le.innerHTML=be,we.appendChild(Le),M.buttonElements[ie]||(M.buttonElements[ie]=[]),M.buttonElements[ie].push(we),oe.appendChild(we)})),oe=M.parseRowDOMContainers(oe,V,me,fe),M.keyboardRowsDOM.appendChild(oe)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||H||O?H?(document.ontouchend=function(Y){return M.handleButtonMouseUp(void 0,Y)},document.ontouchcancel=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.ontouchstart=function(Y){return M.handleKeyboardContainerMouseDown(Y)}):H||(document.onmouseup=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.onmousedown=function(Y){return M.handleKeyboardContainerMouseDown(Y)}):(document.onpointerup=function(Y){return M.handleButtonMouseUp(void 0,Y)},this.keyboardDOM.onpointerdown=function(Y){return M.handleKeyboardContainerMouseDown(Y)}),this.onInit())}}],X&&he(B.prototype,X),D&&he(B,D),Object.defineProperty(B,"prototype",{writable:!1}),B;var B,X,D})(),pe=ce,Se=pe;return m})()},442:function(l){l.exports=n}},a={};function s(l){var c=a[l];if(c!==void 0)return c.exports;var d=a[l]={exports:{}};return r[l].call(d.exports,d,d.exports,s),d.exports}s.n=function(l){var c=l&&l.__esModule?function(){return l.default}:function(){return l};return s.d(c,{a:c}),c},s.d=function(l,c){for(var d in c)s.o(c,d)&&!s.o(l,d)&&Object.defineProperty(l,d,{enumerable:!0,get:c[d]})},s.o=function(l,c){return Object.prototype.hasOwnProperty.call(l,c)},s.r=function(l){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(l,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(l,"__esModule",{value:!0})};var o={};return(function(){s.r(o),s.d(o,{KeyboardReact:function(){return v},default:function(){return b}}),s(981);var l=s(442),c=s(548),d=s.n(c);function u(g){return u=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(_){return typeof _}:function(_){return _&&typeof Symbol=="function"&&_.constructor===Symbol&&_!==Symbol.prototype?"symbol":typeof _},u(g)}function m(g,_){var N=Object.keys(g);if(Object.getOwnPropertySymbols){var C=Object.getOwnPropertySymbols(g);_&&(C=C.filter((function(k){return Object.getOwnPropertyDescriptor(g,k).enumerable}))),N.push.apply(N,C)}return N}function p(g){for(var _=1;_{let _=g.parentElement;for(;_;){const N=getComputedStyle(_);if(N.overflowY==="auto"||N.overflowY==="scroll")break;_=_.parentElement}_&&(u.current=_,_.style.paddingBottom="280px")},[]),p=w.useCallback(()=>{u.current&&(u.current.style.paddingBottom="",u.current=null)},[]),f=w.useCallback(g=>{if(a.current)return;const _=g.target;if(!_.closest('[data-vkb="false"]')){if(_ instanceof HTMLInputElement){if(!Ont.has(_.type))return}else if(!(_ instanceof HTMLTextAreaElement))return;l.current=_,e(!0),o("default"),c.current?.setInput?.(l.current.value),m(_),setTimeout(()=>{_.scrollIntoView({behavior:"smooth",block:"center"})},100)}},[m]),y=w.useCallback(()=>{setTimeout(()=>{const g=document.activeElement;g&&(d.current?.contains(g)||g===l.current)||(p(),e(!1),l.current=null)},150)},[p]);w.useEffect(()=>(document.addEventListener("focusin",f),document.addEventListener("focusout",y),()=>{document.removeEventListener("focusin",f),document.removeEventListener("focusout",y)}),[f,y]);const v=w.useCallback(()=>{a.current=!0,r(!0),p(),l.current?.blur(),l.current=null,setTimeout(()=>{e(!1),r(!1),a.current=!1},400)},[p]),b=w.useCallback(g=>{const _=l.current;if(_){if(g==="{shift}"){o(N=>N==="default"?"shift":"default");return}if(g==="{lock}"){o(N=>N==="default"?"shift":"default");return}if(g==="{close}"){v();return}g==="{bksp}"?a3(_,_.value.slice(0,-1)):g==="{space}"?a3(_,_.value+" "):(a3(_,_.value+g),s==="shift"&&o("default")),_.focus(),c.current?.setInput?.(_.value)}},[s,v]);return t?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-[9998] bg-transparent",onMouseDown:g=>{g.preventDefault(),g.stopPropagation(),n||v()},onTouchStart:g=>{g.preventDefault(),g.stopPropagation(),n||v()},onClick:g=>{g.preventDefault(),g.stopPropagation()}}),!n&&i.jsx("div",{ref:d,className:"fixed bottom-0 left-0 right-0 z-[9999]",onMouseDown:g=>g.preventDefault(),onTouchStart:g=>{g.target.closest(".hg-button")||g.preventDefault()},children:i.jsx(Lnt,{keyboardRef:g=>{c.current=g},layoutName:s,onKeyPress:b,theme:"simple-keyboard vkb-theme",layout:{default:["1 2 3 4 5 6 7 8 9 0 {bksp}","q w e r t y u i o p","{lock} a s d f g h j k l","{shift} z x c v b n m . @","{space} {close}"],shift:["! @ # $ % ^ & * ( ) {bksp}","Q W E R T Y U I O P","{lock} A S D F G H J K L","{shift} Z X C V B N M , _","{space} {close}"]},display:{"{bksp}":"⌫","{close}":"✕ Close","{shift}":"⇧","{lock}":"⇪","{space}":" "}})})]}):null}function znt(){const[t,e]=w.useState(null),[n,r]=w.useState(null),[a,s]=w.useState(!1),[o,l]=w.useState(100),[c,d]=w.useState(0),u=w.useRef(Date.now()),{i18n:m}=jt(),p=Po(),f=Fc(),y=jnt(),{data:v}=et({queryKey:["settings"],queryFn:ge.getSettings});w.useEffect(()=>{v?.language&&v.language!==m.language&&m.changeLanguage(v.language)},[v?.language,m]);const{data:b=[]}=et({queryKey:["spoolbuddy-devices"],queryFn:()=>zi.getDevices(),refetchInterval:3e4}),g=b[0],_=y.deviceOnline||!!g?.online,N=w.useMemo(()=>({...y,deviceOnline:_}),[y,_]),C=w.useRef(!1);w.useEffect(()=>{g&&!C.current&&(l(g.display_brightness),d(g.display_blank_timeout),C.current=!0)},[g]),w.useEffect(()=>{const ue=document.documentElement,he=ue.classList.contains("dark");return ue.classList.add("dark"),()=>{he||ue.classList.remove("dark")}},[]);const{data:k}=et({queryKey:["spoolbuddy-update-check",g?.device_id],queryFn:()=>g?zi.checkDaemonUpdate(g.device_id):Promise.resolve(null),enabled:!!g,refetchInterval:300*1e3,staleTime:0});w.useEffect(()=>{_?k?.update_available&&k.latest_version?r({type:"info",message:`Update available: v${k.latest_version}`}):r(null):r({type:"warning",message:"SpoolBuddy device disconnected"})},[_,k?.update_available,k?.latest_version]);const P=w.useCallback(()=>{u.current=Date.now(),s(!1)},[]);w.useEffect(()=>(window.addEventListener("pointerdown",P),window.addEventListener("keydown",P),()=>{window.removeEventListener("pointerdown",P),window.removeEventListener("keydown",P)}),[P]);const A=!!(y.matchedSpool||y.unknownTagUid),j=w.useRef(!1);w.useEffect(()=>{A&&!j.current&&(P(),f.pathname!=="/spoolbuddy"&&p("/spoolbuddy")),j.current=A},[A,f.pathname,p,P]),w.useEffect(()=>{if(c<=0)return;const ue=setInterval(()=>{Date.now()-u.current>=c*1e3&&s(!0)},1e3);return()=>clearInterval(ue)},[c]);const{data:T=[]}=et({queryKey:["printers"],queryFn:()=>ge.getPrinters()}),F=Jh({queries:T.map(ue=>({queryKey:["printerStatus",ue.id],queryFn:()=>ge.getPrinterStatus(ue.id),refetchInterval:1e4}))}),G=w.useMemo(()=>T.filter((ue,he)=>F[he]?.data?.connected),[T,F]),z=w.useRef(null),J=w.useRef(!1),I=50,te=w.useRef(null),ae=w.useCallback(ue=>{z.current={x:ue.touches[0].clientX,y:ue.touches[0].clientY},J.current=!1},[]),Z=w.useCallback(ue=>{if(!z.current||G.length<2)return;const he=ue.changedTouches[0].clientX-z.current.x,K=ue.changedTouches[0].clientY-z.current.y;if(z.current=null,J.current=!1,Math.abs(he)Math.abs(he))return;const se=G.findIndex(pe=>pe.id===t),ce=he<0?(se+1)%G.length:(se-1+G.length)%G.length;e(G[ce].id)},[G,t,e]);w.useEffect(()=>{const ue=te.current;if(!ue)return;const he=K=>{if(!z.current)return;const se=Math.abs(K.touches[0].clientX-z.current.x),ce=Math.abs(K.touches[0].clientY-z.current.y);if(J.current){K.preventDefault();return}se>10&&se>ce&&(J.current=!0,K.preventDefault())};return ue.addEventListener("touchmove",he,{passive:!1}),()=>ue.removeEventListener("touchmove",he)},[]);const de=o<100?{filter:`brightness(${o/100})`}:void 0;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{ref:te,className:"w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden",style:{...de,overscrollBehaviorX:"none"},onTouchStart:ae,onTouchEnd:Z,children:[i.jsx(Cnt,{selectedPrinterId:t,onPrinterChange:e,deviceOnline:_}),i.jsx("main",{className:"flex-1 overflow-y-auto",children:i.jsx(TX,{context:{selectedPrinterId:t,setSelectedPrinterId:e,sbState:N,setAlert:r,displayBrightness:o,setDisplayBrightness:l,displayBlankTimeout:c,setDisplayBlankTimeout:d}})}),i.jsx(Pnt,{alert:n}),i.jsx(Ant,{}),i.jsx(Int,{})]}),a&&i.jsx("div",{className:"fixed inset-0 bg-black z-[9999]",onPointerDown:ue=>{ue.stopPropagation(),P()}})]})}function O5({color:t,isEmpty:e,size:n=32}){return e?i.jsx("div",{className:"rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center",style:{width:n,height:n},children:i.jsx("div",{className:"w-2 h-2 rounded-full bg-zinc-600"})}):i.jsxs("svg",{width:n,height:n,viewBox:"0 0 32 32",children:[i.jsx("circle",{cx:"16",cy:"16",r:"14",fill:t,stroke:"white",strokeWidth:"1.5",strokeOpacity:"0.7"}),i.jsx("circle",{cx:"16",cy:"16",r:"11",fill:t,style:{filter:"brightness(0.85)"}})]})}const Unt="spoolbuddy-default-core-weight";function yle(){try{const t=localStorage.getItem(Unt);if(t){const e=parseInt(t,10);if(e>=0&&e<=500)return e}}catch{}return 250}function Bnt({spool:t,scaleWeight:e,onClose:n,onSyncWeight:r,onAssignToAms:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(!1),u=t.rgba?`#${t.rgba.slice(0,6)}`:"#808080",m=t.core_weight&&t.core_weight>0?t.core_weight:yle(),p=e!==null?Math.round(Math.max(0,e)):null,f=p!==null?Math.round(Math.max(0,p-m)):null,y=Math.round(t.label_weight||1e3),v=f!==null?Math.min(100,Math.round(f/y*100)):null,b=v!==null?v>50?"#22c55e":v>20?"#eab308":"#ef4444":"#808080",_=Math.max(0,(t.label_weight||0)-(t.weight_used||0))+m,N=p!==null?p-_:null,C=N!==null?Math.abs(N)<=50:null,k=async()=>{if(e!==null){l(!0);try{await zi.updateSpoolWeight(t.id,Math.round(e)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(P){console.error("Failed to sync weight:",P)}finally{l(!1)}}};return i.jsxs("div",{className:"flex flex-col items-center space-y-4 max-w-md",children:[i.jsxs("div",{className:"flex items-start gap-5",children:[i.jsxs("div",{className:"relative shrink-0",children:[i.jsx(O5,{color:u,isEmpty:!1,size:100}),v!==null&&i.jsxs("div",{className:"absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg",style:{backgroundColor:b},children:[v,"%"]})]}),i.jsxs("div",{className:"flex-1 min-w-0 pt-1",children:[i.jsx("h3",{className:"text-lg font-semibold text-zinc-100",children:t.color_name||"Unknown color"}),i.jsxs("p",{className:"text-sm text-zinc-400",children:[t.brand," • ",t.material,t.subtype&&` ${t.subtype}`]}),f!==null&&i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsxs("span",{className:"text-3xl font-bold font-mono text-zinc-100",children:[f,"g"]}),i.jsxs("span",{className:"text-sm text-zinc-500",children:["/ ",y,"g"]})]}),i.jsx("p",{className:"text-xs text-zinc-500 mt-0.5",children:s("spoolbuddy.spool.remaining","Remaining")}),i.jsx("div",{className:"mt-2 max-w-xs",children:i.jsx("div",{className:"h-2 bg-zinc-700 rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${v}%`,backgroundColor:b}})})})]})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.grossWeight","Gross weight")}),i.jsx("span",{className:"font-mono text-zinc-300",children:p!==null?`${p}g`:"—"})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.spool.coreWeight","Core")}),i.jsxs("span",{className:"font-mono text-zinc-300",children:[m,"g"]})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.spoolSize","Spool size")}),i.jsxs("span",{className:"font-mono text-zinc-300",children:[y,"g"]})]}),i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.spool.scaleWeight","Scale")}),p!==null?i.jsxs("span",{className:`flex items-center gap-1 font-mono ${C?"text-green-500":"text-yellow-500"}`,children:[p,"g",C?i.jsx(Zr,{className:"w-3.5 h-3.5"}):i.jsxs(i.Fragment,{children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsx("button",{onClick:k,className:"p-1 hover:bg-green-500/20 rounded transition-colors text-green-500",title:s("spoolbuddy.dashboard.syncWeight","Sync Weight"),children:i.jsx(vr,{className:"w-4 h-4"})})]})]}):i.jsx("span",{className:"text-zinc-500",children:"—"})]}),i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-zinc-500",children:s("spoolbuddy.dashboard.tagId","Tag")}),i.jsx("span",{className:"font-mono text-xs text-zinc-400 truncate max-w-[120px]",title:t.tag_uid||"",children:t.tag_uid?t.tag_uid.slice(-8):"—"})]})]}),i.jsxs("div",{className:"flex gap-2 justify-center",children:[a&&i.jsx("button",{onClick:a,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:s("spoolbuddy.modal.assignToAms","Assign to AMS")}),i.jsx("button",{onClick:k,disabled:e===null||o,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${c?"bg-green-600/20 text-green-400":a?"bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed":"bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed"}`,children:o?"...":c?s("spoolbuddy.dashboard.weightSynced","Synced!"):s("spoolbuddy.dashboard.syncWeight","Sync Weight")}),n&&i.jsx("button",{onClick:n,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:s("spoolbuddy.dashboard.close","Close")})]})]})}function Hnt({tagUid:t,scaleWeight:e,coreWeight:n,onLinkSpool:r,onAddToInventory:a,onClose:s}){const{t:o}=jt(),l=n??yle(),c=e!==null?Math.round(Math.max(0,e)):null,d=c!==null?Math.round(Math.max(0,c-l)):null;return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-5",children:[i.jsx("div",{className:"w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center",children:i.jsx("svg",{className:"w-10 h-10 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z"})})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-zinc-100",children:o("spoolbuddy.dashboard.newTag","New Tag Detected")}),i.jsx("p",{className:"text-sm text-zinc-500 font-mono mt-1",children:t})]}),c!==null&&i.jsxs("div",{className:"text-sm text-zinc-400",children:[i.jsxs("span",{className:"font-mono font-semibold",children:[c,"g"]})," ",o("spoolbuddy.dashboard.onScale","on scale"),d!==null&&d>0&&i.jsxs("span",{className:"text-zinc-500",children:[" • ~",d,"g filament"]})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 justify-center",children:[a&&i.jsx("button",{onClick:a,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:o("spoolbuddy.modal.addToInventory","Add to Inventory")}),r&&i.jsxs("button",{onClick:r,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:[i.jsx("svg",{className:"w-4 h-4 inline-block mr-1.5 -mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),o("spoolbuddy.dashboard.linkSpool","Link to Spool")]}),s&&i.jsx("button",{onClick:s,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:o("spoolbuddy.dashboard.close","Close")})]})]})}function $nt(t){return t?`#${t.slice(0,6)}`:"#808080"}function vle(t){return!t.tray_type||t.tray_type===""}function qnt(t){return t<=3?`AMS ${String.fromCharCode(65+t)}`:t>=128&&t<=135?`AMS HT ${String.fromCharCode(65+t-128)}`:`AMS ${t}`}function Vnt({className:t}){return i.jsx("svg",{className:t,viewBox:"0 0 36 54",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{d:"M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z",fill:"#C3C2C1"})})}function Gnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 35 53",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z",fill:"#C3C2C1"}),i.jsx("path",{d:"M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z",fill:"#1F8FEB"})]})}function Wnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 36 54",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z",fill:"#1F8FEB"}),i.jsx("path",{d:"M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z",fill:"#C3C2C1"})]})}function Knt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"}),i.jsx("circle",{cx:"6",cy:"15",r:"2.5",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function Ynt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"4.5",y:"8",width:"3",height:"4.5",fill:"#d4a017",rx:"0.5"}),i.jsx("circle",{cx:"6",cy:"15",r:"2",fill:"#d4a017"}),i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function Xnt({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 12 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"4.5",y:"3",width:"3",height:"9.5",fill:"#c62828",rx:"0.5"}),i.jsx("circle",{cx:"6",cy:"15",r:"2",fill:"#c62828"}),i.jsx("path",{d:"M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z",stroke:"#C3C2C1",strokeWidth:"1",fill:"none"})]})}function wle({humidity:t,goodThreshold:e=40,fairThreshold:n=60}){let r,a;return t<=e?(r="#22a352",a=Vnt):t<=n?(r="#d4a017",a=Gnt):(r="#c62828",a=Wnt),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx(a,{className:"w-3 h-3.5"}),i.jsxs("span",{className:"font-medium tabular-nums text-xs",style:{color:r},children:[t,"%"]})]})}function Sle({temp:t,goodThreshold:e=28,fairThreshold:n=35}){let r,a;return t<=e?(r="#22a352",a=Knt):t<=n?(r="#d4a017",a=Ynt):(r="#c62828",a=Xnt),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx(a,{className:"w-3 h-3.5"}),i.jsxs("span",{className:"font-medium tabular-nums text-xs",style:{color:r},children:[t,"°C"]})]})}function I5({side:t}){return i.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded",style:{backgroundColor:"#1a4d2e",color:"#00ae42"},children:t})}function Qnt({tray:t,slotIndex:e,isActive:n,fillOverride:r,spoolmanFill:a,onClick:s}){const o=vle(t),l=$nt(t.tray_color),c=t.remain!==null&&t.remain!==void 0&&t.remain>=0?t.remain:null,d=r===0&&c!==null&&c>0?null:r,u=a??d??c;return i.jsxs("div",{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?"ring-2 ring-bambu-green":""} ${s?"cursor-pointer hover:bg-white/5":""}`,onClick:s,children:[i.jsxs("div",{className:"relative w-16 h-16 mb-1",children:[o?i.jsx("div",{className:"w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center",children:i.jsx("div",{className:"w-3 h-3 rounded-full bg-gray-600"})}):i.jsxs("svg",{viewBox:"0 0 56 56",className:"w-full h-full",children:[i.jsx("circle",{cx:"28",cy:"28",r:"26",fill:l}),i.jsx("circle",{cx:"28",cy:"28",r:"20",fill:l,style:{filter:"brightness(0.85)"}}),i.jsx("ellipse",{cx:"20",cy:"20",rx:"6",ry:"4",fill:"white",opacity:"0.3"}),i.jsx("circle",{cx:"28",cy:"28",r:"8",fill:"#2d2d2d"}),i.jsx("circle",{cx:"28",cy:"28",r:"5",fill:"#1a1a1a"})]}),n&&i.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full"})]}),i.jsx("span",{className:"text-sm text-white/70 truncate max-w-full",children:o?"Empty":t.tray_type||"Unknown"}),!o&&u!==null&&u>=0&&i.jsx("div",{className:"w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1",children:i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${u}%`,backgroundColor:sx(u)}})}),i.jsx("span",{className:"absolute top-1 right-1 text-xs text-white/30",children:e+1})]})}function _le({unit:t,activeSlot:e,onConfigureSlot:n,isDualNozzle:r,nozzleSide:a,thresholds:s,fillOverrides:o,spoolmanFillOverrides:l}){const c=t.tray||[],d=t.is_ams_ht,u=d?1:4;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-white font-medium text-base",children:qnt(t.id)}),r&&a&&i.jsx(I5,{side:a})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.temp!=null&&i.jsx(Sle,{temp:t.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair}),t.humidity!=null&&i.jsx(wle,{humidity:t.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair})]})]}),i.jsx("div",{className:`grid ${d?"grid-cols-1 max-w-[100px] mx-auto":"grid-cols-4"} gap-2`,children:Array.from({length:u}).map((m,p)=>{const f=c[p]||{id:p,tray_color:null,tray_type:"",tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return i.jsx(Qnt,{tray:f,slotIndex:p,isActive:e===p,fillOverride:o?.[`${t.id}-${p}`]??null,spoolmanFill:l?.[`${t.id}-${p}`]??null,onClick:n?()=>n(t.id,p,vle(f)?null:f):void 0},p)})})]})}function s3(t){return t<=3?`AMS ${String.fromCharCode(65+t)}`:t>=128&&t<=135?`AMS HT ${String.fromCharCode(65+t-128)}`:`AMS ${t}`}function o3(t){return!t.tray_type||t.tray_type===""}function Znt(t){return t?`#${t.slice(0,6)}`:"#808080"}const tT=t=>(t??"").trim().toUpperCase();function Jnt(t,e){const n=tT(t),r=tT(e);return!n||!r?"none":n===r?"exact":r.includes(n)||n.includes(r)?"partial":"none"}function ert(t,e){const n=tT(t),r=tT(e);return!n||!r?!1:n===r}function trt({isOpen:t,onClose:e,spool:n,printerId:r}){const{t:a}=jt(),s=cn(),[o,l]=w.useState(null),[c,d]=w.useState(null),[u,m]=w.useState(!1),[p,f]=w.useState(null),[y,v]=w.useState(null);w.useEffect(()=>{t&&(l(null),d(null),m(!1),f(null),v(null))},[t]);const b=w.useCallback(Se=>{Se.key==="Escape"&&e()},[e]);w.useEffect(()=>(t&&document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)),[t,b]);const{data:g}=et({queryKey:["printerStatus",r],queryFn:()=>ge.getPrinterStatus(r),enabled:t&&r!==null,refetchInterval:5e3}),{data:_}=et({queryKey:["printer",r],queryFn:()=>ge.getPrinter(r),enabled:t&&r!==null}),{data:N}=et({queryKey:["settings"],queryFn:()=>ge.getSettings(),enabled:t,staleTime:300*1e3}),{data:C}=et({queryKey:["spool-assignments",r],queryFn:()=>ge.getAssignments(r),enabled:t&&r!==null,staleTime:30*1e3}),k=w.useMemo(()=>{const Se={};if(!C)return Se;for(const B of C){const X=B.spool;if(X&&X.label_weight>0&&X.weight_used!=null){const D=Math.round(Math.max(0,X.label_weight-X.weight_used)/X.label_weight*100);Se[`${B.ams_id}-${B.tray_id}`]=D}}return Se},[C]),P=N?{humidityGood:Number(N.ams_humidity_good)||40,humidityFair:Number(N.ams_humidity_fair)||60,tempGood:Number(N.ams_temp_good)||28,tempFair:Number(N.ams_temp_fair)||35}:void 0,A=g?.connected??!1,j=w.useMemo(()=>g?.ams??[],[g?.ams]),T=w.useMemo(()=>j.filter(Se=>!Se.is_ams_ht),[j]),F=w.useMemo(()=>j.filter(Se=>Se.is_ams_ht),[j]),G=w.useMemo(()=>[...g?.vt_tray??[]].sort((Se,B)=>(Se.id??254)-(B.id??254)),[g?.vt_tray]),z=_?.nozzle_count===2||g?.temperatures?.nozzle_2!==void 0,J=w.useRef({});w.useEffect(()=>{g?.ams_extruder_map&&Object.keys(g.ams_extruder_map).length>0&&(J.current=g.ams_extruder_map)},[g?.ams_extruder_map]);const I=g?.ams_extruder_map&&Object.keys(g.ams_extruder_map).length>0?g.ams_extruder_map:J.current,te=w.useCallback(Se=>{if(!z)return null;const B=I[String(Se)],X=Se>=128?Se-128:Se;return(B!==void 0?B:X)===1?"L":"R"},[z,I]),ae=ht({mutationFn:async({amsId:Se,trayId:B})=>{if(!r)throw new Error("No printer selected");await ge.assignSpool({spool_id:n.id,printer_id:r,ams_id:Se,tray_id:B})},onSuccess:()=>{d("success"),l(a("spoolbuddy.modal.assignSuccess","Assigned!")),s.invalidateQueries({queryKey:["slotPresets"]}),setTimeout(()=>e(),1500)},onError:Se=>{d("error"),l(Se instanceof Error?Se.message:a("spoolbuddy.modal.assignError","Failed to assign spool."))}}),Z=ae.isPending,de=w.useCallback((Se,B)=>{if(Se===254||Se===255){const D=Se===254?254:254+B;return G.find(M=>(M.id??254)===D)||null}return j.find(D=>D.id===Se)?.tray?.find(D=>D.id===B)||null},[j,G]),ue=w.useCallback((Se,B)=>Se<=3?`${s3(Se)} ${a("ams.slot","Slot")} ${B+1}`:Se>=128&&Se<=135?s3(Se):Se===254?a("printers.extL","Ext-L"):z?a("printers.extR","Ext-R"):a("printers.ext","Ext"),[a,z]),he=w.useCallback((Se,B)=>{d("info"),l(a("spoolbuddy.modal.assigning","Configuring slot...")),ae.mutate({amsId:Se,trayId:B})},[ae,a]),K=w.useCallback((Se,B)=>{if(!Z){if(!N?.disable_filament_warnings){const X=de(Se,B);if(X&&!o3(X)){const D=X.tray_sub_brands||X.tray_type||"",M=Jnt(n.material,D),U=n.slicer_filament_name||n.slicer_filament,W=X.tray_type||"",H=ert(U,W);if(M!=="exact"||!H){let re="profile";M==="none"&&!H?re="material_profile":M==="partial"&&!H?re="partial_profile":M==="none"?re="material":M==="partial"&&(re="partial");const O=ue(Se,B);v({amsId:Se,trayId:B}),f({type:re,spoolMaterial:n.material||"",trayMaterial:D||"",spoolProfile:U||void 0,trayProfile:W||void 0,location:O}),m(!0);return}}}he(Se,B)}},[Z,N?.disable_filament_warnings,n,de,ue,he]),se=w.useCallback(()=>{y&&(m(!1),f(null),he(y.amsId,y.trayId),v(null))},[y,he]),ce=w.useMemo(()=>{const Se=[];for(const B of F){const X=B.tray?.[0]||{id:0,tray_color:null,tray_type:"",tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},D=k[`${B.id}-0`]??null,M=X.remain!=null&&X.remain>=0?X.remain:null,U=D===0&&M!==null&&M>0?null:D;Se.push({key:`ht-${B.id}`,label:s3(B.id),amsId:B.id,trayId:0,tray:X,isEmpty:o3(X),nozzleSide:te(B.id),effectiveFill:U??M})}for(const B of G){const X=B.id??254,D=X-254,M=k[`255-${D}`]??null,U=B.remain!=null&&B.remain>=0?B.remain:null,W=M===0&&U!==null&&U>0?null:M;Se.push({key:`ext-${X}`,label:z?X===254?a("printers.extL","Ext-L"):a("printers.extR","Ext-R"):a("printers.ext","Ext"),amsId:255,trayId:D,tray:B,isEmpty:o3(B),nozzleSide:z?X===254?"L":"R":null,effectiveFill:W??U})}return Se},[F,G,z,a,te,k]);if(!t)return null;const pe=n.rgba?`#${n.rgba.slice(0,6)}`:"#808080";return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"fixed inset-0 z-[60] bg-bambu-dark flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("div",{className:"w-7 h-7 rounded-full shrink-0",style:{backgroundColor:pe}}),i.jsx("div",{className:"min-w-0",children:i.jsxs("h2",{className:"text-sm font-semibold text-zinc-100 truncate",children:[a("spoolbuddy.modal.assignToAmsTitle","Assign to AMS"),i.jsxs("span",{className:"font-normal text-zinc-500 ml-2",children:[n.color_name||"Unknown"," • ",n.brand," ",n.material,n.subtype&&` ${n.subtype}`]})]})})]}),i.jsx("button",{onClick:e,disabled:Z,className:"p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50",children:i.jsx(qt,{className:"w-5 h-5"})})]}),o&&i.jsxs("div",{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${c==="info"?"bg-blue-500/10 border-blue-500/40":c==="success"?"bg-green-500/10 border-green-500/40":"bg-red-500/10 border-red-500/40"}`,children:[c==="info"&&i.jsx(ft,{className:"w-4 h-4 text-blue-400 animate-spin shrink-0"}),c==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-400 shrink-0"}),c==="error"&&i.jsx(Wi,{className:"w-4 h-4 text-red-400 shrink-0"}),i.jsx("span",{className:`text-sm ${c==="info"?"text-blue-300":c==="success"?"text-green-300":"text-red-300"}`,children:o})]}),i.jsx("div",{className:"flex-1 flex flex-col gap-3 p-4 min-h-0",children:!A&&r?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsx("div",{className:"text-center text-white/50",children:i.jsx("p",{className:"text-lg mb-2",children:a("spoolbuddy.ams.printerDisconnected","Printer disconnected")})})}):j.length===0&&G.length===0?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"text-center text-white/50",children:[i.jsx(Ki,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-lg mb-2",children:a("spoolbuddy.ams.noData","No AMS detected")}),i.jsx("p",{className:"text-sm",children:a("spoolbuddy.ams.connectAms","Connect an AMS to see filament slots")})]})}):i.jsxs(i.Fragment,{children:[T.length>0&&i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0",children:T.map(Se=>i.jsx(_le,{unit:Se,activeSlot:null,onConfigureSlot:(B,X)=>K(Se.id,X),isDualNozzle:z,nozzleSide:te(Se.id),thresholds:P,fillOverrides:k},Se.id))}),ce.length>0&&i.jsx("div",{className:"flex gap-2 shrink-0",children:ce.map(({key:Se,label:B,amsId:X,trayId:D,tray:M,isEmpty:U,nozzleSide:W,effectiveFill:H})=>{const re=Znt(M.tray_color);return i.jsxs("div",{onClick:()=>K(X,D),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${Z?"opacity-50 pointer-events-none":""}`,children:[i.jsx("div",{className:"relative w-10 h-10 shrink-0",children:U?i.jsx("div",{className:"w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center",children:i.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-gray-600"})}):i.jsxs("svg",{viewBox:"0 0 56 56",className:"w-full h-full",children:[i.jsx("circle",{cx:"28",cy:"28",r:"26",fill:re}),i.jsx("circle",{cx:"28",cy:"28",r:"20",fill:re,style:{filter:"brightness(0.85)"}}),i.jsx("ellipse",{cx:"20",cy:"20",rx:"6",ry:"4",fill:"white",opacity:"0.3"}),i.jsx("circle",{cx:"28",cy:"28",r:"8",fill:"#2d2d2d"}),i.jsx("circle",{cx:"28",cy:"28",r:"5",fill:"#1a1a1a"})]})}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"text-xs text-white/50 font-medium",children:B}),W&&i.jsx(I5,{side:W})]}),i.jsx("div",{className:"text-sm text-white/80 truncate",children:U?"Empty":M.tray_type||"?"})]}),!U&&H!=null&&H>=0&&i.jsx("div",{className:"w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse",children:i.jsx("div",{className:"w-full rounded-full",style:{height:`${H}%`,backgroundColor:sx(H)}})})]},Se)})})]})}),i.jsx("div",{className:"flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0",children:i.jsx("button",{onClick:e,disabled:Z,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50",children:c==="success"?a("spoolbuddy.dashboard.close","Close"):a("spoolbuddy.modal.cancel","Cancel")})})]}),u&&p&&(()=>{let Se="";return p.type==="material"?Se=a("inventory.assignMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type==="partial"?Se=a("inventory.assignPartialMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type==="material_profile"?Se=`${a("inventory.assignMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})} ${a("inventory.assignProfileMismatchMessage",{spoolProfile:p.spoolProfile||a("common.unknown"),trayProfile:p.trayProfile||a("common.unknown"),location:p.location})}`:p.type==="partial_profile"?Se=`${a("inventory.assignPartialMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})} diff --git a/static/index.html b/static/index.html index 6ba9cf570..40d08b1a9 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +