| 1 |
- import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,x as a}from"./client-BdOyoZJz.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./createLucideIcon-Yo2YoYjm.js";import{t as l}from"./box-BIRPxdgi.js";import{n as u,r as d}from"./info-DcT0QU8O.js";import{n as f}from"./ToastContext-VFOrCCoA.js";import{t as p}from"./loader-circle-CB4leTZa.js";import{t as m}from"./maximize-2-Cggm3z8J.js";import{t as h}from"./x-Dctff5l9.js";import{An as g,Ft as _,Lt as v,Rt as y,_t as b,kn as x,yt as S}from"./index-BoVbGTav.js";var C=c(`minimize`,[[`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3`,key:`hohbtr`}],[`path`,{d:`M21 8h-3a2 2 0 0 1-2-2V3`,key:`5jw1f3`}],[`path`,{d:`M3 16h3a2 2 0 0 1 2 2v3`,key:`198tvr`}],[`path`,{d:`M16 21v-3a2 2 0 0 1 2-2h3`,key:`ph8mxp`}]]),w=t();function T({on:e,className:t=`w-5 h-5`}){let n=e?`#facc15`:`none`,r=e?`#78350f`:`currentColor`;return(0,w.jsxs)(`svg`,{viewBox:`0 0 32 32`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,children:[(0,w.jsxs)(`g`,{stroke:r,opacity:+!!e,children:[(0,w.jsx)(`line`,{x1:`16`,y1:`2`,x2:`16`,y2:`6`}),(0,w.jsx)(`line`,{x1:`6.1`,y1:`6.1`,x2:`8.9`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`25.9`,y1:`6.1`,x2:`23.1`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`2`,y1:`16`,x2:`6`,y2:`16`}),(0,w.jsx)(`line`,{x1:`30`,y1:`16`,x2:`26`,y2:`16`})]}),(0,w.jsx)(`path`,{d:`M12 24v-2.3c0-.9-.4-1.7-1-2.3C9.2 17.6 8 15.4 8 13c0-4.4 3.6-8 8-8s8 3.6 8 8c0 2.4-1.2 4.6-3 6.4-.6.6-1 1.4-1 2.3V24`,fill:n,stroke:r}),(0,w.jsx)(`path`,{d:`M12 24h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M12 27h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M13 30h6`,stroke:r})]})}var E=e(n(),1);function D(e,t,n){let r=Math.max(0,Math.min(e.width-1,Math.floor(t))),i=(Math.max(0,Math.min(e.height-1,Math.floor(n)))*e.width+r)*4,a=e.data[i],o=e.data[i+1],s=e.data[i+2];return!e.data[i+3]||a===0&&o===0&&s===0?null:a+(o<<8)+(s<<16)}function O(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n);if(!(a>0))return null;let o=(r-e.left-(e.width-t*a)/2)/a,s=(i-e.top-(e.height-n*a)/2)/a;return o<0||s<0||o>=t||s>=n?null:{x:o,y:s}}var k=({className:e})=>(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,w.jsx)(`rect`,{x:`2`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`rect`,{x:`9.5`,y:`15`,width:`5`,height:`5`,rx:`0.5`,fill:`currentColor`,opacity:`0.3`}),(0,w.jsx)(`rect`,{x:`17`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`path`,{d:`M4 12 C4 6, 14 6, 14 12`}),(0,w.jsx)(`polyline`,{points:`12,10 14,12 12,14`})]});function A({printerId:e,isOpen:t,onClose:n}){let{t:c}=i(),{showToast:u}=f(),{hasPermission:g}=S(),[_,x]=(0,E.useState)(new Set),[C,T]=(0,E.useState)(!1),[A,j]=(0,E.useState)(!1),[M,N]=(0,E.useState)(!1),P=(0,E.useRef)(null),F=(0,E.useRef)(null),I=(0,E.useRef)(null),{data:L}=o({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:3e4,enabled:t}),{data:R,refetch:z}=o({queryKey:[`printableObjects`,e],queryFn:()=>r.getPrintableObjects(e),enabled:t,refetchInterval:t?5e3:!1}),B=(R?.objects.length??0)>0,V=B&&L?.cover_url?a(`${L.cover_url}?view=top`):null,H=B&&L?.cover_url?a(`${L.cover_url}?view=pick`):null,U=(0,E.useMemo)(()=>(R?.objects??[]).filter(e=>!e.skipped),[R]),W=(0,E.useMemo)(()=>U.filter(e=>_.has(e.id)),[U,_]),G=U.length>0&&W.length===U.length,K=G&&_.size>0,q=_.size>0&&(L?.layer_num??0)>1&&g(`printers:control`),J=s({mutationFn:t=>r.skipObjects(e,t),onSuccess:async e=>{u(e.message||c(`printers.skipObjects.objectsSkipped`)),await z(),T(!1),x(new Set),n()},onError:e=>{T(!1),u(e.message||c(`printers.toast.failedToSkipObjects`),`error`)}});(0,E.useEffect)(()=>{t||(x(new Set),T(!1),j(!1))},[t]),(0,E.useEffect)(()=>{if(P.current=null,N(!1),!t||!H)return;let e=!1,n=new Image;return n.onload=()=>{if(e)return;let t=document.createElement(`canvas`);t.width=n.naturalWidth||512,t.height=n.naturalHeight||512;let r=t.getContext(`2d`,{willReadFrequently:!0});r&&(r.drawImage(n,0,0),P.current=r.getImageData(0,0,t.width,t.height),N(!0))},n.onerror=()=>{e||N(!1)},n.src=H,()=>{e=!0}},[t,H]),(0,E.useEffect)(()=>{let e=P.current;if(!e||!R)return;let t=new Set(R.objects.filter(e=>e.skipped).map(e=>e.id));for(let n of[F.current,I.current]){if(!n)continue;n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(!r)continue;let i=r.createImageData(e.width,e.height);for(let n=0;n<e.data.length;n+=4){let r=e.data[n]+(e.data[n+1]<<8)+(e.data[n+2]<<16),a=_.has(r),o=t.has(r);if(!a&&!o)continue;let s=n/4,c=(s%e.width+Math.floor(s/e.width))%14<7;i.data[n]=a?c?37:74:148,i.data[n+1]=a?c?199:222:163,i.data[n+2]=a?c?91:128:184,i.data[n+3]=a?c?205:145:175}r.putImageData(i,0,0)}},[A,R,M,_]);let Y=e=>{e.skipped||x(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},X=e=>{let t=P.current;if(!t)return;let n=O(e.currentTarget.getBoundingClientRect(),t.width,t.height,e.clientX,e.clientY);if(!n)return;let r=D(t,n.x,n.y),i=R?.objects.find(e=>e.id===r);i&&Y(i)},Z=(e=!1)=>(0,w.jsxs)(`div`,{className:`relative aspect-square overflow-hidden rounded-lg border border-gray-300 bg-gray-900 dark:border-gray-600 ${M?`cursor-crosshair`:``}`,children:[V?(0,w.jsx)(`img`,{src:V,alt:c(`printers.printPreview`),className:`absolute inset-0 h-full w-full object-contain`}):(0,w.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,w.jsx)(l,{className:`h-10 w-10 text-gray-500`})}),(0,w.jsx)(`canvas`,{ref:e?I:F,onClick:X,className:`absolute inset-0 h-full w-full object-contain`,"aria-label":c(`printers.skipObjects.selectObjectsToSkip`)}),!e&&V&&(0,w.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`absolute right-2 top-2 rounded bg-black/65 p-1.5 text-white/80 hover:text-white`,title:c(`common.expand`),children:(0,w.jsx)(m,{className:`h-4 w-4`})}),!M&&V&&(0,w.jsx)(`div`,{className:`absolute bottom-2 left-2 rounded bg-black/70 px-2 py-1 text-[10px] text-white/80`,children:c(`common.unavailable`)})]});return t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&(A?j(!1):n())},tabIndex:-1,ref:e=>e?.focus(),children:[(0,w.jsx)(`div`,{className:`absolute inset-0 bg-black/55`}),(0,w.jsxs)(`section`,{className:`relative z-10 flex max-h-[88vh] w-full max-w-[980px] flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-2xl dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,onClick:e=>e.stopPropagation(),"aria-label":c(`printers.skipObjects.title`),children:[(0,w.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(k,{className:`h-5 w-5 text-bambu-green`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-white`,children:c(`printers.skipObjects.title`)}),(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-bambu-gray`,children:c(`printers.skipObjects.selectObjectsToSkip`)})]})]}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-gray-500 hover:text-gray-900 dark:text-bambu-gray dark:hover:text-white`,children:(0,w.jsx)(h,{className:`h-5 w-5`})})]}),R?R.objects.length===0?(0,w.jsxs)(`div`,{className:`px-4 py-12 text-center text-bambu-gray`,children:[(0,w.jsx)(`p`,{className:`text-sm`,children:c(`printers.noObjectsFound`)}),(0,w.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:c(`printers.objectsLoadedOnPrintStart`)})]}):(0,w.jsxs)(w.Fragment,{children:[(L?.layer_num??0)<=1&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-amber-400/20 bg-amber-500/10 px-4 py-2 text-xs text-amber-400`,children:[(0,w.jsx)(d,{className:`h-4 w-4 flex-shrink-0`}),c(`printers.skipObjects.waitForLayer`,{layer:L?.layer_num??0})]}),(0,w.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(320px,1fr)_minmax(340px,0.9fr)] overflow-hidden max-md:grid-cols-1 max-md:overflow-y-auto`,children:[(0,w.jsxs)(`div`,{className:`border-r border-gray-200 bg-gray-50 p-4 dark:border-bambu-dark-tertiary dark:bg-bambu-dark-secondary max-md:border-b-0 max-md:border-r-0`,children:[Z(),(0,w.jsxs)(`div`,{className:`mt-3 flex items-center justify-between text-xs text-gray-500 dark:text-bambu-gray`,children:[(0,w.jsxs)(`span`,{children:[_.size,`/`,U.length]}),(0,w.jsxs)(`span`,{children:[R.skipped_count,` `,c(`printers.skipObjects.skipped`)]})]})]}),(0,w.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>x(G?new Set:new Set(U.map(e=>e.id))),className:`flex items-center gap-3 border-b border-gray-200 px-4 py-3 text-left text-sm font-semibold text-gray-900 hover:bg-gray-50 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:[G?(0,w.jsx)(y,{className:`h-5 w-5 text-bambu-green`}):(0,w.jsx)(v,{className:`h-5 w-5 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`flex-1`,children:c(G?`common.deselectAll`:`common.selectAll`)}),(0,w.jsx)(`span`,{className:`text-xs font-normal text-bambu-gray`,children:U.length})]}),(0,w.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:R.objects.map((e,t)=>{let n=_.has(e.id);return(0,w.jsxs)(`button`,{type:`button`,onClick:()=>Y(e),disabled:e.skipped,className:`flex w-full items-center gap-3 border-b border-gray-200 px-4 py-2.5 text-left transition-colors dark:border-bambu-dark-tertiary/60 ${e.skipped?`cursor-not-allowed bg-red-500/5 opacity-55`:n?`bg-bambu-green/15 hover:bg-bambu-green/20`:`hover:bg-gray-50 dark:hover:bg-white/5`}`,children:[e.skipped||n?(0,w.jsx)(y,{className:`h-5 w-5 flex-shrink-0 ${e.skipped?`text-red-400`:`text-bambu-green`}`}):(0,w.jsx)(v,{className:`h-5 w-5 flex-shrink-0 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`w-8 flex-shrink-0 text-xs font-bold text-bambu-gray`,children:t+1}),(0,w.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm ${e.skipped?`text-red-400 line-through`:`text-gray-900 dark:text-white`}`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[`ID `,e.id]})]},e.id)})})]})]}),(0,w.jsxs)(`footer`,{className:`flex items-center gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsx)(`span`,{className:`mr-auto text-sm text-gray-600 dark:text-bambu-gray`,children:_.size===0?c(`printers.skipObjects.noObjectsSelected`):`${_.size}/${U.length}`}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:c(`common.cancel`)}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>T(!0),disabled:!q||J.isPending,className:`rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-35`,children:J.isPending?c(`printers.skipObjects.skipping`):c(`printers.skipObjects.skipSelected`)})]})]}):(0,w.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,w.jsx)(p,{className:`h-6 w-6 animate-spin text-bambu-gray`})})]})]}),C&&(0,w.jsx)(b,{variant:`warning`,title:c(`printers.skipObjects.confirmTitle`),message:K?c(`printers.skipObjects.confirmAllMessage`):W.length===1?c(`printers.skipObjects.confirmMessage`,{name:W[0].name}):c(`printers.skipObjects.confirmMultipleMessage`,{count:W.length}),confirmText:c(`printers.skipObjects.skipSelected`),isLoading:J.isPending,onConfirm:()=>J.mutate([..._]),onCancel:()=>T(!1)}),A&&(0,w.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/90 p-8`,onClick:()=>j(!1),children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>j(!1),className:`absolute right-4 top-4 rounded p-2 text-white/70 hover:text-white`,children:(0,w.jsx)(h,{className:`h-6 w-6`})}),(0,w.jsx)(`div`,{className:`aspect-square max-h-[86vh] w-full max-w-[86vh]`,onClick:e=>e.stopPropagation(),children:Z(!0)})]})]}):null}function j({status:e}){return e===`ok`?(0,w.jsx)(g,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`failed`?(0,w.jsx)(u,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,w.jsx)(x,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function M({printerId:e,printerName:t,onClose:n}){let{t:a}=i(),o=s({mutationFn:()=>r.diagnoseCamera(e)});(0,E.useEffect)(()=>{o.mutate()},[]),(0,E.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let c=o.data;return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,w.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,w.jsx)(_,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:a(`camera.diagnose.modalTitle`,{name:t||``})})]}),(0,w.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:a(`common.close`),children:(0,w.jsx)(h,{className:`w-5 h-5`})})]}),(0,w.jsxs)(`div`,{className:`p-6 space-y-4`,children:[o.isPending&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,w.jsx)(p,{className:`w-4 h-4 animate-spin`}),(0,w.jsx)(`span`,{children:a(`camera.diagnose.running`)})]}),o.isError&&(0,w.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.runFailed`,{error:o.error.message})}),c&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`ol`,{className:`space-y-2`,children:c.stages.map(e=>(0,w.jsxs)(`li`,{className:`flex items-center gap-3 bg-bambu-dark rounded-lg px-4 py-2.5`,children:[(0,w.jsx)(j,{status:e.status}),(0,w.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,w.jsx)(`div`,{className:`text-sm text-white`,children:a(`camera.diagnose.stage.${e.name}`)}),e.code&&(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray font-mono`,children:e.code})]}),(0,w.jsxs)(`div`,{className:`text-xs text-bambu-gray tabular-nums flex-shrink-0`,children:[e.duration_ms,` ms`]})]},e.name))}),(0,w.jsx)(`div`,{className:c.overall_status===`ok`?`rounded-lg bg-bambu-green/10 border border-bambu-green/30 px-4 py-3 text-sm text-bambu-green`:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.summary.${c.summary_code}`,{defaultValue:a(`camera.diagnose.summary.unknown_failure`)})}),(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray space-y-0.5`,children:(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.protocol`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.protocol}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.port`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.port}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.profile`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.profile})]})})]})]}),(0,w.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,w.jsx)(`button`,{onClick:()=>o.mutate(),disabled:o.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:a(`camera.diagnose.retry`)}),(0,w.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:a(`common.close`)})]})]})})}export{C as a,T as i,k as n,A as r,M as t};
|