From 1de4e409b0607a6e1ecec1a23a0cfab1064fe29c Mon Sep 17 00:00:00 2001 From: maziggy Date: Mon, 20 Apr 2026 13:06:29 +0200 Subject: [PATCH] fix(printer): suppress "not homed" re-prompt after Auto Home (#1052 follow-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bed-jog "not homed" warning modal was gated on a session-scoped "warned" flag set only by the "Move anyway" button. Clicking "Auto Home" sent the G28 and closed the modal but never set the flag, so the next jog click in the same session re-prompted — even though the printer was now homed. The homeAxes mutation's onSuccess handler now flips the same `bambuddy.bedJog.warned.` sessionStorage flag. The warning still fires once per printer per session (intended safety guard, cleared on restart), but not repeatedly after a successful auto-home. --- CHANGELOG.md | 2 +- frontend/src/pages/PrintersPage.tsx | 9 ++++++++- static/assets/{index-DbBotyQl.js => index-DFkuTMRb.js} | 2 +- static/index.html | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) rename static/assets/{index-DbBotyQl.js => index-DFkuTMRb.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a897d1262..9508a01f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to Bambuddy will be documented in this file. ## [0.2.4b1] - Unreleased ### Fixed -- **⚠️ Bed-Jog "Home Z" Could Crash the Bed Into the Toolhead** ([#1052](https://github.com/maziggy/bambuddy/issues/1052)) — **Critical safety fix.** On H2C (and by extension any Bambu printer where Z-home moves the bed UP toward an endstop — H2D, H2S, and X1 family all share this kinematics) the bed-jog modal's "Home Z" button sent a raw `G28 Z` over the `gcode_line` MQTT command. Bare `G28 Z` skips the toolhead-park step that a full `G28` runs first, so the bed raised without stopping at a safe height — in the reporter's case the toolhead happened to be parked on the purge chute and no damage was caused, but hitting the button with a toolhead anywhere else would have driven the bed into it at full Z speed. Root cause was the `/api/v1/printers/{id}/home-axes` endpoint's per-axis gcode mapping (`"z" → "G28 Z"`, `"xy" → "G28 X Y"`, `"all" → "G28"`). The endpoint now ignores the `axes` argument entirely and always sends a bare `G28`, which Bambu firmware expands into the safe multi-step sequence (park toolhead → home XY → home Z). The MQTT client helper `BambuClient.home_axes()` has the same change. The bed-jog modal is retitled "Auto Home" and its copy now says "parks the toolhead, then homes X, Y, and Z" so users aren't surprised when X/Y motion happens first. Regression test covers all three axes arguments producing the same bare `G28`. Thanks to @mikefromdot for catching this with an undamaged retest. +- **⚠️ Bed-Jog "Home Z" Could Crash the Bed Into the Toolhead** ([#1052](https://github.com/maziggy/bambuddy/issues/1052)) — **Critical safety fix.** On H2C (and by extension any Bambu printer where Z-home moves the bed UP toward an endstop — H2D, H2S, and X1 family all share this kinematics) the bed-jog modal's "Home Z" button sent a raw `G28 Z` over the `gcode_line` MQTT command. Bare `G28 Z` skips the toolhead-park step that a full `G28` runs first, so the bed raised without stopping at a safe height — in the reporter's case the toolhead happened to be parked on the purge chute and no damage was caused, but hitting the button with a toolhead anywhere else would have driven the bed into it at full Z speed. Root cause was the `/api/v1/printers/{id}/home-axes` endpoint's per-axis gcode mapping (`"z" → "G28 Z"`, `"xy" → "G28 X Y"`, `"all" → "G28"`). The endpoint now ignores the `axes` argument entirely and always sends a bare `G28`, which Bambu firmware expands into the safe multi-step sequence (park toolhead → home XY → home Z). The MQTT client helper `BambuClient.home_axes()` has the same change. The bed-jog modal is retitled "Auto Home" and its copy now says "parks the toolhead, then homes X, Y, and Z" so users aren't surprised when X/Y motion happens first. After a successful Auto Home click, the modal no longer re-prompts on the next jog in the same session — the "not homed" warning is gated on a session-scoped acknowledgement flag that was only being set by "Move anyway" and now also fires on successful Auto Home. Regression test covers all three axes arguments producing the same bare `G28`. Thanks to @mikefromdot for catching this with an undamaged retest. - **AMS: Configure / Assign Spool Hidden on Reset Slots, and Assign Spool Missing Matching-Material Inventory** ([#1047](https://github.com/maziggy/bambuddy/issues/1047)) — Two separate symptoms from the same report. (1) After resetting an AMS slot from the printer UI, the Bambuddy printer card showed "Empty Slot" with no Configure or Assign Spool actions on hover, while the same slot in SpoolBuddy's AMS page still let the user re-configure it. Root cause: commit `c9efa4b8` (#784) added a `tray?.state === 10` gate to the `EmptySlotHoverCard` actions, intended to show the buttons only when a spool was physically present but not loaded (state=10) and hide them on truly empty slots (state=9). In practice, firmware often reports `state=9` (or no `state` field at all) after a user-initiated reset — even when a spool is still physically in the slot — so the actions disappeared exactly when the user needed them. The gate is redundant anyway (`EmptySlotHoverCard` is only rendered when the slot has no `tray_type`, so it's definitionally empty from Bambuddy's perspective), and configuring an empty slot is a valid "tell the printer what will be loaded here" operation. The gate is now removed at both the standard-AMS and AMS-HT render paths. (2) After configuring a slot with a Generic profile (e.g. "Devil Design PLA Basic Red"), the Assign Spool modal didn't list the matching inventory spool unless the user enabled the "Show all spools" toggle. Root cause: the filter at `AssignSpoolModal.tsx:144` required `normalizeValue(spool.slicer_filament_name) === normalizeValue(trayInfo.profile)` — manually-added inventory spools typically don't have `slicer_filament_name` populated, so they failed the exact-profile check even when the material matched. The filter now prefers an exact slicer-profile match when both sides advertise one, and falls back to partial material match in either direction (so e.g. a spool with `material="PLA"` is selectable for a slot reporting `"PLA Basic"`) when profile info is missing. (3) Once the matching spool was assignable, a "profile mismatch" confirmation dialog still warned on every assignment because Bambu Studio / OrcaSlicer slicer-profile names carry a printer/nozzle/variant qualifier after `@` (e.g. `"Devil Design PLA Basic @Bambu Lab H2D 0.4 nozzle (Custom)"`) while the tray stores only the bare base name (`"Devil Design PLA Basic"`), and `checkProfileMatch` compared the full strings. Both the filter and the mismatch check now strip the `@…` qualifier before comparing, so identical base profiles are treated as a match. Regression test covers a spool with no slicer profile being surfaced for a slot whose profile + material are both set. Thanks to @TravisWilder for the report. - **Skip Objects: Enlarged Preview Image Fails to Load on Auth-Enabled Instances** ([#1046](https://github.com/maziggy/bambuddy/issues/1046)) — Clicking the mini print-pr diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index 17d60390e..fadb69cc3 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -1878,7 +1878,14 @@ function PrinterCard({ const homeAxesMutation = useMutation({ mutationFn: (axes: 'z' | 'xy' | 'all') => api.homeAxes(printer.id, axes), - onSuccess: () => showToast(t('printers.bedJog.homingStarted')), + onSuccess: () => { + // Flip the session-scoped "warned" flag so the next bed-jog click doesn't re-prompt + // the not-homed modal. The flag is the same one "Move anyway" sets; after a successful + // auto-home request the printer is (or will shortly be) in a known-homed state, so + // prompting again in the same session is noise — #1052 follow-up. + try { sessionStorage.setItem(`bambuddy.bedJog.warned.${printer.id}`, '1'); } catch { /* ignore */ } + showToast(t('printers.bedJog.homingStarted')); + }, onError: (error: Error) => showToast(error.message || t('printers.toast.failedToSendCommand'), 'error'), }); diff --git a/static/assets/index-DbBotyQl.js b/static/assets/index-DFkuTMRb.js similarity index 99% rename from static/assets/index-DbBotyQl.js rename to static/assets/index-DFkuTMRb.js index e876bce28..803de688d 100644 --- a/static/assets/index-DbBotyQl.js +++ b/static/assets/index-DFkuTMRb.js @@ -8533,7 +8533,7 @@ ${o("inventory.assignProfileMismatchMessage",{spoolProfile:C.spoolProfile||o("co absolute left-0 z-50 ${u==="top"?"bottom-full mb-2":"top-full mt-2"} animate-in fade-in-0 zoom-in-95 duration-150 - `,style:{maxWidth:"calc(100vw - 24px)"},onMouseEnter:T,onMouseLeave:F,children:a.jsxs("div",{className:"w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2",children:[a.jsx("div",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:n}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx("span",{className:"text-[10px] tracking-wide text-bambu-gray font-medium shrink-0",children:l("printers.amsPopup.serialNumber")}),a.jsx("span",{className:"text-[10px] text-white font-mono truncate",children:t.serial_number||"—"})]}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx("span",{className:"text-[10px] tracking-wide text-bambu-gray font-medium shrink-0",children:l("printers.amsPopup.firmwareVersion")}),a.jsx("span",{className:"text-[10px] text-white font-mono truncate",children:t.sw_ver||"—"})]}),a.jsx("div",{className:"h-px bg-bambu-dark-tertiary/50"}),a.jsxs("div",{className:"space-y-1",children:[a.jsx("span",{className:"text-[10px] text-bambu-gray font-medium block",children:l("printers.amsPopup.friendlyName")}),a.jsx("input",{type:"text",value:p,onChange:H=>i&&f(H.target.value),onKeyDown:H=>H.key==="Enter"&&k(),onFocus:()=>C(!0),onBlur:()=>{C(!1),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>d(!1),200)},placeholder:i?l("printers.amsPopup.friendlyNamePlaceholder"):r?.[t.id]||"—",disabled:!i,title:i?void 0:l("printers.amsPopup.noEditPermission"),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed",maxLength:100}),i&&a.jsxs("div",{className:"space-y-1",children:[b&&a.jsx("p",{className:"text-[10px] text-red-400 break-words",children:b}),a.jsxs("div",{className:"flex gap-1 justify-end",children:[a.jsx("button",{onClick:k,disabled:x,className:"px-2 py-0.5 text-[10px] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50",children:l("printers.amsPopup.save")}),r?.[t.id]&&a.jsx("button",{onClick:D,disabled:x,className:"px-2 py-0.5 text-[10px] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50",children:l("printers.amsPopup.clear")})]})]})]})]})})]})}const bL={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};function hK({printer:t,hideIfDisconnected:e,maintenanceInfo:n,viewMode:r="expanded",cardSize:i=2,amsThresholds:s,spoolmanEnabled:o=!1,linkedSpools:l,spoolmanUrl:c,spoolmanSyncMode:d,onGetAssignment:u,onUnassignSpool:m,timeFormat:p="system",cameraViewMode:f="window",onOpenEmbeddedCamera:x,checkPrinterFirmware:v=!0,dryingPresets:b=bL,requirePlateClear:g=!1,selectionMode:_=!1,isSelected:C=!1,onToggleSelect:P}){const{t:N}=Dt(),A=nn(),T=Uo(),{showToast:F}=hn(),{hasPermission:k}=_r(),[D,H]=w.useState(!1),[z,Y]=w.useState(!1),[L,te]=w.useState(!0),[ie,J]=w.useState(!1),[oe,fe]=w.useState(!1),[re,W]=w.useState(!1),[ne,me]=w.useState(!1),[be,Pe]=w.useState(!1),[q,Q]=w.useState(!1),[E,j]=w.useState(!1),[O,K]=w.useState(!1),[U,ue]=w.useState(null),[I,G]=w.useState(null),[X,V]=w.useState(null),[ee,se]=w.useState(10),[ge,pe]=w.useState(null),[le,B]=w.useState(!1),[R,ae]=w.useState(!1),[ke,Se]=w.useState(!1),[ye,Te]=w.useState(!1),ve=w.useCallback(()=>Te(!1),[]),[Ae,Re]=w.useState(null),[Me,Le]=w.useState(null),[Oe,qe]=w.useState("n3f"),[Qe,tt]=w.useState("PLA"),[he,Fe]=w.useState(50),[we,Ve]=w.useState(4),[je,ce]=w.useState(!1),[xe,Be]=w.useState(null),[Ze,pt]=w.useState(!1),[xt,yt]=w.useState(!1),Ut=w.useRef(0),[Kt,en]=w.useState(null),[Vt,Yt]=w.useState(null),[rn,Nn]=w.useState(null),[We,at]=w.useState(null),[dt,It]=w.useState(!1),[Ft,ze]=w.useState(null),[lt,gt]=w.useState(!1),[rt,Ie]=w.useState(!1),[ot,Ce]=w.useState(null),[Ge,et]=w.useState(!1),[Ke,Xe]=w.useState(!1),{data:Ue}=Ye({queryKey:["printerStatus",t.id],queryFn:()=>de.getPrinterStatus(t.id),refetchInterval:3e4}),{data:Je}=Ye({queryKey:["firmwareUpdate",t.id],queryFn:()=>Ok.checkPrinterUpdate(t.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:v&&k("firmware:read")}),At=w.useMemo(()=>{const mt=new Set;if(Ue?.ams)for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])Zt.tray_info_idx&&mt.add(Zt.tray_info_idx);for(const Ht of Ue?.vt_tray??[])Ht.tray_info_idx&&mt.add(Ht.tray_info_idx);if(Ue?.nozzle_rack)for(const Ht of Ue.nozzle_rack)Ht.filament_id&&mt.add(Ht.filament_id);return Array.from(mt)},[Ue?.ams,Ue?.vt_tray,Ue?.nozzle_rack]),vt=w.useMemo(()=>{const mt=new Set;if(Ue?.ams)for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])Zt.tray_type&&mt.add(Zt.tray_type.toUpperCase());for(const Ht of Ue?.vt_tray??[])Ht.tray_type&&mt.add(Ht.tray_type.toUpperCase());return mt},[Ue?.ams,Ue?.vt_tray]),$e=w.useMemo(()=>{const mt=new Set;if(Ue?.ams){for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])if(Zt.tray_type&&Zt.tray_color){const ct=Zt.tray_color.replace("#","").toLowerCase().slice(0,6);mt.add(`${Zt.tray_type.toUpperCase()}:${ct}`)}}for(const Ht of Ue?.vt_tray??[])if(Ht.tray_type&&Ht.tray_color){const Zt=Ht.tray_color.replace("#","").toLowerCase().slice(0,6);mt.add(`${Ht.tray_type.toUpperCase()}:${Zt}`)}return mt},[Ue?.ams,Ue?.vt_tray]),{data:wt}=Ye({queryKey:["filamentInfo",At],queryFn:()=>de.getFilamentInfo(At),enabled:At.length>0,staleTime:300*1e3}),{data:Mt}=Ye({queryKey:["slotPresets",t.id],queryFn:()=>de.getSlotPresets(t.id),staleTime:120*1e3}),{data:Gt,refetch:sn}=Ye({queryKey:["amsLabels",t.id],queryFn:()=>de.getAmsLabels(t.id),staleTime:300*1e3}),[pn,zn]=w.useState(null);w.useEffect(()=>{Ue?.wifi_signal!=null&&zn(Ue.wifi_signal)},[Ue?.wifi_signal]);const cn=Ue?.wifi_signal??pn,dn=w.useRef(void 0);w.useEffect(()=>{Ue?.connected!==void 0&&(dn.current=Ue.connected)},[Ue?.connected]);const gn=Ue?.connected??dn.current,Sn=w.useRef({});w.useEffect(()=>{Ue?.ams_extruder_map&&Object.keys(Ue.ams_extruder_map).length>0&&(Sn.current=Ue.ams_extruder_map)},[Ue?.ams_extruder_map]);const gr=Ue?.ams_extruder_map&&Object.keys(Ue.ams_extruder_map).length>0?Ue.ams_extruder_map:Sn.current,Dr=w.useRef([]);w.useEffect(()=>{Ue?.ams&&Ue.ams.length>0&&(Dr.current=Ue.ams)},[Ue?.ams]);const En=Ue?.ams&&Ue.ams.length>0?Ue.ams:Dr.current,Ea=w.useRef(void 0),Pn=Ue?.tray_now;Pn!==void 0&&Pn!==255?Ea.current=Pn:Pn===255&&(Ea.current=void 0);const na=Pn!==void 0&&Pn!==255?Pn:Ea.current,{data:qn}=Ye({queryKey:["smartPlugByPrinter",t.id],queryFn:()=>de.getSmartPlugByPrinter(t.id)}),{data:ra}=Ye({queryKey:["scriptPlugsByPrinter",t.id],queryFn:()=>de.getScriptPlugsByPrinter(t.id)}),{data:br}=Ye({queryKey:["smartPlugStatus",qn?.id],queryFn:()=>qn?de.getSmartPlugStatus(qn.id):null,enabled:!!qn,refetchInterval:1e4}),{data:ki}=Ye({queryKey:["queue",t.id,"pending"],queryFn:()=>de.getQueue(t.id,"pending")}),Ni=w.useMemo(()=>ki?.length?DJ(ki,vt,$e).length:0,[ki,vt,$e]),{data:Rm}=Ye({queryKey:["queue",t.id,"printing"],queryFn:()=>de.getQueue(t.id,"printing"),enabled:Ue?.state==="RUNNING"}),{data:au}=Ye({queryKey:["currentPrintUser",t.id],queryFn:()=>de.getCurrentPrintUser(t.id),enabled:Ue?.state==="RUNNING"}),_l=Rm?.[0]?.created_by_username||au?.username,{data:St}=Ye({queryKey:["archives",t.id,"last"],queryFn:()=>de.getArchives(t.id,1,0),enabled:Ue?.connected&&Ue?.state!=="RUNNING"}),Bn=St?.[0],mr=Ue?.state==="RUNNING"||Ue?.state==="PAUSE",qt=g&&Ue?.awaiting_plate_clear===!0,ad=Ue?.connected&&qt&&!mr,Bi=!g||!Ue?.connected?null:mr?{label:N("printers.plateStatus.inUse"),className:"bg-blue-500/20 text-blue-400"}:Ue.awaiting_plate_clear?{label:N("printers.plateStatus.notCleared"),className:"bg-yellow-500/20 text-yellow-400"}:{label:N("printers.plateStatus.cleared"),className:"bg-status-ok/20 text-status-ok"},yo=Bi?a.jsx("span",{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${Bi.className}`,children:Bi.label}):null,id=e&&gn===!1,li=it({mutationFn:mt=>de.deletePrinter(t.id,mt.deleteArchives),onSuccess:()=>{A.invalidateQueries({queryKey:["printers"]}),A.invalidateQueries({queryKey:["archives"]}),A.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:mt=>F(mt.message||N("printers.toast.failedToDelete"),"error")}),Ip=it({mutationFn:()=>de.connectPrinter(t.id),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]})}}),iu=it({mutationFn:()=>de.refreshPrinterStatus(t.id),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]}),F(N("printers.forceRefreshSuccess"),"success")},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),vc=it({mutationFn:mt=>de.unlinkSpool(mt),onSuccess:mt=>{F(N("spoolman.unlinkSuccess")||mt?.message,"success"),A.invalidateQueries({queryKey:["linked-spools"]}),A.invalidateQueries({queryKey:["unlinked-spools"]})},onError:mt=>{F(mt.message||N("spoolman.unlinkFailed"),"error")}}),Ns=it({mutationFn:({amsId:mt,temp:Ht,duration:Zt,filament:ct,rotateTray:Hn})=>de.startDrying(t.id,mt,Ht,Zt,ct,Hn),onSuccess:()=>{Le(null),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),kl=it({mutationFn:mt=>de.stopDrying(t.id,mt),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),ns=it({mutationFn:mt=>qn?de.controlSmartPlug(qn.id,mt):Promise.reject("No plug"),onSuccess:()=>{A.invalidateQueries({queryKey:["smartPlugStatus",qn?.id]})}}),$o=it({mutationFn:mt=>qn?de.updateSmartPlug(qn.id,{auto_off:mt}):Promise.reject("No plug"),onSuccess:()=>{A.invalidateQueries({queryKey:["smartPlugByPrinter",t.id]}),A.invalidateQueries({queryKey:["smart-plugs"]})}}),Nl=it({mutationFn:({id:mt,action:Ht})=>de.controlSmartPlug(mt,Ht),onSuccess:()=>{F(N("printers.toast.scriptTriggered"))},onError:mt=>F(mt.message||N("printers.toast.failedToRunScript"),"error")}),wc=it({mutationFn:()=>de.stopPrint(t.id),onSuccess:()=>{F(N("printers.toast.printStopped")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToStopPrint"),"error")}),vo=it({mutationFn:()=>de.pausePrint(t.id),onSuccess:()=>{F(N("printers.toast.printPaused")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToPausePrint"),"error")}),Sc=it({mutationFn:()=>de.resumePrint(t.id),onSuccess:()=>{F(N("printers.toast.printResumed")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToResumePrint"),"error")}),Vo=it({mutationFn:()=>de.clearPlate(t.id),onSuccess:()=>{F(N("queue.clearPlateSuccess")),A.setQueryData(["printerStatus",t.id],mt=>mt&&{...mt,awaiting_plate_clear:!1}),A.invalidateQueries({queryKey:["printerStatus",t.id]}),A.invalidateQueries({queryKey:["queue",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),zp=it({mutationFn:mt=>de.setChamberLight(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,chamber_light:mt})),{previousStatus:Ht}},onSuccess:(mt,Ht)=>{F(`Chamber light ${Ht?"on":"off"}`)},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToControlChamberLight"),"error")}}),Ci=it({mutationFn:mt=>de.setPrintSpeed(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,speed_level:mt})),{previousStatus:Ht}},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToSetSpeed"),"error")}}),_c=it({mutationFn:mt=>de.setAirductMode(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,airduct_mode:mt==="cooling"?0:1})),{previousStatus:Ht}},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToSendCommand"),"error")}}),su=it({mutationFn:({distance:mt,force:Ht})=>de.bedJog(t.id,mt,Ht??!1),onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),sd=it({mutationFn:mt=>de.homeAxes(t.id,mt),onSuccess:()=>F(N("printers.bedJog.homingStarted")),onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),od=it({mutationFn:mt=>de.updatePrinter(t.id,{plate_detection_enabled:mt}),onSuccess:()=>{A.invalidateQueries({queryKey:["printers"]}),F(od.variables?N("printers.toast.plateCheckEnabled"):N("printers.toast.plateCheckDisabled"))},onError:mt=>F(mt.message||N("printers.toast.failedToUpdateSetting"),"error")}),Go=(Ue?.state==="RUNNING"||Ue?.state==="PAUSE")&&(Ue?.printable_objects_count??0)>=2,{data:kc}=Ye({queryKey:["printableObjects",t.id],queryFn:()=>de.getPrintableObjects(t.id),enabled:R||Go,refetchInterval:R?5e3:Go?3e4:!1}),[Cs,Ps]=w.useState(null),Cl=w.useRef(!1),Ts=w.useRef(null),ld=w.useRef(!1),Up=it({mutationFn:({amsId:mt,slotId:Ht})=>de.refreshAmsSlot(t.id,mt,Ht),onMutate:({amsId:mt,slotId:Ht})=>{Ts.current&&clearTimeout(Ts.current),Cl.current=!1,ld.current=!1,Ps({amsId:mt,slotId:Ht}),setTimeout(()=>{ld.current=!0},2e3),Ts.current=setTimeout(()=>{Ps(null)},3e4)},onSuccess:mt=>{F(mt.message||N("printers.toast.rfidRereadInitiated"))},onError:mt=>{F(mt.message||N("printers.toast.failedToRereadRfid"),"error"),Ts.current&&clearTimeout(Ts.current),Ps(null)}}),[Xs,Bg]=w.useState(null),[fn,Lm]=w.useState(null),cd=async()=>{try{const mt=await de.getPlateReferences(t.id);Bg(mt)}catch{}},Hg=()=>{od.mutate(!t.plate_detection_enabled)},Om=async()=>{gt(!0),ze(null);const mt=Ue?.chamber_light===!1;Xe(mt),mt&&(await de.setChamberLight(t.id,!0),await new Promise(Ht=>setTimeout(Ht,2500)));try{const Ht=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Ht),cd()}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.failedToCheckPlate"),"error"),mt&&(await de.setChamberLight(t.id,!1),Xe(!1))}finally{gt(!1)}},Nc=w.useCallback(async()=>{ze(null),Ke&&(await de.setChamberLight(t.id,!1),Xe(!1))},[Ke,t.id]),qg=async mt=>{Ie(!0);try{const Ht=await de.calibratePlateDetection(t.id,{label:mt});if(Ht.success){F(Ht.message||N("printers.toast.calibrationSaved"),"success"),cd();const Zt=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Zt)}else F(Ht.message||N("printers.toast.calibrationFailed"),"error")}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.calibrationFailed"),"error")}finally{Ie(!1)}},Im=async(mt,Ht)=>{try{await de.updatePlateReferenceLabel(t.id,mt,Ht),Lm(null),cd()}catch(Zt){F(Zt instanceof Error?Zt.message:N("printers.toast.failedToUpdateLabel"),"error")}},$y=async mt=>{try{await de.deletePlateReference(t.id,mt),F(N("printers.toast.referenceDeleted"),"success"),cd();const Ht=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Ht)}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.failedToDeleteReference"),"error")}},dd=async()=>{if(ot){et(!0);try{await de.updatePrinter(t.id,{plate_detection_roi:ot}),F(N("printers.toast.detectionAreaSaved"),"success"),Ce(null);const mt=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(mt)}catch(mt){F(mt instanceof Error?mt.message:N("printers.toast.failedToSaveDetectionArea"),"error")}finally{et(!1)}}};w.useEffect(()=>{const mt=Ht=>{Ht.key==="Escape"&&Ft&&Nc()};return window.addEventListener("keydown",mt),()=>window.removeEventListener("keydown",mt)},[Ft,Nc]);const Wo=w.useRef(null);w.useEffect(()=>{if(!Cs)return;const mt=Ue?.ams_status_main??0;return mt!==0&&(Cl.current=!0,Wo.current&&(clearTimeout(Wo.current),Wo.current=null)),Cl.current&&mt===0&&(ld.current?(Ts.current&&clearTimeout(Ts.current),Ps(null)):Wo.current||(Wo.current=setTimeout(()=>{Ts.current&&clearTimeout(Ts.current),Ps(null)},2e3))),()=>{Wo.current&&clearTimeout(Wo.current)}},[Ue?.ams_status_main,Cs]);const[Ko,_e]=w.useState(null);if(id)return null;const Rt=()=>{switch(i){case 1:return"w-10 h-10";case 2:return"w-14 h-14";case 3:return"w-16 h-16";case 4:return"w-20 h-20";default:return"w-14 h-14"}},Rn=()=>{switch(i){case 1:return"text-base truncate";case 2:return"text-lg";case 3:return"text-xl";case 4:return"text-2xl";default:return"text-lg"}},Tn=()=>{switch(i){case 1:return"mb-2";case 2:return"mb-4";case 3:return"mb-5";case 4:return"mb-6";default:return"mb-4"}},Ln=gn&&Ue?.state!=="RUNNING"&&Ue?.state!=="PAUSE"&&k("printers:control"),xa=mt=>{mt.preventDefault(),Ut.current++,Ut.current===1&&pt(!0)},ci=mt=>{mt.preventDefault(),mt.dataTransfer.dropEffect=Ln?"copy":"none"},Lr=mt=>{mt.preventDefault(),Ut.current--,Ut.current===0&&pt(!1)},zm=async mt=>{if(mt.preventDefault(),Ut.current=0,pt(!1),!Ln)return;const Zt=Array.from(mt.dataTransfer.files)[0];if(!Zt)return;const ct=Zt.name.toLowerCase();if(!ct.endsWith(".gcode")&&!ct.includes(".gcode.")){F(N("printers.dropNotPrintable","Only .gcode and .gcode.3mf files can be printed"),"error");return}yt(!0);try{const Hn=await de.uploadLibraryFile(Zt,null),Pr=Hn.metadata?.sliced_for_model,ir=D0(t.model);if(Pr&&ir&&Pr.toLowerCase()!==ir.toLowerCase()){await de.deleteLibraryFile(Hn.id).catch(()=>{}),F(N("printers.incompatibleFile","This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}",{slicedFor:Pr,printerModel:ir}),"error");return}Re({id:Hn.id,filename:Hn.filename})}catch{F(N("common.uploadFailed","Upload failed"),"error")}finally{yt(!1)}};return a.jsxs(Tt,{className:`relative ${C?"ring-2 ring-bambu-green":""} ${_?"cursor-pointer":""}`,onDragEnter:xa,onDragOver:ci,onDragLeave:Lr,onDrop:zm,children:[_&&a.jsx("div",{className:"absolute inset-0 z-20 flex items-start p-2",onClick:mt=>{mt.stopPropagation(),P?.(t.id)},children:C?a.jsx(_s,{className:"w-5 h-5 text-bambu-green"}):a.jsx(uo,{className:"w-5 h-5 text-bambu-gray"})}),(Ze||xt)&&a.jsx("div",{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${xt?"bg-bambu-green/10 border-bambu-green/50":Ln?"bg-bambu-green/10 border-bambu-green":"bg-red-500/10 border-red-500/50"}`,children:a.jsx("div",{className:"text-center",children:xt?a.jsxs(a.Fragment,{children:[a.jsx(ft,{className:"w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin"}),a.jsx("p",{className:"text-sm font-medium text-bambu-green",children:N("common.uploading","Uploading...")})]}):Ln?a.jsxs(a.Fragment,{children:[a.jsx(Mr,{className:"w-8 h-8 mx-auto mb-2 text-bambu-green"}),a.jsx("p",{className:"text-sm font-medium text-bambu-green",children:N("printers.dropToPrint","Drop to print")})]}):a.jsxs(a.Fragment,{children:[a.jsx(Bt,{className:"w-8 h-8 mx-auto mb-2 text-red-400"}),a.jsx("p",{className:"text-sm font-medium text-red-400",children:N("printers.cannotPrint","Printer busy")})]})})}),a.jsxs(jt,{className:i>=3?"p-5":"",children:[a.jsxs("div",{className:Tn(),children:[a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("img",{src:MJ(t.model),alt:t.model||N("common.printer"),className:`object-contain rounded-lg bg-bambu-dark flex-shrink-0 ${Rt()}`}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h3",{className:`font-semibold text-white ${Rn()}`,children:t.name}),r==="compact"&&(()=>{const mt=Ue?.connected&&Ue.hms_errors?sm(Ue.hms_errors):[],Ht=mt.some(Pr=>Pr.severity<=2),Zt=mt.length>0,ct=Ue?.connected?Ht?"bg-status-error":Zt?"bg-status-warning":"bg-status-ok":"bg-status-error",Hn=Ue?.connected?Zt?`${mt.length} HMS ${mt.length===1?"error":"errors"}`:N("printers.connection.connected"):N("printers.connection.offline");return a.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 ${ct}`,title:Hn})})()]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[t.model||"Unknown Model",r==="expanded"&&Ue?.nozzles&&Ue.nozzles[0]?.nozzle_diameter&&a.jsxs("span",{className:"ml-1.5 text-bambu-gray",title:Ue.nozzles[0].nozzle_type||"Nozzle",children:["• ",Ue.nozzles[0].nozzle_diameter,"mm"]}),r==="expanded"&&n&&n.total_print_hours>0&&a.jsxs("span",{className:"ml-2 text-bambu-gray",children:[a.jsx(Qn,{className:"w-3 h-3 inline-block mr-1"}),Math.round(n.total_print_hours),"h"]})]})]})]}),a.jsxs("div",{className:"relative flex-shrink-0",children:[a.jsx(De,{variant:"ghost",size:"sm",onClick:()=>H(!D),children:a.jsx(Jh,{className:"w-4 h-4"})}),D&&a.jsxs("div",{className:"absolute right-0 mt-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20",children:[a.jsxs("button",{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${k("printers:update")?"hover:bg-bambu-dark-tertiary":"opacity-50 cursor-not-allowed"}`,onClick:()=>{k("printers:update")&&(J(!0),H(!1))},title:k("printers:update")?void 0:N("printers.permission.noEdit"),children:[a.jsx(oi,{className:"w-4 h-4"}),N("common.edit")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{Te(!0),H(!1)},children:[a.jsx(vs,{className:"w-4 h-4"}),N("printers.printerInformation")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{Ip.mutate(),H(!1)},children:[a.jsx(cr,{className:"w-4 h-4"}),N("printers.reconnect")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50",disabled:iu.isPending,onClick:()=>{iu.mutate(),H(!1)},children:[a.jsx(nw,{className:`w-4 h-4 ${iu.isPending?"animate-spin":""}`}),N("printers.forceRefresh")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{W(!0),H(!1)},children:[a.jsx(WQ,{className:"w-4 h-4"}),N("printers.mqttDebug")]}),a.jsxs("button",{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${k("printers:delete")?"text-red-400 hover:bg-bambu-dark-tertiary":"text-red-400/50 cursor-not-allowed"}`,onClick:()=>{k("printers:delete")&&(Y(!0),H(!1))},title:k("printers:delete")?void 0:N("printers.permission.noDelete"),children:[a.jsx(Jt,{className:"w-4 h-4"}),N("common.delete")]})]})]})]}),r==="expanded"&&a.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[a.jsxs("span",{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${Ue?.connected?"bg-status-ok/20 text-status-ok":"bg-status-error/20 text-status-error"}`,children:[Ue?.connected?a.jsx(_y,{className:"w-3 h-3"}):a.jsx(gp,{className:"w-3 h-3"}),Ue?.connected?N("printers.connection.connected"):N("printers.connection.offline")]}),Ue?.connected&&Ue?.wired_network&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok",title:N("printers.connection.ethernet","Ethernet"),children:[a.jsx(NO,{className:"w-3 h-3"}),N("printers.connection.ethernet","Ethernet")]}),Ue?.connected&&!Ue?.wired_network&&cn!=null&&a.jsxs("span",{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${cn>=-50||cn>=-60?"bg-status-ok/20 text-status-ok":cn>=-70?"bg-status-warning/20 text-status-warning":cn>=-80?"bg-orange-500/20 text-orange-600":"bg-status-error/20 text-status-error"}`,title:`WiFi: ${cn} dBm - ${N(EJ(cn).labelKey)}`,children:[a.jsx($Q,{className:"w-3 h-3"}),cn,"dBm"]}),Ue?.connected&&(()=>{const mt=Ue.hms_errors?sm(Ue.hms_errors):[];return a.jsxs("button",{onClick:()=>Q(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${mt.length>0?mt.some(Ht=>Ht.severity<=2)?"bg-status-error/20 text-status-error":"bg-status-warning/20 text-status-warning":"bg-status-ok/20 text-status-ok"}`,title:N("printers.clickToViewHmsErrors"),children:[a.jsx(Dn,{className:"w-3 h-3"}),mt.length>0?mt.length:"OK"]})})(),n&&a.jsxs("button",{onClick:()=>T("/maintenance"),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?"bg-status-error/20 text-status-error":n.warning_count>0?"bg-status-warning/20 text-status-warning":"bg-status-ok/20 text-status-ok"}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:""}${n.due_count>0&&n.warning_count>0?", ":""}${n.warning_count>0?`${n.warning_count} due soon`:""} - Click to view`:N("printers.maintenanceUpToDate"),children:[a.jsx(lg,{className:"w-3 h-3"}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:"OK"]}),Ni>0&&a.jsxs("button",{onClick:()=>T("/queue"),className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-500/20 text-indigo-400 hover:opacity-80 transition-opacity",title:N("printers.queue.inQueue",{count:Ni}),children:[a.jsx(ma,{className:"w-3 h-3"}),Ni]}),v&&Je?.current_version&&Je?.latest_version?a.jsxs("button",{onClick:()=>It(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${Je.update_available?"bg-orange-500/20 text-orange-400":"bg-status-ok/20 text-status-ok"}`,title:Je.update_available?N("printers.firmwareUpdateAvailable",{current:Je.current_version,latest:Je.latest_version}):N("printers.firmwareUpToDate",{version:Je.current_version}),children:[Je.update_available?a.jsx(ga,{className:"w-3 h-3"}):a.jsx(vr,{className:"w-3 h-3"}),Je.current_version]}):Ue?.firmware_version?a.jsx("span",{className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray",children:Ue.firmware_version}):null,Ue?.connected&&["X1C","X1","X1E","X2D","P1S","P1P","P2S","H2D","H2D Pro","H2C","H2S"].includes(t.model??"")&&a.jsx("span",{className:`flex items-center px-2 py-1 rounded-full text-xs ${Ue.door_open?"bg-yellow-500/20 text-yellow-400":"bg-status-ok/20 text-status-ok"}`,title:Ue.door_open?N("printers.door.open"):N("printers.door.closed"),children:Ue.door_open?a.jsx($fe,{className:"w-3 h-3"}):a.jsx(Hfe,{className:"w-3 h-3"})})]})]}),z&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsx(Tt,{className:"w-full max-w-md mx-4",children:a.jsxs(jt,{children:[a.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[a.jsx("div",{className:"p-2 rounded-full bg-red-500/20",children:a.jsx(Dn,{className:"w-5 h-5 text-red-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:N("printers.confirm.deleteTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:N("printers.confirm.deleteMessage",{name:t.name})})]})]}),a.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:a.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:L,onChange:mt=>te(mt.target.checked),className:"mt-0.5 w-4 h-4 rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:N("printers.deleteArchives")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:N(L?"printers.confirm.deleteArchivesNote":"printers.confirm.keepArchivesNote")})]})]})}),a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsx(De,{variant:"secondary",onClick:()=>{Y(!1),te(!0)},children:N("common.cancel")}),a.jsx(De,{variant:"danger",onClick:()=>{li.mutate({deleteArchives:L}),Y(!1),te(!0)},children:"Delete"})]})]})})}),Ue?.connected&&a.jsxs(a.Fragment,{children:[r==="compact"?a.jsx("div",{className:"mt-2",children:Ue.state==="RUNNING"||Ue.state==="PAUSE"?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5",children:a.jsx("div",{className:`${Ue.state==="PAUSE"?"bg-status-warning":"bg-bambu-green"} h-1.5 rounded-full transition-all`,style:{width:`${Ue.progress||0}%`}})}),a.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1.5",children:[a.jsxs("span",{className:"text-xs text-white",children:[Math.round(Ue.progress||0),"%"]}),yo]})]}):a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[a.jsx("p",{className:"min-w-0 truncate text-xs text-bambu-gray",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),ad&&a.jsx("button",{type:"button",onClick:()=>Vo.mutate(),disabled:Vo.isPending||!k("printers:clear_plate"),"aria-label":N("printers.plateStatus.markCleared"),className:"inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full bg-yellow-500/20 border border-yellow-400/40 text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50",title:k("printers:clear_plate")?N("printers.plateStatus.markCleared"):N("printers.permission.noControl"),children:Vo.isPending?a.jsx(ft,{className:"w-3 h-3 animate-spin"}):a.jsx(ZW,{className:"w-3 h-3"})})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-4 p-3 bg-bambu-dark rounded-lg relative",children:[a.jsxs("button",{onClick:()=>ae(!0),disabled:!(Ue.state==="RUNNING"||Ue.state==="PAUSE")||(Ue.printable_objects_count??0)<2||!k("printers:control"),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${(Ue.state==="RUNNING"||Ue.state==="PAUSE")&&(Ue.printable_objects_count??0)>=2&&k("printers:control")?"text-bambu-gray hover:text-white hover:bg-white/10":"text-bambu-gray/30 cursor-not-allowed"}`,title:k("printers:control")?Ue.state==="RUNNING"||Ue.state==="PAUSE"?(Ue.printable_objects_count??0)>=2?N("printers.skipObjects.tooltip"):N("printers.skipObjects.requiresMultiple"):N("printers.skipObjects.onlyWhilePrinting"):N("printers.permission.noControl"),children:[a.jsx(rT,{className:"w-4 h-4"}),kc&&kc.skipped_count>0&&a.jsx("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-bold bg-red-500 text-white rounded-full",children:kc.skipped_count})]}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(R7e,{url:Ue.state==="RUNNING"||Ue.state==="PAUSE"?Ue.cover_url:null,printName:(Ue.state==="RUNNING"||Ue.state==="PAUSE")&&iK(Ue.subtask_name||Ue.current_print||null,Ue.gcode_file,N)||void 0}),a.jsx("div",{className:"flex-1 min-w-0",children:Ue.current_print&&(Ue.state==="RUNNING"||Ue.state==="PAUSE")?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),a.jsx("p",{className:"text-white text-sm mb-2 truncate",children:iK(Ue.subtask_name||Ue.current_print||null,Ue.gcode_file,N)}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-2 mr-3",children:a.jsx("div",{className:`${Ue.state==="PAUSE"?"bg-status-warning":"bg-bambu-green"} h-2 rounded-full transition-all`,style:{width:`${Ue.progress||0}%`}})}),a.jsxs("span",{className:"text-white",children:[Math.round(Ue.progress||0),"%"]})]}),a.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-bambu-gray",children:[Ue.remaining_time!=null&&Ue.remaining_time>0&&a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(Qn,{className:"w-3 h-3"}),ys(Ue.remaining_time*60)]}),a.jsxs("span",{className:"text-bambu-green font-medium",title:N("printers.estimatedCompletion"),children:["ETA ",zO(Ue.remaining_time,p,N)]})]}),Ue.layer_num!=null&&Ue.total_layers!=null&&Ue.total_layers>0&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(ma,{className:"w-3 h-3"}),Ue.layer_num,"/",Ue.total_layers]}),_l&&a.jsxs("span",{className:"flex items-center gap-1",title:`Started by ${_l}`,children:[a.jsx(xm,{className:"w-3 h-3"}),_l]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-1",children:N("printers.sort.status")}),a.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[a.jsx("p",{className:"text-white text-sm",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-2 mr-3",children:a.jsx("div",{className:"bg-bambu-dark-tertiary h-2 rounded-full"})}),a.jsx("span",{className:"text-bambu-gray",children:"—"})]}),Bn?a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 truncate",title:Bn.print_name||Bn.filename,children:["Last: ",Bn.print_name||Bn.filename,Bn.completed_at&&a.jsxs("span",{className:"ml-1 text-bambu-gray/60",children:["• ",cg(Bn.completed_at,{month:"short",day:"numeric"})]})]}):a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:N("printers.readyToPrint")})]})})]})]}),a.jsx(YMe,{printerId:t.id,printerModel:t.model,printerState:Ue.state,awaitingPlateClear:Ue.awaiting_plate_clear,requirePlateClear:g,loadedFilamentTypes:vt,loadedFilaments:$e})]}),Ue.temperatures&&r==="expanded"&&(()=>{const mt=Ue.temperatures.nozzle_heating||Ue.temperatures.nozzle_2_heating||!1,Ht=Ue.temperatures.bed_heating||!1,Zt=Ue.temperatures.chamber_heating||!1,ct=t.nozzle_count===2||Ue.temperatures.nozzle_2!==void 0,Hn=Ue.active_extruder===1?"L":"R",Pr=Ue.nozzle_rack?.find(ka=>ka.id===1),ir=Ue.nozzle_rack?.find(ka=>ka.id===0),aa=ir||Pr;return a.jsxs("div",{className:"flex items-stretch gap-1.5 flex-wrap",children:[a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-orange-400",isHeating:mt}),Ue.temperatures.nozzle_2!==void 0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:"L / R"}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"° / ",Math.round(Ue.temperatures.nozzle_2||0),"°"]})]}):aa?a.jsx(rie,{slot:aa,index:0,activeStatus:!0,filamentName:aa.filament_id?wt?.[aa.filament_id]?.name:void 0,children:a.jsxs("div",{className:"cursor-default",children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"°C"]})]})}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"°C"]})]})]}),a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-blue-400",isHeating:Ht}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.bed")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.bed||0),"°C"]})]}),Ue.temperatures.chamber!==void 0&&a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-green-400",isHeating:Zt}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.chamber")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.chamber||0),"°C"]})]}),ct&&a.jsx(T7e,{leftSlot:Pr,rightSlot:ir,activeNozzle:Hn,filamentInfo:wt,children:a.jsxs("div",{className:"text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center cursor-default",title:N("printers.activeNozzle",{nozzle:N(Hn==="L"?"common.left":"common.right")}),children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsxs("span",{className:`text-[11px] font-bold ${Hn==="L"?"text-amber-400":"text-gray-500"}`,children:["L",Pr?.nozzle_diameter?` ${Pr.nozzle_diameter}`:""]}),a.jsx("span",{className:"text-[9px] text-bambu-gray/40",children:"·"}),a.jsxs("span",{className:`text-[11px] font-bold ${Hn==="R"?"text-amber-400":"text-gray-500"}`,children:["R",ir?.nozzle_diameter?` ${ir.nozzle_diameter}`:""]})]}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")})]})}),Ue.nozzle_rack&&Ue.nozzle_rack.some(ka=>ka.id>=2)&&a.jsx(A7e,{slots:Ue.nozzle_rack,filamentInfo:wt})]})})(),r==="expanded"&&ad&&a.jsxs("button",{type:"button",onClick:()=>Vo.mutate(),disabled:Vo.isPending||!k("printers:clear_plate"),className:"mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-500/20 border border-yellow-400/40 text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50",title:k("printers:clear_plate")?N("printers.plateStatus.markCleared"):N("printers.permission.noControl"),children:[Vo.isPending?a.jsx(ft,{className:"w-3 h-3 animate-spin"}):a.jsx(ZW,{className:"w-4 h-4"}),N("printers.plateStatus.markCleared")]}),r==="expanded"&&(()=>{const mt=Ue.state==="RUNNING",Ht=Ue.state==="PAUSE",Zt=mt||Ht,ct=wc.isPending||vo.isPending||Sc.isPending,Hn=Ue.cooling_fan_speed,Pr=Ue.big_fan1_speed,ir=Ue.big_fan2_speed;return a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx("span",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:N("printers.controls")}),a.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary/30"})]}),a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-2 gap-y-2",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 min-w-0",children:[a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${Hn&&Hn>0?"bg-cyan-500/10":"bg-bambu-dark"}`,title:N("printers.fans.partCooling"),children:[a.jsx(RQ,{className:`w-3.5 h-3.5 ${Hn&&Hn>0?"text-cyan-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${Hn&&Hn>0?"text-cyan-400":"text-bambu-gray/50"}`,children:[Hn??0,"%"]})]}),a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${Pr&&Pr>0?"bg-blue-500/10":"bg-bambu-dark"}`,title:N("printers.fans.auxiliary"),children:[a.jsx(YQ,{className:`w-3.5 h-3.5 ${Pr&&Pr>0?"text-blue-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${Pr&&Pr>0?"text-blue-400":"text-bambu-gray/50"}`,children:[Pr??0,"%"]})]}),a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${ir&&ir>0?"bg-green-500/10":"bg-bambu-dark"}`,title:N("printers.fans.chamber"),children:[a.jsx(mpe,{className:`w-3.5 h-3.5 ${ir&&ir>0?"text-green-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${ir&&ir>0?"text-green-400":"text-bambu-gray/50"}`,children:[ir??0,"%"]})]}),a.jsx("div",{className:"w-px h-5 bg-bambu-gray/30"}),["P2S","X2D","H2D","H2C","H2S"].includes(t.model??"")&&(()=>{const aa=Ue.airduct_mode===1,ka=aa?Bu:TH,an=aa?"text-orange-400":"text-sky-400",wn=aa?"bg-orange-500/10 hover:bg-orange-500/20":"bg-sky-500/10 hover:bg-sky-500/20";return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>G(I===t.id?null:t.id),disabled:!k("printers:control"),className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${wn} disabled:opacity-50 disabled:cursor-not-allowed`,title:N("printers.airduct.title"),children:[a.jsx(ka,{className:`w-3.5 h-3.5 ${an}`}),a.jsx("span",{className:`text-[10px] ${an}`,children:N(aa?"printers.airduct.heating":"printers.airduct.cooling")})]}),I===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>G(null)}),a.jsx("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]",children:[{mode:"cooling",label:N("printers.airduct.cooling"),modeId:0},{mode:"heating",label:N("printers.airduct.heating"),modeId:1}].map(({mode:Da,label:di,modeId:As})=>a.jsxs("button",{onClick:()=>{_c.mutate(Da),G(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${Ue.airduct_mode===As?"text-bambu-green bg-bambu-green/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[Da==="heating"?a.jsx(Bu,{className:"w-3 h-3"}):a.jsx(TH,{className:"w-3 h-3"}),di]},Da))})]})]})})(),(()=>{const ka={1:"50%",2:"100%",3:"124%",4:"166%"}[Ue.speed_level]||"100%";return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>ue(U===t.id?null:t.id),disabled:!Zt||!k("printers:control"),className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${Zt?"bg-amber-500/10 hover:bg-amber-500/20":"bg-bambu-dark cursor-not-allowed"}`,title:Zt?N("printers.speed.title"):void 0,children:[a.jsx(Kw,{className:`w-3.5 h-3.5 ${Zt?"text-amber-400":"text-bambu-gray/50"}`}),a.jsx("span",{className:`text-[10px] ${Zt?"text-amber-400":"text-bambu-gray/50"}`,children:ka})]}),U===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>ue(null)}),a.jsx("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]",children:[{mode:1,label:N("printers.speed.silent")},{mode:2,label:N("printers.speed.standard")},{mode:3,label:N("printers.speed.sport")},{mode:4,label:N("printers.speed.ludicrous")}].map(({mode:an,label:wn})=>a.jsx("button",{onClick:()=>{Ci.mutate(an),ue(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${Ue.speed_level===an?"text-bambu-green bg-bambu-green/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:wn},an))})]})]})})(),a.jsx("div",{className:"w-px h-5 bg-bambu-gray/30"}),(()=>{const aa=k("printers:control"),ka=Zt||!aa,an=wn=>{const Da=wn*ee*1,di=`bambuddy.bedJog.warned.${t.id}`,As=(()=>{try{return sessionStorage.getItem(di)==="1"}catch{return!1}})();V(null),As?su.mutate({distance:Da,force:!0}):pe({distance:Da})};return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>V(X===t.id?null:t.id),disabled:ka,className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${ka?"bg-bambu-dark cursor-not-allowed":"bg-indigo-500/10 hover:bg-indigo-500/20"}`,title:N(aa?Zt?"printers.bedJog.disabledWhilePrinting":"printers.bedJog.title":"printers.permission.noControl"),children:[a.jsx(Tbe,{className:`w-3.5 h-3.5 ${ka?"text-bambu-gray/50":"text-indigo-400"}`}),a.jsx("span",{className:`text-[10px] ${ka?"text-bambu-gray/50":"text-indigo-400"}`,children:N("printers.bedJog.bed")}),a.jsxs("span",{className:`text-[10px] tabular-nums opacity-70 ${ka?"text-bambu-gray/50":"text-indigo-400"}`,children:[ee,"mm"]})]}),X===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>V(null)}),a.jsxs("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-2 min-w-[140px]",children:[a.jsxs("div",{className:"flex items-center justify-between gap-1 mb-2",children:[a.jsx("button",{onClick:()=>an(-1),className:"flex-1 flex items-center justify-center py-1.5 rounded bg-indigo-500/15 hover:bg-indigo-500/30 text-indigo-300","aria-label":N("printers.bedJog.up"),children:a.jsx(fp,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>an(1),className:"flex-1 flex items-center justify-center py-1.5 rounded bg-indigo-500/15 hover:bg-indigo-500/30 text-indigo-300","aria-label":N("printers.bedJog.down"),children:a.jsx(ig,{className:"w-4 h-4"})})]}),a.jsx("div",{className:"text-[9px] uppercase tracking-wider text-bambu-gray/70 px-1 mb-1",children:N("printers.bedJog.step")}),a.jsx("div",{className:"flex gap-1",children:[1,10,50].map(wn=>a.jsx("button",{onClick:()=>se(wn),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${ee===wn?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:wn},wn))})]})]})]})})()]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 max-[550px]:self-start",children:[a.jsxs("button",{onClick:()=>j(!0),disabled:!Zt||ct||!k("printers:control"),className:` + `,style:{maxWidth:"calc(100vw - 24px)"},onMouseEnter:T,onMouseLeave:F,children:a.jsxs("div",{className:"w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2",children:[a.jsx("div",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:n}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx("span",{className:"text-[10px] tracking-wide text-bambu-gray font-medium shrink-0",children:l("printers.amsPopup.serialNumber")}),a.jsx("span",{className:"text-[10px] text-white font-mono truncate",children:t.serial_number||"—"})]}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx("span",{className:"text-[10px] tracking-wide text-bambu-gray font-medium shrink-0",children:l("printers.amsPopup.firmwareVersion")}),a.jsx("span",{className:"text-[10px] text-white font-mono truncate",children:t.sw_ver||"—"})]}),a.jsx("div",{className:"h-px bg-bambu-dark-tertiary/50"}),a.jsxs("div",{className:"space-y-1",children:[a.jsx("span",{className:"text-[10px] text-bambu-gray font-medium block",children:l("printers.amsPopup.friendlyName")}),a.jsx("input",{type:"text",value:p,onChange:H=>i&&f(H.target.value),onKeyDown:H=>H.key==="Enter"&&k(),onFocus:()=>C(!0),onBlur:()=>{C(!1),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>d(!1),200)},placeholder:i?l("printers.amsPopup.friendlyNamePlaceholder"):r?.[t.id]||"—",disabled:!i,title:i?void 0:l("printers.amsPopup.noEditPermission"),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed",maxLength:100}),i&&a.jsxs("div",{className:"space-y-1",children:[b&&a.jsx("p",{className:"text-[10px] text-red-400 break-words",children:b}),a.jsxs("div",{className:"flex gap-1 justify-end",children:[a.jsx("button",{onClick:k,disabled:x,className:"px-2 py-0.5 text-[10px] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50",children:l("printers.amsPopup.save")}),r?.[t.id]&&a.jsx("button",{onClick:D,disabled:x,className:"px-2 py-0.5 text-[10px] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50",children:l("printers.amsPopup.clear")})]})]})]})]})})]})}const bL={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};function hK({printer:t,hideIfDisconnected:e,maintenanceInfo:n,viewMode:r="expanded",cardSize:i=2,amsThresholds:s,spoolmanEnabled:o=!1,linkedSpools:l,spoolmanUrl:c,spoolmanSyncMode:d,onGetAssignment:u,onUnassignSpool:m,timeFormat:p="system",cameraViewMode:f="window",onOpenEmbeddedCamera:x,checkPrinterFirmware:v=!0,dryingPresets:b=bL,requirePlateClear:g=!1,selectionMode:_=!1,isSelected:C=!1,onToggleSelect:P}){const{t:N}=Dt(),A=nn(),T=Uo(),{showToast:F}=hn(),{hasPermission:k}=_r(),[D,H]=w.useState(!1),[z,Y]=w.useState(!1),[L,te]=w.useState(!0),[ie,J]=w.useState(!1),[oe,fe]=w.useState(!1),[re,W]=w.useState(!1),[ne,me]=w.useState(!1),[be,Pe]=w.useState(!1),[q,Q]=w.useState(!1),[E,j]=w.useState(!1),[O,K]=w.useState(!1),[U,ue]=w.useState(null),[I,G]=w.useState(null),[X,V]=w.useState(null),[ee,se]=w.useState(10),[ge,pe]=w.useState(null),[le,B]=w.useState(!1),[R,ae]=w.useState(!1),[ke,Se]=w.useState(!1),[ye,Te]=w.useState(!1),ve=w.useCallback(()=>Te(!1),[]),[Ae,Re]=w.useState(null),[Me,Le]=w.useState(null),[Oe,qe]=w.useState("n3f"),[Qe,tt]=w.useState("PLA"),[he,Fe]=w.useState(50),[we,Ve]=w.useState(4),[je,ce]=w.useState(!1),[xe,Be]=w.useState(null),[Ze,pt]=w.useState(!1),[xt,yt]=w.useState(!1),Ut=w.useRef(0),[Kt,en]=w.useState(null),[Vt,Yt]=w.useState(null),[rn,Nn]=w.useState(null),[We,at]=w.useState(null),[dt,It]=w.useState(!1),[Ft,ze]=w.useState(null),[lt,gt]=w.useState(!1),[rt,Ie]=w.useState(!1),[ot,Ce]=w.useState(null),[Ge,et]=w.useState(!1),[Ke,Xe]=w.useState(!1),{data:Ue}=Ye({queryKey:["printerStatus",t.id],queryFn:()=>de.getPrinterStatus(t.id),refetchInterval:3e4}),{data:Je}=Ye({queryKey:["firmwareUpdate",t.id],queryFn:()=>Ok.checkPrinterUpdate(t.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:v&&k("firmware:read")}),At=w.useMemo(()=>{const mt=new Set;if(Ue?.ams)for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])Zt.tray_info_idx&&mt.add(Zt.tray_info_idx);for(const Ht of Ue?.vt_tray??[])Ht.tray_info_idx&&mt.add(Ht.tray_info_idx);if(Ue?.nozzle_rack)for(const Ht of Ue.nozzle_rack)Ht.filament_id&&mt.add(Ht.filament_id);return Array.from(mt)},[Ue?.ams,Ue?.vt_tray,Ue?.nozzle_rack]),vt=w.useMemo(()=>{const mt=new Set;if(Ue?.ams)for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])Zt.tray_type&&mt.add(Zt.tray_type.toUpperCase());for(const Ht of Ue?.vt_tray??[])Ht.tray_type&&mt.add(Ht.tray_type.toUpperCase());return mt},[Ue?.ams,Ue?.vt_tray]),$e=w.useMemo(()=>{const mt=new Set;if(Ue?.ams){for(const Ht of Ue.ams)for(const Zt of Ht.tray||[])if(Zt.tray_type&&Zt.tray_color){const ct=Zt.tray_color.replace("#","").toLowerCase().slice(0,6);mt.add(`${Zt.tray_type.toUpperCase()}:${ct}`)}}for(const Ht of Ue?.vt_tray??[])if(Ht.tray_type&&Ht.tray_color){const Zt=Ht.tray_color.replace("#","").toLowerCase().slice(0,6);mt.add(`${Ht.tray_type.toUpperCase()}:${Zt}`)}return mt},[Ue?.ams,Ue?.vt_tray]),{data:wt}=Ye({queryKey:["filamentInfo",At],queryFn:()=>de.getFilamentInfo(At),enabled:At.length>0,staleTime:300*1e3}),{data:Mt}=Ye({queryKey:["slotPresets",t.id],queryFn:()=>de.getSlotPresets(t.id),staleTime:120*1e3}),{data:Gt,refetch:sn}=Ye({queryKey:["amsLabels",t.id],queryFn:()=>de.getAmsLabels(t.id),staleTime:300*1e3}),[pn,zn]=w.useState(null);w.useEffect(()=>{Ue?.wifi_signal!=null&&zn(Ue.wifi_signal)},[Ue?.wifi_signal]);const cn=Ue?.wifi_signal??pn,dn=w.useRef(void 0);w.useEffect(()=>{Ue?.connected!==void 0&&(dn.current=Ue.connected)},[Ue?.connected]);const gn=Ue?.connected??dn.current,Sn=w.useRef({});w.useEffect(()=>{Ue?.ams_extruder_map&&Object.keys(Ue.ams_extruder_map).length>0&&(Sn.current=Ue.ams_extruder_map)},[Ue?.ams_extruder_map]);const gr=Ue?.ams_extruder_map&&Object.keys(Ue.ams_extruder_map).length>0?Ue.ams_extruder_map:Sn.current,Dr=w.useRef([]);w.useEffect(()=>{Ue?.ams&&Ue.ams.length>0&&(Dr.current=Ue.ams)},[Ue?.ams]);const En=Ue?.ams&&Ue.ams.length>0?Ue.ams:Dr.current,Ea=w.useRef(void 0),Pn=Ue?.tray_now;Pn!==void 0&&Pn!==255?Ea.current=Pn:Pn===255&&(Ea.current=void 0);const na=Pn!==void 0&&Pn!==255?Pn:Ea.current,{data:qn}=Ye({queryKey:["smartPlugByPrinter",t.id],queryFn:()=>de.getSmartPlugByPrinter(t.id)}),{data:ra}=Ye({queryKey:["scriptPlugsByPrinter",t.id],queryFn:()=>de.getScriptPlugsByPrinter(t.id)}),{data:br}=Ye({queryKey:["smartPlugStatus",qn?.id],queryFn:()=>qn?de.getSmartPlugStatus(qn.id):null,enabled:!!qn,refetchInterval:1e4}),{data:ki}=Ye({queryKey:["queue",t.id,"pending"],queryFn:()=>de.getQueue(t.id,"pending")}),Ni=w.useMemo(()=>ki?.length?DJ(ki,vt,$e).length:0,[ki,vt,$e]),{data:Rm}=Ye({queryKey:["queue",t.id,"printing"],queryFn:()=>de.getQueue(t.id,"printing"),enabled:Ue?.state==="RUNNING"}),{data:au}=Ye({queryKey:["currentPrintUser",t.id],queryFn:()=>de.getCurrentPrintUser(t.id),enabled:Ue?.state==="RUNNING"}),_l=Rm?.[0]?.created_by_username||au?.username,{data:St}=Ye({queryKey:["archives",t.id,"last"],queryFn:()=>de.getArchives(t.id,1,0),enabled:Ue?.connected&&Ue?.state!=="RUNNING"}),Bn=St?.[0],mr=Ue?.state==="RUNNING"||Ue?.state==="PAUSE",qt=g&&Ue?.awaiting_plate_clear===!0,ad=Ue?.connected&&qt&&!mr,Bi=!g||!Ue?.connected?null:mr?{label:N("printers.plateStatus.inUse"),className:"bg-blue-500/20 text-blue-400"}:Ue.awaiting_plate_clear?{label:N("printers.plateStatus.notCleared"),className:"bg-yellow-500/20 text-yellow-400"}:{label:N("printers.plateStatus.cleared"),className:"bg-status-ok/20 text-status-ok"},yo=Bi?a.jsx("span",{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${Bi.className}`,children:Bi.label}):null,id=e&&gn===!1,li=it({mutationFn:mt=>de.deletePrinter(t.id,mt.deleteArchives),onSuccess:()=>{A.invalidateQueries({queryKey:["printers"]}),A.invalidateQueries({queryKey:["archives"]}),A.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:mt=>F(mt.message||N("printers.toast.failedToDelete"),"error")}),Ip=it({mutationFn:()=>de.connectPrinter(t.id),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]})}}),iu=it({mutationFn:()=>de.refreshPrinterStatus(t.id),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]}),F(N("printers.forceRefreshSuccess"),"success")},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),vc=it({mutationFn:mt=>de.unlinkSpool(mt),onSuccess:mt=>{F(N("spoolman.unlinkSuccess")||mt?.message,"success"),A.invalidateQueries({queryKey:["linked-spools"]}),A.invalidateQueries({queryKey:["unlinked-spools"]})},onError:mt=>{F(mt.message||N("spoolman.unlinkFailed"),"error")}}),Ns=it({mutationFn:({amsId:mt,temp:Ht,duration:Zt,filament:ct,rotateTray:Hn})=>de.startDrying(t.id,mt,Ht,Zt,ct,Hn),onSuccess:()=>{Le(null),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),kl=it({mutationFn:mt=>de.stopDrying(t.id,mt),onSuccess:()=>{A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),ns=it({mutationFn:mt=>qn?de.controlSmartPlug(qn.id,mt):Promise.reject("No plug"),onSuccess:()=>{A.invalidateQueries({queryKey:["smartPlugStatus",qn?.id]})}}),$o=it({mutationFn:mt=>qn?de.updateSmartPlug(qn.id,{auto_off:mt}):Promise.reject("No plug"),onSuccess:()=>{A.invalidateQueries({queryKey:["smartPlugByPrinter",t.id]}),A.invalidateQueries({queryKey:["smart-plugs"]})}}),Nl=it({mutationFn:({id:mt,action:Ht})=>de.controlSmartPlug(mt,Ht),onSuccess:()=>{F(N("printers.toast.scriptTriggered"))},onError:mt=>F(mt.message||N("printers.toast.failedToRunScript"),"error")}),wc=it({mutationFn:()=>de.stopPrint(t.id),onSuccess:()=>{F(N("printers.toast.printStopped")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToStopPrint"),"error")}),vo=it({mutationFn:()=>de.pausePrint(t.id),onSuccess:()=>{F(N("printers.toast.printPaused")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToPausePrint"),"error")}),Sc=it({mutationFn:()=>de.resumePrint(t.id),onSuccess:()=>{F(N("printers.toast.printResumed")),A.invalidateQueries({queryKey:["printerStatus",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToResumePrint"),"error")}),Vo=it({mutationFn:()=>de.clearPlate(t.id),onSuccess:()=>{F(N("queue.clearPlateSuccess")),A.setQueryData(["printerStatus",t.id],mt=>mt&&{...mt,awaiting_plate_clear:!1}),A.invalidateQueries({queryKey:["printerStatus",t.id]}),A.invalidateQueries({queryKey:["queue",t.id]})},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),zp=it({mutationFn:mt=>de.setChamberLight(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,chamber_light:mt})),{previousStatus:Ht}},onSuccess:(mt,Ht)=>{F(`Chamber light ${Ht?"on":"off"}`)},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToControlChamberLight"),"error")}}),Ci=it({mutationFn:mt=>de.setPrintSpeed(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,speed_level:mt})),{previousStatus:Ht}},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToSetSpeed"),"error")}}),_c=it({mutationFn:mt=>de.setAirductMode(t.id,mt),onMutate:async mt=>{await A.cancelQueries({queryKey:["printerStatus",t.id]});const Ht=A.getQueryData(["printerStatus",t.id]);return A.setQueryData(["printerStatus",t.id],Zt=>({...Zt,airduct_mode:mt==="cooling"?0:1})),{previousStatus:Ht}},onError:(mt,Ht,Zt)=>{Zt?.previousStatus&&A.setQueryData(["printerStatus",t.id],Zt.previousStatus),F(mt.message||N("printers.toast.failedToSendCommand"),"error")}}),su=it({mutationFn:({distance:mt,force:Ht})=>de.bedJog(t.id,mt,Ht??!1),onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),sd=it({mutationFn:mt=>de.homeAxes(t.id,mt),onSuccess:()=>{try{sessionStorage.setItem(`bambuddy.bedJog.warned.${t.id}`,"1")}catch{}F(N("printers.bedJog.homingStarted"))},onError:mt=>F(mt.message||N("printers.toast.failedToSendCommand"),"error")}),od=it({mutationFn:mt=>de.updatePrinter(t.id,{plate_detection_enabled:mt}),onSuccess:()=>{A.invalidateQueries({queryKey:["printers"]}),F(od.variables?N("printers.toast.plateCheckEnabled"):N("printers.toast.plateCheckDisabled"))},onError:mt=>F(mt.message||N("printers.toast.failedToUpdateSetting"),"error")}),Go=(Ue?.state==="RUNNING"||Ue?.state==="PAUSE")&&(Ue?.printable_objects_count??0)>=2,{data:kc}=Ye({queryKey:["printableObjects",t.id],queryFn:()=>de.getPrintableObjects(t.id),enabled:R||Go,refetchInterval:R?5e3:Go?3e4:!1}),[Cs,Ps]=w.useState(null),Cl=w.useRef(!1),Ts=w.useRef(null),ld=w.useRef(!1),Up=it({mutationFn:({amsId:mt,slotId:Ht})=>de.refreshAmsSlot(t.id,mt,Ht),onMutate:({amsId:mt,slotId:Ht})=>{Ts.current&&clearTimeout(Ts.current),Cl.current=!1,ld.current=!1,Ps({amsId:mt,slotId:Ht}),setTimeout(()=>{ld.current=!0},2e3),Ts.current=setTimeout(()=>{Ps(null)},3e4)},onSuccess:mt=>{F(mt.message||N("printers.toast.rfidRereadInitiated"))},onError:mt=>{F(mt.message||N("printers.toast.failedToRereadRfid"),"error"),Ts.current&&clearTimeout(Ts.current),Ps(null)}}),[Xs,Bg]=w.useState(null),[fn,Lm]=w.useState(null),cd=async()=>{try{const mt=await de.getPlateReferences(t.id);Bg(mt)}catch{}},Hg=()=>{od.mutate(!t.plate_detection_enabled)},Om=async()=>{gt(!0),ze(null);const mt=Ue?.chamber_light===!1;Xe(mt),mt&&(await de.setChamberLight(t.id,!0),await new Promise(Ht=>setTimeout(Ht,2500)));try{const Ht=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Ht),cd()}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.failedToCheckPlate"),"error"),mt&&(await de.setChamberLight(t.id,!1),Xe(!1))}finally{gt(!1)}},Nc=w.useCallback(async()=>{ze(null),Ke&&(await de.setChamberLight(t.id,!1),Xe(!1))},[Ke,t.id]),qg=async mt=>{Ie(!0);try{const Ht=await de.calibratePlateDetection(t.id,{label:mt});if(Ht.success){F(Ht.message||N("printers.toast.calibrationSaved"),"success"),cd();const Zt=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Zt)}else F(Ht.message||N("printers.toast.calibrationFailed"),"error")}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.calibrationFailed"),"error")}finally{Ie(!1)}},Im=async(mt,Ht)=>{try{await de.updatePlateReferenceLabel(t.id,mt,Ht),Lm(null),cd()}catch(Zt){F(Zt instanceof Error?Zt.message:N("printers.toast.failedToUpdateLabel"),"error")}},$y=async mt=>{try{await de.deletePlateReference(t.id,mt),F(N("printers.toast.referenceDeleted"),"success"),cd();const Ht=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(Ht)}catch(Ht){F(Ht instanceof Error?Ht.message:N("printers.toast.failedToDeleteReference"),"error")}},dd=async()=>{if(ot){et(!0);try{await de.updatePrinter(t.id,{plate_detection_roi:ot}),F(N("printers.toast.detectionAreaSaved"),"success"),Ce(null);const mt=await de.checkPlateEmpty(t.id,{includeDebugImage:!0});ze(mt)}catch(mt){F(mt instanceof Error?mt.message:N("printers.toast.failedToSaveDetectionArea"),"error")}finally{et(!1)}}};w.useEffect(()=>{const mt=Ht=>{Ht.key==="Escape"&&Ft&&Nc()};return window.addEventListener("keydown",mt),()=>window.removeEventListener("keydown",mt)},[Ft,Nc]);const Wo=w.useRef(null);w.useEffect(()=>{if(!Cs)return;const mt=Ue?.ams_status_main??0;return mt!==0&&(Cl.current=!0,Wo.current&&(clearTimeout(Wo.current),Wo.current=null)),Cl.current&&mt===0&&(ld.current?(Ts.current&&clearTimeout(Ts.current),Ps(null)):Wo.current||(Wo.current=setTimeout(()=>{Ts.current&&clearTimeout(Ts.current),Ps(null)},2e3))),()=>{Wo.current&&clearTimeout(Wo.current)}},[Ue?.ams_status_main,Cs]);const[Ko,_e]=w.useState(null);if(id)return null;const Rt=()=>{switch(i){case 1:return"w-10 h-10";case 2:return"w-14 h-14";case 3:return"w-16 h-16";case 4:return"w-20 h-20";default:return"w-14 h-14"}},Rn=()=>{switch(i){case 1:return"text-base truncate";case 2:return"text-lg";case 3:return"text-xl";case 4:return"text-2xl";default:return"text-lg"}},Tn=()=>{switch(i){case 1:return"mb-2";case 2:return"mb-4";case 3:return"mb-5";case 4:return"mb-6";default:return"mb-4"}},Ln=gn&&Ue?.state!=="RUNNING"&&Ue?.state!=="PAUSE"&&k("printers:control"),xa=mt=>{mt.preventDefault(),Ut.current++,Ut.current===1&&pt(!0)},ci=mt=>{mt.preventDefault(),mt.dataTransfer.dropEffect=Ln?"copy":"none"},Lr=mt=>{mt.preventDefault(),Ut.current--,Ut.current===0&&pt(!1)},zm=async mt=>{if(mt.preventDefault(),Ut.current=0,pt(!1),!Ln)return;const Zt=Array.from(mt.dataTransfer.files)[0];if(!Zt)return;const ct=Zt.name.toLowerCase();if(!ct.endsWith(".gcode")&&!ct.includes(".gcode.")){F(N("printers.dropNotPrintable","Only .gcode and .gcode.3mf files can be printed"),"error");return}yt(!0);try{const Hn=await de.uploadLibraryFile(Zt,null),Pr=Hn.metadata?.sliced_for_model,ir=D0(t.model);if(Pr&&ir&&Pr.toLowerCase()!==ir.toLowerCase()){await de.deleteLibraryFile(Hn.id).catch(()=>{}),F(N("printers.incompatibleFile","This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}",{slicedFor:Pr,printerModel:ir}),"error");return}Re({id:Hn.id,filename:Hn.filename})}catch{F(N("common.uploadFailed","Upload failed"),"error")}finally{yt(!1)}};return a.jsxs(Tt,{className:`relative ${C?"ring-2 ring-bambu-green":""} ${_?"cursor-pointer":""}`,onDragEnter:xa,onDragOver:ci,onDragLeave:Lr,onDrop:zm,children:[_&&a.jsx("div",{className:"absolute inset-0 z-20 flex items-start p-2",onClick:mt=>{mt.stopPropagation(),P?.(t.id)},children:C?a.jsx(_s,{className:"w-5 h-5 text-bambu-green"}):a.jsx(uo,{className:"w-5 h-5 text-bambu-gray"})}),(Ze||xt)&&a.jsx("div",{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${xt?"bg-bambu-green/10 border-bambu-green/50":Ln?"bg-bambu-green/10 border-bambu-green":"bg-red-500/10 border-red-500/50"}`,children:a.jsx("div",{className:"text-center",children:xt?a.jsxs(a.Fragment,{children:[a.jsx(ft,{className:"w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin"}),a.jsx("p",{className:"text-sm font-medium text-bambu-green",children:N("common.uploading","Uploading...")})]}):Ln?a.jsxs(a.Fragment,{children:[a.jsx(Mr,{className:"w-8 h-8 mx-auto mb-2 text-bambu-green"}),a.jsx("p",{className:"text-sm font-medium text-bambu-green",children:N("printers.dropToPrint","Drop to print")})]}):a.jsxs(a.Fragment,{children:[a.jsx(Bt,{className:"w-8 h-8 mx-auto mb-2 text-red-400"}),a.jsx("p",{className:"text-sm font-medium text-red-400",children:N("printers.cannotPrint","Printer busy")})]})})}),a.jsxs(jt,{className:i>=3?"p-5":"",children:[a.jsxs("div",{className:Tn(),children:[a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("img",{src:MJ(t.model),alt:t.model||N("common.printer"),className:`object-contain rounded-lg bg-bambu-dark flex-shrink-0 ${Rt()}`}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h3",{className:`font-semibold text-white ${Rn()}`,children:t.name}),r==="compact"&&(()=>{const mt=Ue?.connected&&Ue.hms_errors?sm(Ue.hms_errors):[],Ht=mt.some(Pr=>Pr.severity<=2),Zt=mt.length>0,ct=Ue?.connected?Ht?"bg-status-error":Zt?"bg-status-warning":"bg-status-ok":"bg-status-error",Hn=Ue?.connected?Zt?`${mt.length} HMS ${mt.length===1?"error":"errors"}`:N("printers.connection.connected"):N("printers.connection.offline");return a.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 ${ct}`,title:Hn})})()]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[t.model||"Unknown Model",r==="expanded"&&Ue?.nozzles&&Ue.nozzles[0]?.nozzle_diameter&&a.jsxs("span",{className:"ml-1.5 text-bambu-gray",title:Ue.nozzles[0].nozzle_type||"Nozzle",children:["• ",Ue.nozzles[0].nozzle_diameter,"mm"]}),r==="expanded"&&n&&n.total_print_hours>0&&a.jsxs("span",{className:"ml-2 text-bambu-gray",children:[a.jsx(Qn,{className:"w-3 h-3 inline-block mr-1"}),Math.round(n.total_print_hours),"h"]})]})]})]}),a.jsxs("div",{className:"relative flex-shrink-0",children:[a.jsx(De,{variant:"ghost",size:"sm",onClick:()=>H(!D),children:a.jsx(Jh,{className:"w-4 h-4"})}),D&&a.jsxs("div",{className:"absolute right-0 mt-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20",children:[a.jsxs("button",{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${k("printers:update")?"hover:bg-bambu-dark-tertiary":"opacity-50 cursor-not-allowed"}`,onClick:()=>{k("printers:update")&&(J(!0),H(!1))},title:k("printers:update")?void 0:N("printers.permission.noEdit"),children:[a.jsx(oi,{className:"w-4 h-4"}),N("common.edit")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{Te(!0),H(!1)},children:[a.jsx(vs,{className:"w-4 h-4"}),N("printers.printerInformation")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{Ip.mutate(),H(!1)},children:[a.jsx(cr,{className:"w-4 h-4"}),N("printers.reconnect")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50",disabled:iu.isPending,onClick:()=>{iu.mutate(),H(!1)},children:[a.jsx(nw,{className:`w-4 h-4 ${iu.isPending?"animate-spin":""}`}),N("printers.forceRefresh")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2",onClick:()=>{W(!0),H(!1)},children:[a.jsx(WQ,{className:"w-4 h-4"}),N("printers.mqttDebug")]}),a.jsxs("button",{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${k("printers:delete")?"text-red-400 hover:bg-bambu-dark-tertiary":"text-red-400/50 cursor-not-allowed"}`,onClick:()=>{k("printers:delete")&&(Y(!0),H(!1))},title:k("printers:delete")?void 0:N("printers.permission.noDelete"),children:[a.jsx(Jt,{className:"w-4 h-4"}),N("common.delete")]})]})]})]}),r==="expanded"&&a.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[a.jsxs("span",{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${Ue?.connected?"bg-status-ok/20 text-status-ok":"bg-status-error/20 text-status-error"}`,children:[Ue?.connected?a.jsx(_y,{className:"w-3 h-3"}):a.jsx(gp,{className:"w-3 h-3"}),Ue?.connected?N("printers.connection.connected"):N("printers.connection.offline")]}),Ue?.connected&&Ue?.wired_network&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok",title:N("printers.connection.ethernet","Ethernet"),children:[a.jsx(NO,{className:"w-3 h-3"}),N("printers.connection.ethernet","Ethernet")]}),Ue?.connected&&!Ue?.wired_network&&cn!=null&&a.jsxs("span",{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${cn>=-50||cn>=-60?"bg-status-ok/20 text-status-ok":cn>=-70?"bg-status-warning/20 text-status-warning":cn>=-80?"bg-orange-500/20 text-orange-600":"bg-status-error/20 text-status-error"}`,title:`WiFi: ${cn} dBm - ${N(EJ(cn).labelKey)}`,children:[a.jsx($Q,{className:"w-3 h-3"}),cn,"dBm"]}),Ue?.connected&&(()=>{const mt=Ue.hms_errors?sm(Ue.hms_errors):[];return a.jsxs("button",{onClick:()=>Q(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${mt.length>0?mt.some(Ht=>Ht.severity<=2)?"bg-status-error/20 text-status-error":"bg-status-warning/20 text-status-warning":"bg-status-ok/20 text-status-ok"}`,title:N("printers.clickToViewHmsErrors"),children:[a.jsx(Dn,{className:"w-3 h-3"}),mt.length>0?mt.length:"OK"]})})(),n&&a.jsxs("button",{onClick:()=>T("/maintenance"),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?"bg-status-error/20 text-status-error":n.warning_count>0?"bg-status-warning/20 text-status-warning":"bg-status-ok/20 text-status-ok"}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:""}${n.due_count>0&&n.warning_count>0?", ":""}${n.warning_count>0?`${n.warning_count} due soon`:""} - Click to view`:N("printers.maintenanceUpToDate"),children:[a.jsx(lg,{className:"w-3 h-3"}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:"OK"]}),Ni>0&&a.jsxs("button",{onClick:()=>T("/queue"),className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-500/20 text-indigo-400 hover:opacity-80 transition-opacity",title:N("printers.queue.inQueue",{count:Ni}),children:[a.jsx(ma,{className:"w-3 h-3"}),Ni]}),v&&Je?.current_version&&Je?.latest_version?a.jsxs("button",{onClick:()=>It(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${Je.update_available?"bg-orange-500/20 text-orange-400":"bg-status-ok/20 text-status-ok"}`,title:Je.update_available?N("printers.firmwareUpdateAvailable",{current:Je.current_version,latest:Je.latest_version}):N("printers.firmwareUpToDate",{version:Je.current_version}),children:[Je.update_available?a.jsx(ga,{className:"w-3 h-3"}):a.jsx(vr,{className:"w-3 h-3"}),Je.current_version]}):Ue?.firmware_version?a.jsx("span",{className:"flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray",children:Ue.firmware_version}):null,Ue?.connected&&["X1C","X1","X1E","X2D","P1S","P1P","P2S","H2D","H2D Pro","H2C","H2S"].includes(t.model??"")&&a.jsx("span",{className:`flex items-center px-2 py-1 rounded-full text-xs ${Ue.door_open?"bg-yellow-500/20 text-yellow-400":"bg-status-ok/20 text-status-ok"}`,title:Ue.door_open?N("printers.door.open"):N("printers.door.closed"),children:Ue.door_open?a.jsx($fe,{className:"w-3 h-3"}):a.jsx(Hfe,{className:"w-3 h-3"})})]})]}),z&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsx(Tt,{className:"w-full max-w-md mx-4",children:a.jsxs(jt,{children:[a.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[a.jsx("div",{className:"p-2 rounded-full bg-red-500/20",children:a.jsx(Dn,{className:"w-5 h-5 text-red-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:N("printers.confirm.deleteTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:N("printers.confirm.deleteMessage",{name:t.name})})]})]}),a.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:a.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:L,onChange:mt=>te(mt.target.checked),className:"mt-0.5 w-4 h-4 rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:N("printers.deleteArchives")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:N(L?"printers.confirm.deleteArchivesNote":"printers.confirm.keepArchivesNote")})]})]})}),a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsx(De,{variant:"secondary",onClick:()=>{Y(!1),te(!0)},children:N("common.cancel")}),a.jsx(De,{variant:"danger",onClick:()=>{li.mutate({deleteArchives:L}),Y(!1),te(!0)},children:"Delete"})]})]})})}),Ue?.connected&&a.jsxs(a.Fragment,{children:[r==="compact"?a.jsx("div",{className:"mt-2",children:Ue.state==="RUNNING"||Ue.state==="PAUSE"?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5",children:a.jsx("div",{className:`${Ue.state==="PAUSE"?"bg-status-warning":"bg-bambu-green"} h-1.5 rounded-full transition-all`,style:{width:`${Ue.progress||0}%`}})}),a.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1.5",children:[a.jsxs("span",{className:"text-xs text-white",children:[Math.round(Ue.progress||0),"%"]}),yo]})]}):a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[a.jsx("p",{className:"min-w-0 truncate text-xs text-bambu-gray",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),ad&&a.jsx("button",{type:"button",onClick:()=>Vo.mutate(),disabled:Vo.isPending||!k("printers:clear_plate"),"aria-label":N("printers.plateStatus.markCleared"),className:"inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full bg-yellow-500/20 border border-yellow-400/40 text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50",title:k("printers:clear_plate")?N("printers.plateStatus.markCleared"):N("printers.permission.noControl"),children:Vo.isPending?a.jsx(ft,{className:"w-3 h-3 animate-spin"}):a.jsx(ZW,{className:"w-3 h-3"})})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-4 p-3 bg-bambu-dark rounded-lg relative",children:[a.jsxs("button",{onClick:()=>ae(!0),disabled:!(Ue.state==="RUNNING"||Ue.state==="PAUSE")||(Ue.printable_objects_count??0)<2||!k("printers:control"),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${(Ue.state==="RUNNING"||Ue.state==="PAUSE")&&(Ue.printable_objects_count??0)>=2&&k("printers:control")?"text-bambu-gray hover:text-white hover:bg-white/10":"text-bambu-gray/30 cursor-not-allowed"}`,title:k("printers:control")?Ue.state==="RUNNING"||Ue.state==="PAUSE"?(Ue.printable_objects_count??0)>=2?N("printers.skipObjects.tooltip"):N("printers.skipObjects.requiresMultiple"):N("printers.skipObjects.onlyWhilePrinting"):N("printers.permission.noControl"),children:[a.jsx(rT,{className:"w-4 h-4"}),kc&&kc.skipped_count>0&&a.jsx("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-bold bg-red-500 text-white rounded-full",children:kc.skipped_count})]}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(R7e,{url:Ue.state==="RUNNING"||Ue.state==="PAUSE"?Ue.cover_url:null,printName:(Ue.state==="RUNNING"||Ue.state==="PAUSE")&&iK(Ue.subtask_name||Ue.current_print||null,Ue.gcode_file,N)||void 0}),a.jsx("div",{className:"flex-1 min-w-0",children:Ue.current_print&&(Ue.state==="RUNNING"||Ue.state==="PAUSE")?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),a.jsx("p",{className:"text-white text-sm mb-2 truncate",children:iK(Ue.subtask_name||Ue.current_print||null,Ue.gcode_file,N)}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-2 mr-3",children:a.jsx("div",{className:`${Ue.state==="PAUSE"?"bg-status-warning":"bg-bambu-green"} h-2 rounded-full transition-all`,style:{width:`${Ue.progress||0}%`}})}),a.jsxs("span",{className:"text-white",children:[Math.round(Ue.progress||0),"%"]})]}),a.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-bambu-gray",children:[Ue.remaining_time!=null&&Ue.remaining_time>0&&a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(Qn,{className:"w-3 h-3"}),ys(Ue.remaining_time*60)]}),a.jsxs("span",{className:"text-bambu-green font-medium",title:N("printers.estimatedCompletion"),children:["ETA ",zO(Ue.remaining_time,p,N)]})]}),Ue.layer_num!=null&&Ue.total_layers!=null&&Ue.total_layers>0&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(ma,{className:"w-3 h-3"}),Ue.layer_num,"/",Ue.total_layers]}),_l&&a.jsxs("span",{className:"flex items-center gap-1",title:`Started by ${_l}`,children:[a.jsx(xm,{className:"w-3 h-3"}),_l]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-1",children:N("printers.sort.status")}),a.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[a.jsx("p",{className:"text-white text-sm",children:RD(Ue.state,Ue.stg_cur_name)}),yo]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-2 mr-3",children:a.jsx("div",{className:"bg-bambu-dark-tertiary h-2 rounded-full"})}),a.jsx("span",{className:"text-bambu-gray",children:"—"})]}),Bn?a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 truncate",title:Bn.print_name||Bn.filename,children:["Last: ",Bn.print_name||Bn.filename,Bn.completed_at&&a.jsxs("span",{className:"ml-1 text-bambu-gray/60",children:["• ",cg(Bn.completed_at,{month:"short",day:"numeric"})]})]}):a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:N("printers.readyToPrint")})]})})]})]}),a.jsx(YMe,{printerId:t.id,printerModel:t.model,printerState:Ue.state,awaitingPlateClear:Ue.awaiting_plate_clear,requirePlateClear:g,loadedFilamentTypes:vt,loadedFilaments:$e})]}),Ue.temperatures&&r==="expanded"&&(()=>{const mt=Ue.temperatures.nozzle_heating||Ue.temperatures.nozzle_2_heating||!1,Ht=Ue.temperatures.bed_heating||!1,Zt=Ue.temperatures.chamber_heating||!1,ct=t.nozzle_count===2||Ue.temperatures.nozzle_2!==void 0,Hn=Ue.active_extruder===1?"L":"R",Pr=Ue.nozzle_rack?.find(ka=>ka.id===1),ir=Ue.nozzle_rack?.find(ka=>ka.id===0),aa=ir||Pr;return a.jsxs("div",{className:"flex items-stretch gap-1.5 flex-wrap",children:[a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-orange-400",isHeating:mt}),Ue.temperatures.nozzle_2!==void 0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:"L / R"}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"° / ",Math.round(Ue.temperatures.nozzle_2||0),"°"]})]}):aa?a.jsx(rie,{slot:aa,index:0,activeStatus:!0,filamentName:aa.filament_id?wt?.[aa.filament_id]?.name:void 0,children:a.jsxs("div",{className:"cursor-default",children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"°C"]})]})}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.nozzle||0),"°C"]})]})]}),a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-blue-400",isHeating:Ht}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.bed")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.bed||0),"°C"]})]}),Ue.temperatures.chamber!==void 0&&a.jsxs("div",{className:"text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center",children:[a.jsx(DD,{className:"w-3.5 h-3.5 mb-0.5",color:"text-green-400",isHeating:Zt}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.chamber")}),a.jsxs("p",{className:"text-[11px] text-white",children:[Math.round(Ue.temperatures.chamber||0),"°C"]})]}),ct&&a.jsx(T7e,{leftSlot:Pr,rightSlot:ir,activeNozzle:Hn,filamentInfo:wt,children:a.jsxs("div",{className:"text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center cursor-default",title:N("printers.activeNozzle",{nozzle:N(Hn==="L"?"common.left":"common.right")}),children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsxs("span",{className:`text-[11px] font-bold ${Hn==="L"?"text-amber-400":"text-gray-500"}`,children:["L",Pr?.nozzle_diameter?` ${Pr.nozzle_diameter}`:""]}),a.jsx("span",{className:"text-[9px] text-bambu-gray/40",children:"·"}),a.jsxs("span",{className:`text-[11px] font-bold ${Hn==="R"?"text-amber-400":"text-gray-500"}`,children:["R",ir?.nozzle_diameter?` ${ir.nozzle_diameter}`:""]})]}),a.jsx("p",{className:"text-[9px] text-bambu-gray",children:N("printers.temperatures.nozzle")})]})}),Ue.nozzle_rack&&Ue.nozzle_rack.some(ka=>ka.id>=2)&&a.jsx(A7e,{slots:Ue.nozzle_rack,filamentInfo:wt})]})})(),r==="expanded"&&ad&&a.jsxs("button",{type:"button",onClick:()=>Vo.mutate(),disabled:Vo.isPending||!k("printers:clear_plate"),className:"mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-500/20 border border-yellow-400/40 text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50",title:k("printers:clear_plate")?N("printers.plateStatus.markCleared"):N("printers.permission.noControl"),children:[Vo.isPending?a.jsx(ft,{className:"w-3 h-3 animate-spin"}):a.jsx(ZW,{className:"w-4 h-4"}),N("printers.plateStatus.markCleared")]}),r==="expanded"&&(()=>{const mt=Ue.state==="RUNNING",Ht=Ue.state==="PAUSE",Zt=mt||Ht,ct=wc.isPending||vo.isPending||Sc.isPending,Hn=Ue.cooling_fan_speed,Pr=Ue.big_fan1_speed,ir=Ue.big_fan2_speed;return a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx("span",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:N("printers.controls")}),a.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary/30"})]}),a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-2 gap-y-2",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 min-w-0",children:[a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${Hn&&Hn>0?"bg-cyan-500/10":"bg-bambu-dark"}`,title:N("printers.fans.partCooling"),children:[a.jsx(RQ,{className:`w-3.5 h-3.5 ${Hn&&Hn>0?"text-cyan-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${Hn&&Hn>0?"text-cyan-400":"text-bambu-gray/50"}`,children:[Hn??0,"%"]})]}),a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${Pr&&Pr>0?"bg-blue-500/10":"bg-bambu-dark"}`,title:N("printers.fans.auxiliary"),children:[a.jsx(YQ,{className:`w-3.5 h-3.5 ${Pr&&Pr>0?"text-blue-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${Pr&&Pr>0?"text-blue-400":"text-bambu-gray/50"}`,children:[Pr??0,"%"]})]}),a.jsxs("div",{className:`flex items-center gap-1 px-1.5 py-1 rounded ${ir&&ir>0?"bg-green-500/10":"bg-bambu-dark"}`,title:N("printers.fans.chamber"),children:[a.jsx(mpe,{className:`w-3.5 h-3.5 ${ir&&ir>0?"text-green-400":"text-bambu-gray/50"}`}),a.jsxs("span",{className:`text-[10px] ${ir&&ir>0?"text-green-400":"text-bambu-gray/50"}`,children:[ir??0,"%"]})]}),a.jsx("div",{className:"w-px h-5 bg-bambu-gray/30"}),["P2S","X2D","H2D","H2C","H2S"].includes(t.model??"")&&(()=>{const aa=Ue.airduct_mode===1,ka=aa?Bu:TH,an=aa?"text-orange-400":"text-sky-400",wn=aa?"bg-orange-500/10 hover:bg-orange-500/20":"bg-sky-500/10 hover:bg-sky-500/20";return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>G(I===t.id?null:t.id),disabled:!k("printers:control"),className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${wn} disabled:opacity-50 disabled:cursor-not-allowed`,title:N("printers.airduct.title"),children:[a.jsx(ka,{className:`w-3.5 h-3.5 ${an}`}),a.jsx("span",{className:`text-[10px] ${an}`,children:N(aa?"printers.airduct.heating":"printers.airduct.cooling")})]}),I===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>G(null)}),a.jsx("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]",children:[{mode:"cooling",label:N("printers.airduct.cooling"),modeId:0},{mode:"heating",label:N("printers.airduct.heating"),modeId:1}].map(({mode:Da,label:di,modeId:As})=>a.jsxs("button",{onClick:()=>{_c.mutate(Da),G(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${Ue.airduct_mode===As?"text-bambu-green bg-bambu-green/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[Da==="heating"?a.jsx(Bu,{className:"w-3 h-3"}):a.jsx(TH,{className:"w-3 h-3"}),di]},Da))})]})]})})(),(()=>{const ka={1:"50%",2:"100%",3:"124%",4:"166%"}[Ue.speed_level]||"100%";return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>ue(U===t.id?null:t.id),disabled:!Zt||!k("printers:control"),className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${Zt?"bg-amber-500/10 hover:bg-amber-500/20":"bg-bambu-dark cursor-not-allowed"}`,title:Zt?N("printers.speed.title"):void 0,children:[a.jsx(Kw,{className:`w-3.5 h-3.5 ${Zt?"text-amber-400":"text-bambu-gray/50"}`}),a.jsx("span",{className:`text-[10px] ${Zt?"text-amber-400":"text-bambu-gray/50"}`,children:ka})]}),U===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>ue(null)}),a.jsx("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]",children:[{mode:1,label:N("printers.speed.silent")},{mode:2,label:N("printers.speed.standard")},{mode:3,label:N("printers.speed.sport")},{mode:4,label:N("printers.speed.ludicrous")}].map(({mode:an,label:wn})=>a.jsx("button",{onClick:()=>{Ci.mutate(an),ue(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${Ue.speed_level===an?"text-bambu-green bg-bambu-green/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:wn},an))})]})]})})(),a.jsx("div",{className:"w-px h-5 bg-bambu-gray/30"}),(()=>{const aa=k("printers:control"),ka=Zt||!aa,an=wn=>{const Da=wn*ee*1,di=`bambuddy.bedJog.warned.${t.id}`,As=(()=>{try{return sessionStorage.getItem(di)==="1"}catch{return!1}})();V(null),As?su.mutate({distance:Da,force:!0}):pe({distance:Da})};return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>V(X===t.id?null:t.id),disabled:ka,className:`flex items-center gap-1 px-1.5 py-1 rounded transition-colors ${ka?"bg-bambu-dark cursor-not-allowed":"bg-indigo-500/10 hover:bg-indigo-500/20"}`,title:N(aa?Zt?"printers.bedJog.disabledWhilePrinting":"printers.bedJog.title":"printers.permission.noControl"),children:[a.jsx(Tbe,{className:`w-3.5 h-3.5 ${ka?"text-bambu-gray/50":"text-indigo-400"}`}),a.jsx("span",{className:`text-[10px] ${ka?"text-bambu-gray/50":"text-indigo-400"}`,children:N("printers.bedJog.bed")}),a.jsxs("span",{className:`text-[10px] tabular-nums opacity-70 ${ka?"text-bambu-gray/50":"text-indigo-400"}`,children:[ee,"mm"]})]}),X===t.id&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>V(null)}),a.jsxs("div",{className:"absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-2 min-w-[140px]",children:[a.jsxs("div",{className:"flex items-center justify-between gap-1 mb-2",children:[a.jsx("button",{onClick:()=>an(-1),className:"flex-1 flex items-center justify-center py-1.5 rounded bg-indigo-500/15 hover:bg-indigo-500/30 text-indigo-300","aria-label":N("printers.bedJog.up"),children:a.jsx(fp,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>an(1),className:"flex-1 flex items-center justify-center py-1.5 rounded bg-indigo-500/15 hover:bg-indigo-500/30 text-indigo-300","aria-label":N("printers.bedJog.down"),children:a.jsx(ig,{className:"w-4 h-4"})})]}),a.jsx("div",{className:"text-[9px] uppercase tracking-wider text-bambu-gray/70 px-1 mb-1",children:N("printers.bedJog.step")}),a.jsx("div",{className:"flex gap-1",children:[1,10,50].map(wn=>a.jsx("button",{onClick:()=>se(wn),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${ee===wn?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:wn},wn))})]})]})]})})()]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 max-[550px]:self-start",children:[a.jsxs("button",{onClick:()=>j(!0),disabled:!Zt||ct||!k("printers:control"),className:` flex items-center justify-center gap-1 px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${Zt&&k("printers:control")?"bg-red-500/20 text-red-400 hover:bg-red-500/30":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"} diff --git a/static/index.html b/static/index.html index 31f30ba19..c193d28c8 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +