ConnectionDiagnostic-CQjKNMAx.js 4.9 KB

1
  1. import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{T as t,a as n,k as r,w as i}from"./client-DWQBE01c.js";import{t as a}from"./useMutation-D7HomC3_.js";import{n as o}from"./info-CPhSLaIW.js";import{t as s}from"./circle-check-hi6qvMgh.js";import{t as c}from"./circle-minus-WQH5QP-Y.js";import{t as l}from"./loader-circle-QIogdiwG.js";import{t as u}from"./stethoscope-C07o_kbI.js";import{t as d}from"./triangle-alert-C-5b4OJS.js";import{t as f}from"./x-Ros7hs1-.js";var p=e(r(),1),m=i();function h({status:e}){return e===`pass`?(0,m.jsx)(s,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,m.jsx)(o,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,m.jsx)(d,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,m.jsx)(c,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function g({result:e}){let{t:n}=t(),r=e.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:e.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,m.jsxs)(`div`,{className:`space-y-4`,children:[(0,m.jsx)(`ol`,{className:`space-y-2`,children:e.checks.map(e=>{let t=e.id===`port_rtsps`?{protocol:`RTSPS`,port:322,...e.params}:e.id===`network_mode`&&e.params?.runtime===`container`?{...e.params,runtime:n(`diagnostic.check.network_mode.genericRuntime`)}:e.params,r=e.params?.reason,i=n(`diagnostic.check.${e.id}.${e.status}${r?`_${r}`:``}`,{...t,defaultValue:r?n(`diagnostic.check.${e.id}.${e.status}`,{...t,defaultValue:``}):``});return(0,m.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,m.jsx)(`div`,{className:`mt-0.5`,children:(0,m.jsx)(h,{status:e.status})}),(0,m.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,m.jsx)(`div`,{className:`text-sm text-white`,children:n(`diagnostic.check.${e.id}.title`,t)}),i&&(0,m.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:i})]})]},e.id)})}),(0,m.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${r}`,children:n(`diagnostic.overall.${e.overall}`)})]})}var _=10;function v(e){let{onClose:r,printerName:i}=e,{t:o}=t(),s=`printerId`in e?e.printerId:void 0,c=`connection`in e?e.connection:void 0,d=a({mutationFn:()=>s===void 0?n.diagnoseConnection(c):n.diagnosePrinter(s)});(0,p.useEffect)(()=>{d.mutate()},[]),(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let[h,v]=(0,p.useState)(0);(0,p.useEffect)(()=>{if(!d.isPending){v(0);return}let e=Date.now(),t=window.setInterval(()=>{v(Math.floor((Date.now()-e)/1e3))},500);return()=>window.clearInterval(t)},[d.isPending]);let y=d.data;return(0,m.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,m.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,m.jsx)(u,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,m.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:o(`diagnostic.modalTitle`,{name:i||``})})]}),(0,m.jsx)(`button`,{onClick:r,className:`text-bambu-gray hover:text-white transition-colors`,title:o(`common.close`),children:(0,m.jsx)(f,{className:`w-5 h-5`})})]}),(0,m.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[d.isPending&&(0,m.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,m.jsx)(l,{className:`w-4 h-4 animate-spin`}),(0,m.jsx)(`span`,{children:h>0?o(`diagnostic.runningElapsed`,{elapsed:h}):o(`diagnostic.running`)})]}),s!==void 0&&(0,m.jsx)(`p`,{className:`text-xs text-bambu-gray-light pl-6`,children:o(`diagnostic.waitingForReportHint`,{max:_})})]}),d.isError&&(0,m.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:o(`diagnostic.runFailed`,{error:d.error.message})}),y&&(0,m.jsx)(g,{result:y})]}),(0,m.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,m.jsx)(`button`,{onClick:()=>d.mutate(),disabled:d.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:o(`diagnostic.retry`)}),(0,m.jsx)(`button`,{onClick:r,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:o(`common.close`)})]})]})})}export{g as n,v as t};