| 1 |
- import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,l as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./useQueries-Be6PMvSC.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{r as d,t as f}from"./info-ROUoQhJR.js";import{n as p}from"./ToastContext-BRX0SW3C.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as h}from"./triangle-alert-Dt_1FcBy.js";import{t as g}from"./x-DR-Trv6U.js";import{o as _}from"./date-G9KUauqz.js";import{At as v,Cn as y,Ct as b,Vt as x}from"./index-CovRLYqQ.js";var S=u(`video-off`,[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),C=e(n(),1),w=[`s`,`m`,`l`,`xl`];function T(e){switch(e){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`}}var E=t(),D=8;function O(e,t){if(t>0)return`error`;switch(e){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:case`FAILED`:return`finished`;default:return`idle`}}var k={printing:`bg-bambu-green/85 text-black`,paused:`bg-amber-500/85 text-black`,finished:`bg-sky-500/80 text-white`,error:`bg-red-500/85 text-white`,idle:`bg-bambu-dark-tertiary/80 text-bambu-gray`};function A({printerId:e,printerName:t,cameraRotation:n=0,mode:i,snapshotIntervalMs:s,connected:c,onClick:l,statusMode:u=`off`,printerState:d=null,progress:f=null,remainingMin:p=null,layerNum:m=null,totalLayers:g=null,printName:v=null,hmsErrorCount:y=0}){let{t:x}=o(),[w,T]=(0,C.useState)(0),[A,j]=(0,C.useState)(!1),M=(0,C.useRef)(i);(0,C.useEffect)(()=>{let t=M.current===`live`,n=i===`live`;if(M.current=i,t&&!n){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}j(!1),T(e=>e+1)},[i,e]),(0,C.useEffect)(()=>()=>{if(M.current===`live`){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},[e]),(0,C.useEffect)(()=>{if(i!==`snapshot`)return;let e=setInterval(()=>T(e=>e+1),s);return()=>clearInterval(e)},[i,s]);let N=r(`/api/v1/printers/${e}/camera/stream?fps=${D}&t=${w}`),P=r(`/api/v1/printers/${e}/camera/snapshot?t=${w}`),F=l!=null,I=n?`rotate(${n}deg)`:void 0,L=O(d,y),R=c&&u!==`off`&&L!==`idle`,z=c&&u===`full`&&(L===`printing`||L===`paused`),B=v??null,V=f==null?null:Math.round(f),H=m!=null&&g!=null&&g>0,U=p!=null&&p>0,W=`group relative aspect-video w-full overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-black text-left ${F?`focus:outline-none focus:ring-2 focus:ring-bambu-green`:`cursor-default`}`,G=(0,E.jsxs)(E.Fragment,{children:[!c||i===`paused`?(0,E.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/60`,children:c?(0,E.jsx)(S,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`}):(0,E.jsx)(b,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`})}):A?(0,E.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1 bg-black/80 text-bambu-gray`,children:[(0,E.jsx)(S,{className:`h-7 w-7`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{className:`text-xs`,children:x(`printers.camWall.noSignal`)})]}):(0,E.jsx)(`img`,{src:i===`live`?N:P,alt:t,draggable:!1,loading:`lazy`,className:`h-full w-full select-none object-contain`,style:{transform:I},onError:()=>j(!0)},`${i}-${w}`),R&&(0,E.jsxs)(`span`,{className:`absolute left-2 top-2 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${k[L]}`,children:[y>0&&(0,E.jsx)(h,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{children:x(`printers.status.${L}`)})]}),(0,E.jsx)(`span`,{className:`absolute right-2 top-2 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${i===`live`?`bg-red-500/80 text-white`:i===`snapshot`?`bg-amber-500/70 text-black`:`bg-bambu-dark-tertiary/70 text-bambu-gray`}`,children:x(i===`live`?`printers.camWall.live`:i===`snapshot`?`printers.camWall.snap`:`printers.camWall.off`)}),(0,E.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2 pb-1.5 pt-3 text-white`,children:[z&&(0,E.jsxs)(`div`,{className:`mb-0.5 space-y-0.5 text-[11px] leading-tight text-white/90`,children:[B&&(0,E.jsx)(`div`,{className:`truncate`,title:B,children:B}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-bambu-gray`,children:[V!=null&&(0,E.jsxs)(`span`,{className:`font-semibold text-white`,children:[V,`%`]}),H&&(0,E.jsx)(`span`,{children:x(`printers.camWall.layer`,{cur:m,total:g})}),U&&(0,E.jsx)(`span`,{children:x(`printers.camWall.timeLeft`,{time:_((p??0)*60)})})]})]}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:t})]})]});return F?(0,E.jsx)(`button`,{type:`button`,onClick:l,className:W,title:t,children:G}):(0,E.jsx)(`div`,{className:W,title:t,children:G})}var j=new Set([`0700_8011`,`0701_8011`,`0702_8011`,`0703_8011`,`0704_8011`,`0705_8011`,`0706_8011`,`0707_8011`,`07FF_8011`]),M=`0500050000010007`;function N(e){switch(e){case 1:return{labelKey:`hmsErrors.severityError`,color:`text-red-600 dark:text-red-400`,bgColor:`bg-red-100 dark:bg-red-500/20`,Icon:h};case 2:return{labelKey:`hmsErrors.severityWarning`,color:`text-orange-700 dark:text-orange-400`,bgColor:`bg-orange-100 dark:bg-orange-500/20`,Icon:h};case 3:return{labelKey:`hmsErrors.severityNotice`,color:`text-blue-700 dark:text-blue-400`,bgColor:`bg-blue-100 dark:bg-blue-500/20`,Icon:f};default:return{labelKey:`hmsErrors.severityUnknown`,color:`text-bambu-gray`,bgColor:`bg-bambu-dark-tertiary`,Icon:d}}}function P(e){return e.severity===1||e.severity===2}function F(e,t){let n=e>>16&65535||(e>>8&255)<<8|e&255,r=t&65535;return`${n.toString(16).padStart(4,`0`).toUpperCase()}_${r.toString(16).padStart(4,`0`).toUpperCase()}`}function I(e){if(e.full_code&&e.full_code.length===16)return e.full_code.match(/.{4}/g).join(`-`);let t=parseInt(e.code.replace(`0x`,``),16)||0;return F(e.attr,t).replace(`_`,`-`)}function L(e){if(!(e.severity>=1))return!1;if((e.actions?.length??0)>0)return!0;let t=e.full_code?.length===16&&e.severity===3;return!!e.description&&!t}function R(e){return e.filter(L)}function z(e){return e.filter(e=>!L(e))}function B(){return`https://wiki.bambulab.com/en/hms/home`}function V({printerName:e,errors:t,onClose:n,printerId:r,hasPermission:a,runoutGuidance:l}){let{t:u}=o(),{showToast:f}=p(),_=s(),b=c({mutationFn:()=>i.clearHMSErrors(r),onSuccess:()=>{f(u(`hmsErrors.clearSuccess`),`success`),n()},onError:()=>{f(u(`hmsErrors.clearFailed`),`error`)}}),x=R(t),S=z(t);(0,C.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let w=c({mutationFn:e=>i.executeHMSAction(r,{action:e.action,print_error:e.print_error,job_id:e.job_id}),onSuccess:()=>{_.invalidateQueries({queryKey:[`printerStatus`,r]}),f(u(`hmsErrors.actionSuccess`,`Action sent to printer`),`success`),n()},onError:e=>{f(`${u(`hmsErrors.actionFailed`,`Failed to send action`)}: ${e.message}`,`error`)}});return(0,E.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,E.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(h,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),(0,E.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`hmsErrors.title`,{name:e})})]}),(0,E.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,E.jsx)(g,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0&&S.length===0?(0,E.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,E.jsx)(d,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,E.jsx)(`p`,{children:u(`hmsErrors.noErrors`)})]}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[x.map((e,t)=>{let{labelKey:n,color:r,bgColor:i,Icon:o}=N(e.severity),s=parseInt(e.code.replace(`0x`,``),16)||0,c=F(e.attr,s),d=e.description||u(`hmsErrors.unknownCode`),f=e.full_code===M;f&&(d=u(`hmsErrors.mqttVerifyFailedDescription`));let p=f?u(`hmsErrors.mqttVerifyFailedRemedy`):null;l&&j.has(c)&&(d=l.expectedSlotLabel&&l.ranOutSlotLabel?u(`hmsErrors.runoutExpectedSlot`,{expected:l.expectedSlotLabel,ranOut:l.ranOutSlotLabel}):l.expectedSlotLabel?u(`hmsErrors.runoutExpectedSlotOnly`,{expected:l.expectedSlotLabel}):u(`hmsErrors.runoutSlotUnknown`));let h=B(),g=I(e);return(0,E.jsx)(`div`,{className:`p-4 rounded-lg ${i} border border-white/10`,children:(0,E.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,E.jsx)(o,{className:`w-5 h-5 ${r} flex-shrink-0 mt-0.5`}),(0,E.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-sm ${r}`,children:[`[`,g,`]`]}),(0,E.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${i} ${r}`,children:u(n)})]}),(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:d}),p&&(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:p}),e.actions&&e.actions.length>0&&(0,E.jsx)(`div`,{className:`flex flex-wrap gap-2 my-2`,children:e.actions.map(t=>{let n=w.variables,r=w.isPending&&n?.action===t&&n?.print_error===(e.full_code||c.replace(`_`,``));return(0,E.jsxs)(`button`,{onClick:()=>{w.mutate({action:t,print_error:e.full_code||c.replace(`_`,``),job_id:e.job_id??null})},disabled:!a(`printers:control`)||w.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-white/10 hover:bg-white/20 active:bg-white/30 text-white border border-white/20 hover:border-white/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[r&&(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}),u(`hmsErrors.actions.${t}`,t)]},t)})}),(0,E.jsxs)(`a`,{href:h,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-bambu-green hover:underline`,children:[(0,E.jsx)(y,{className:`w-3 h-3`}),u(`hmsErrors.viewOnWiki`)]})]})]})},`${e.code}-${t}`)}),S.length>0&&(0,E.jsxs)(`details`,{className:`rounded-lg border border-white/10 p-3`,"data-testid":`hms-uncounted`,children:[(0,E.jsx)(`summary`,{className:`cursor-pointer text-sm text-bambu-gray`,children:u(`hmsErrors.uncountedSummary`,{n:S.length})}),(0,E.jsx)(`p`,{className:`mt-2 text-xs text-bambu-gray`,children:u(`hmsErrors.uncountedHint`)}),(0,E.jsx)(`ul`,{className:`mt-2 space-y-2`,children:S.map((e,t)=>(0,E.jsxs)(`li`,{className:`text-xs`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-bambu-gray`,children:[`[`,I(e),`]`]}),(0,E.jsx)(`span`,{className:`text-bambu-gray`,children:u(N(e.severity).labelKey)})]}),e.description&&(0,E.jsx)(`p`,{className:`mt-0.5 text-bambu-gray`,children:e.description})]},`${e.full_code||e.code}-${t}`))})]})]})}),(0,E.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:u(`hmsErrors.clearInstructions`)}),t.length>0&&(0,E.jsxs)(`button`,{onClick:()=>b.mutate(),disabled:!a(`printers:control`)||b.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[b.isPending?(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}):(0,E.jsx)(v,{className:`w-4 h-4`}),u(`hmsErrors.clearErrors`)]})]})]})})}var H=1,U=16,W=2,G=60,K=[`off`,`compact`,`full`];function q({printers:e,maxLive:t,snapshotIntervalSec:n,statusMode:r,onTileClick:a,onChangeMaxLive:s,onChangeSnapshotIntervalSec:c,onChangeStatusMode:u,statuses:d,showSettings:f=!0,tileSize:p=2}){let{t:m}=o(),h=(0,C.useRef)(new Map),g=d?[]:e,_=l({queries:g.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>i.getPrinterStatus(e.id),staleTime:5e3}))}),v=(0,C.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{e.set(t.id,_[n]?.data)}),e},[e,_,d]),y=d??v,[b,S]=(0,C.useState)(()=>new Set),[w,D]=(0,C.useState)(!1),O=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!w)return;let e=e=>{O.current&&!O.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[w]),(0,C.useEffect)(()=>{let e=new IntersectionObserver(e=>{S(t=>{let n=new Set(t);for(let t of e){let e=Number(t.target.dataset.printerId);Number.isFinite(e)&&(t.isIntersecting?n.add(e):n.delete(e))}return n})},{threshold:.4});for(let[,t]of h.current)t&&e.observe(t);return()=>e.disconnect()},[e]);let k=(0,C.useMemo)(()=>{let n=new Map,r=Math.max(0,t);for(let t of e){let e=y.get(t.id)?.connected??!1;if(!b.has(t.id)||!e){n.set(t.id,`paused`);continue}r>0?(n.set(t.id,`live`),--r):n.set(t.id,`snapshot`)}return n},[e,b,t,y]);return e.length===0?(0,E.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-6 text-center text-bambu-gray`,children:m(`printers.camWall.noPrinters`)}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,E.jsx)(`span`,{children:m(`printers.camWall.summary`,{live:Array.from(k.values()).filter(e=>e===`live`).length,snap:Array.from(k.values()).filter(e=>e===`snapshot`).length,total:e.length})}),f&&(0,E.jsxs)(`div`,{className:`relative`,ref:O,children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:`flex h-7 items-center gap-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 text-white hover:bg-bambu-dark-tertiary`,title:m(`printers.camWall.settings.title`),children:[(0,E.jsx)(x,{className:`h-3.5 w-3.5`}),(0,E.jsx)(`span`,{children:m(`printers.camWall.settings.title`)})]}),w&&(0,E.jsxs)(`div`,{className:`absolute right-0 top-9 z-30 w-72 space-y-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-3 shadow-xl`,children:[(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.maxLive`)}),(0,E.jsx)(`input`,{type:`number`,min:H,max:U,value:t,onChange:e=>{s(Math.min(U,Math.max(H,Number(e.target.value)||H)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.maxLiveHint`)})]}),(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.snapshotInterval`)}),(0,E.jsx)(`input`,{type:`number`,min:W,max:G,value:n,onChange:e=>{c(Math.min(G,Math.max(W,Number(e.target.value)||W)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.snapshotIntervalHint`)})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(`span`,{className:`block text-xs font-medium text-white`,children:m(`printers.camWall.settings.statusOverlay`)}),(0,E.jsx)(`div`,{role:`radiogroup`,"aria-label":m(`printers.camWall.settings.statusOverlay`),className:`flex overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:K.map(e=>(0,E.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r===e,onClick:()=>u(e),className:`flex-1 px-2 py-1 text-xs ${r===e?`bg-bambu-green text-black font-semibold`:`bg-bambu-dark text-white hover:bg-bambu-dark-tertiary`}`,children:m(`printers.camWall.statusMode.${e}`)},e))}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.statusOverlayHint`)})]})]})]})]}),(0,E.jsx)(`div`,{className:`grid gap-3 ${T(p)}`,"data-testid":`camwall-grid`,children:e.map(e=>{let t=k.get(e.id)??`paused`;return(0,E.jsx)(`div`,{ref:t=>{h.current.set(e.id,t)},"data-printer-id":e.id,children:(0,E.jsx)(A,{printerId:e.id,printerName:e.name,cameraRotation:e.camera_rotation,mode:t,snapshotIntervalMs:n*1e3,connected:y.get(e.id)?.connected??!1,statusMode:r,printerState:y.get(e.id)?.state??null,progress:y.get(e.id)?.progress??null,remainingMin:y.get(e.id)?.remaining_time??null,layerNum:y.get(e.id)?.layer_num??null,totalLayers:y.get(e.id)?.total_layers??null,printName:y.get(e.id)?.subtask_name??y.get(e.id)?.gcode_file??null,hmsErrorCount:R(y.get(e.id)?.hms_errors??[]).length,onClick:a?()=>a(e.id,e.name):void 0})},e.id)})})]})}export{w as a,P as i,V as n,R as r,q as t};
|