diff --git a/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx b/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx index a0cd5a98b..2603b9110 100644 --- a/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx +++ b/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx @@ -740,18 +740,22 @@ export function SpoolBuddyAmsPage() { {assignSpoolModal && ( <> -
+
{ diff --git a/static/assets/index-vlxFmu1X.js b/static/assets/index-ydLRgpbj.js similarity index 99% rename from static/assets/index-vlxFmu1X.js rename to static/assets/index-ydLRgpbj.js index d81c5b4c8..bc494d1e9 100644 --- a/static/assets/index-vlxFmu1X.js +++ b/static/assets/index-ydLRgpbj.js @@ -8731,15 +8731,19 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho ${a("inventory.assignProfileMismatchMessage",{spoolProfile:p.spoolProfile||a("common.unknown"),trayProfile:p.trayProfile||a("common.unknown"),location:p.location})}`:p.type==="partial_profile"?Ne=`${a("inventory.assignPartialMismatchMessage",{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})} ${a("inventory.assignProfileMismatchMessage",{spoolProfile:p.spoolProfile||a("common.unknown"),trayProfile:p.trayProfile||a("common.unknown"),location:p.location})}`:p.type==="profile"&&(Ne=a("inventory.assignProfileMismatchMessage",{spoolProfile:p.spoolProfile||a("common.unknown"),trayProfile:p.trayProfile||a("common.unknown"),location:p.location})),i.jsx(_n,{title:a("inventory.assignMismatchTitle"),message:Ne,confirmText:a("inventory.assignMismatchConfirm"),variant:"warning",isLoading:se.isPending,onConfirm:ae,onCancel:()=>{se.isPending||(m(!1),v(null),f(null))}})})()]})}function trt({isOpen:t,onClose:e,tagId:n,untaggedSpools:r,onLink:a}){const{t:s}=jt(),[o,l]=w.useState(null),c=w.useCallback(()=>{l(null),e()},[e]),d=w.useCallback(m=>{m.key==="Escape"&&c()},[c]);if(w.useEffect(()=>(t&&(document.addEventListener("keydown",d),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",d),document.body.style.overflow=""}),[t,d]),!t)return null;const u=()=>{o&&(a(o),l(null))};return i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in",onClick:c,children:i.jsxs("div",{className:"bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up",onClick:m=>m.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-zinc-700",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-base font-semibold text-zinc-100",children:s("spoolbuddy.dashboard.linkTagTitle","Link Tag to Spool")}),i.jsx("p",{className:"text-sm text-zinc-500 font-mono",children:n})]}),i.jsx("button",{onClick:c,className:"p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto",children:[i.jsx("p",{className:"text-sm text-zinc-400",children:s("spoolbuddy.dashboard.selectSpool","Select a spool to link this tag to:")}),r.length===0?i.jsx("div",{className:"text-center py-8 text-zinc-500",children:s("spoolbuddy.dashboard.noUntagged","No spools without tags found")}):i.jsx("div",{className:"space-y-2",children:r.map(m=>i.jsxs("button",{type:"button",onClick:()=>l(m),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===m.id?"border-green-500 bg-green-500/10":"border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50"}`,children:[i.jsx(O5,{color:m.rgba?`#${m.rgba.slice(0,6)}`:"#808080",isEmpty:!1,size:40}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium text-zinc-100 truncate",children:m.color_name||"Unknown color"}),i.jsxs("div",{className:"text-sm text-zinc-400 truncate",children:[m.brand," • ",m.material,m.subtype&&` ${m.subtype}`]})]}),i.jsxs("div",{className:"text-sm font-mono text-zinc-500",children:[Math.max(0,m.label_weight-m.weight_used),"g"]})]},m.id))})]}),i.jsxs("div",{className:"flex justify-end gap-2 px-5 py-4 border-t border-zinc-700",children:[i.jsx("button",{onClick:c,className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:s("common.cancel","Cancel")}),i.jsx("button",{onClick:u,disabled:!o,className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]",children:s("spoolbuddy.dashboard.linkTag","Link Tag")})]})]})})}const XY=["#00AE42","#FF6B35","#3B82F6","#EF4444","#A855F7","#FBBF24","#14B8A6","#EC4899","#F97316","#22C55E"];function QY(t){return t?t.replace(/[^0-9a-f]/gi,"").toUpperCase():""}function nrt(t,e){const n=QY(t),r=QY(e);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}function rrt(){const{t}=jt(),[e,n]=w.useState(0);w.useEffect(()=>{const a=setInterval(()=>{n(s=>(s+1)%XY.length)},2e3);return()=>clearInterval(a)},[]);const r=XY[e];return i.jsxs("div",{className:"flex flex-col items-center text-center",children:[i.jsxs("div",{className:"relative mb-6 flex items-center justify-center",style:{width:160,height:160},children:[i.jsx("div",{className:"absolute w-24 h-24 rounded-full border-2 border-green-500/30 animate-ping",style:{animationDuration:"2.5s"}}),i.jsx("div",{className:"absolute w-32 h-32 rounded-full border border-green-500/20 animate-ping",style:{animationDuration:"2.5s",animationDelay:"0.4s"}}),i.jsx("div",{className:"absolute w-40 h-40 rounded-full border border-green-500/10 animate-ping",style:{animationDuration:"2.5s",animationDelay:"0.8s"}}),i.jsxs("div",{className:"relative",children:[i.jsx("div",{className:"absolute -inset-4 rounded-full blur-2xl opacity-30 transition-colors duration-1000",style:{backgroundColor:r}}),i.jsx("div",{className:"transition-all duration-1000",children:i.jsx(O5,{color:r,isEmpty:!1,size:100})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xl font-medium text-zinc-300",children:t("spoolbuddy.dashboard.readyToScan","Ready to scan")}),i.jsx("p",{className:"text-sm text-zinc-500",children:t("spoolbuddy.dashboard.idleMessage","Place a spool on the scale to identify it")})]}),i.jsxs("div",{className:"mt-6 flex items-center gap-2 text-sm text-zinc-600",children:[i.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),i.jsx("span",{children:t("spoolbuddy.dashboard.nfcHint","NFC tag will be read automatically")})]})]})}function irt(){const{t}=jt();return i.jsxs("div",{className:"flex flex-col items-center text-center",children:[i.jsx("div",{className:"relative mb-6 flex items-center justify-center",style:{width:160,height:160},children:i.jsx("div",{className:"w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center",children:i.jsx("svg",{className:"w-12 h-12 text-zinc-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728"})})})}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-lg font-medium text-zinc-500",children:t("spoolbuddy.status.deviceOffline","Device Offline")}),i.jsx("p",{className:"text-sm text-zinc-600",children:t("spoolbuddy.status.connectDisplay","Connect the SpoolBuddy display to scan spools")})]}),i.jsxs("div",{className:"mt-6 flex items-center gap-2 text-xs text-zinc-600",children:[i.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0"})}),i.jsx("span",{children:t("spoolbuddy.status.waitingConnection","Waiting for device connection...")})]})]})}function art(){const{sbState:t,selectedPrinterId:e}=fw(),{t:n}=jt(),{data:r=[],refetch:a}=et({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(!1)}),{data:s=[]}=et({queryKey:["printers"],queryFn:()=>fe.getPrinters()}),o=Jh({queries:s.map(W=>({queryKey:["printerStatus",W.id],queryFn:()=>fe.getPrinterStatus(W.id),refetchInterval:1e4}))}),[l,c]=w.useState(null),[d,u]=w.useState(null),[m,p]=w.useState(null),[f,y]=w.useState(!1),[v,b]=w.useState(!1),[g,_]=w.useState(!1),[N,C]=w.useState(!1),k=t.matchedSpool?.tag_uid??t.unknownTagUid??null,P=t.weight,T=t.weightStable,j=w.useRef(null);P===null?j.current=null:(j.current===null||Math.abs(P-j.current)>=3||T)&&(j.current=P);const F=j.current,G=w.useMemo(()=>{if(t.matchedSpool?.id){const W=r.find(ae=>ae.id===t.matchedSpool?.id);if(W)return W}return l?r.find(W=>nrt(W.tag_uid,l))??null:null},[l,t.matchedSpool,r]),z=w.useMemo(()=>r.filter(W=>!W.tag_uid&&!W.archived_at),[r]);w.useEffect(()=>{if(k){const W=m===k;(l!==null&&l!==k||!W&&l!==k)&&(c(k),u(null),p(null)),!W&&P!==null&&T&&u(Math.round(Math.max(0,P)))}else m&&(c(null),p(null),u(null))},[k,P,T,l,m]);const J=()=>{p(l)},I=async W=>{if(l)try{await fe.linkTagToSpool(W.id,{tag_uid:l,tag_type:"generic",data_origin:"nfc_link"}),y(!1),a()}catch(ae){console.error("Failed to link tag:",ae)}},te=async()=>{if(l){C(!0);try{const W=Z??d;await fe.createSpool({material:"PLA",subtype:null,color_name:null,rgba:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:l,tray_uuid:null,data_origin:"spoolbuddy",tag_type:"generic",cost_per_kg:null,last_scale_weight:W,last_weighed_at:W!==null?new Date().toISOString():null}),_(!1),a()}catch(W){console.error("Failed to quick-add spool:",W)}finally{C(!1)}}},Z=P!==null&&(k===l||k===null&&l!==null)?P:null,de=r.length,ue=new Set(r.map(W=>W.material)).size,me=new Set(r.filter(W=>W.brand).map(W=>W.brand)).size;return i.jsxs("div",{className:"h-full flex flex-col p-4",children:[i.jsxs("div",{className:"flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xl font-bold text-zinc-100",children:de}),i.jsx("span",{className:"text-sm text-zinc-500",children:n("spoolbuddy.inventory.spools","Spools")})]}),i.jsx("div",{className:"w-px h-5 bg-zinc-700"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xl font-bold text-zinc-100",children:ue}),i.jsx("span",{className:"text-sm text-zinc-500",children:n("spoolbuddy.spool.material","Materials")})]}),i.jsx("div",{className:"w-px h-5 bg-zinc-700"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xl font-bold text-zinc-100",children:me}),i.jsx("span",{className:"text-sm text-zinc-500",children:n("spoolbuddy.spool.brand","Brands")})]})]}),i.jsxs("div",{className:"flex-1 flex gap-4 min-h-0",children:[i.jsxs("div",{className:"w-5/12 flex flex-col min-h-0",children:[i.jsxs("div",{className:"border border-dashed border-zinc-700/50 rounded-xl p-4",children:[i.jsx("h2",{className:"text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3",children:n("spoolbuddy.dashboard.device","Device")}),i.jsxs("div",{className:"space-y-2.5",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.deviceOnline?"bg-green-500 animate-pulse":"bg-red-500"}`}),i.jsx("span",{className:"text-base text-zinc-400",children:t.deviceOnline?n("spoolbuddy.status.online","Online"):n("spoolbuddy.status.offline","Disconnected")})]}),i.jsxs("div",{className:"flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("svg",{className:`w-4 h-4 ${t.deviceOnline?"text-green-500":"text-zinc-500"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3"})}),i.jsx("span",{className:"text-sm text-zinc-500",children:n("spoolbuddy.spool.scaleWeight","Scale")})]}),i.jsx("span",{className:"text-lg font-mono font-semibold text-zinc-100",children:F!==null?`${Math.abs(F)<=20?0:Math.round(Math.max(0,F))}g`:"—"})]}),i.jsxs("div",{className:"flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("svg",{className:`w-4 h-4 ${t.deviceOnline?"text-green-500":"text-zinc-500"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z"})}),i.jsx("span",{className:"text-sm text-zinc-500",children:"NFC"})]}),i.jsx("span",{className:`text-sm font-medium ${k?"text-green-500":"text-zinc-500"}`,children:k?n("spoolbuddy.dashboard.tagDetected","Tag detected"):n("spoolbuddy.dashboard.noTag","No tag")})]})]})]}),s.length>0&&i.jsxs("div",{className:"mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4",children:[i.jsx("h2",{className:"text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5",children:n("spoolbuddy.dashboard.printers","Printers")}),i.jsx("div",{className:"flex flex-wrap gap-2 overflow-hidden",children:s.map((W,ae)=>{const ce=o[ae]?.data?.connected??!1;return i.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg",title:`${W.name} — ${ce?"Online":"Offline"}`,children:[i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${ce?"bg-green-500":"bg-zinc-600"}`}),i.jsx("span",{className:"text-xs text-zinc-400 truncate max-w-[100px]",children:W.name})]},W.id)})})]})]}),i.jsx("div",{className:"w-7/12 min-h-0",children:i.jsxs("div",{className:"border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col",children:[i.jsx("h2",{className:"text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0",children:n("spoolbuddy.dashboard.currentSpool","Current Spool")}),i.jsx("div",{className:"flex-1 flex items-center justify-center min-h-0",children:t.deviceOnline?(G||t.matchedSpool)&&l&&m!==l?i.jsx(Unt,{spool:{id:G?.id??t.matchedSpool.id,tag_uid:l,material:G?.material??t.matchedSpool.material,subtype:G?.subtype??t.matchedSpool.subtype,color_name:G?.color_name??t.matchedSpool.color_name,rgba:G?.rgba??t.matchedSpool.rgba,brand:G?.brand??t.matchedSpool.brand,label_weight:G?.label_weight??t.matchedSpool.label_weight,core_weight:G?.core_weight??t.matchedSpool.core_weight,weight_used:G?.weight_used??t.matchedSpool.weight_used},scaleWeight:Z??d,onSyncWeight:()=>a(),onAssignToAms:()=>b(!0),onClose:J}):k&&l&&!G&&!t.matchedSpool&&m!==l?i.jsx(Bnt,{tagUid:l,scaleWeight:Z??d,onLinkSpool:z.length>0?()=>y(!0):void 0,onAddToInventory:()=>_(!0),onClose:J}):i.jsx(rrt,{}):i.jsx(irt,{})})]})})]}),G&&l&&i.jsx(ert,{isOpen:v,onClose:()=>b(!1),spool:G,printerId:e}),l&&i.jsx(trt,{isOpen:f,onClose:()=>y(!1),tagId:l,untaggedSpools:z,onLink:I}),g&&l&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:i.jsxs("div",{className:"bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700",children:[i.jsx("h3",{className:"text-lg font-semibold text-zinc-100 mb-3",children:n("spoolbuddy.modal.addToInventory","Add to Inventory")}),i.jsxs("div",{className:"flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4",children:[i.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),i.jsx("p",{className:"text-sm text-amber-200/80",children:n("spoolbuddy.modal.quickAddHint",'For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Link to Spool" here to assign the NFC tag.')})]}),i.jsx("p",{className:"text-sm text-zinc-400 mb-1",children:n("spoolbuddy.modal.quickAddDesc","This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.")}),i.jsx("p",{className:"text-xs text-zinc-500 font-mono mb-5",children:l}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:()=>_(!1),className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:n("common.cancel","Cancel")}),i.jsx("button",{onClick:te,disabled:N,className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]",children:N?n("common.saving","Saving..."):n("spoolbuddy.modal.addAnyway","Add Anyway")})]})]})})]})}function l3(t){return t<=3?`AMS ${String.fromCharCode(65+t)}`:t>=128&&t<=135?`AMS HT ${String.fromCharCode(65+t-128)}`:`AMS ${t}`}function srt(t){return t?{O1D:"H2D",O1E:"H2D Pro",O2D:"H2D Pro",O1C:"H2C",O1C2:"H2C",O1S:"H2S","BL-P001":"X1C","BL-P002":"X1","BL-P003":"X1E",C11:"P1S",C12:"P1P",C13:"P2S",N2S:"A1",N1:"A1 Mini",X1C:"X1C",X1:"X1",X1E:"X1E",P1S:"P1S",P1P:"P1P",P2S:"P2S",A1:"A1","A1 Mini":"A1 Mini",H2D:"H2D","H2D Pro":"H2D Pro",H2C:"H2C",H2S:"H2S"}[t]||t:""}function Bp(t){return!t.tray_type||t.tray_type===""}function ort(t){return t?`#${t.slice(0,6)}`:"#808080"}function lrt(){const{selectedPrinterId:t,setAlert:e}=fw(),{t:n}=jt(),r=cn(),{showToast:a}=pn(),{data:s}=et({queryKey:["printerStatus",t],queryFn:()=>fe.getPrinterStatus(t),enabled:t!==null,staleTime:30*1e3}),{data:o}=et({queryKey:["printer",t],queryFn:()=>fe.getPrinter(t),enabled:t!==null,staleTime:60*1e3}),{data:l}=et({queryKey:["slotPresets",t],queryFn:()=>fe.getSlotPresets(t),enabled:t!==null,staleTime:120*1e3}),{data:c}=et({queryKey:["settings"],queryFn:()=>fe.getSettings(),staleTime:300*1e3}),{data:d}=et({queryKey:["spoolman-status"],queryFn:fe.getSpoolmanStatus,staleTime:60*1e3}),u=d?.enabled&&d?.connected,{data:m}=et({queryKey:["linked-spools"],queryFn:fe.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),p=m?.linked,{data:f}=et({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:t!==null,staleTime:30*1e3}),y=w.useMemo(()=>{const Y={};if(!f)return Y;for(const V of f){const ee=V.spool;if(ee&&ee.label_weight>0&&ee.weight_used!=null){const oe=Math.round(Math.max(0,ee.label_weight-ee.weight_used)/ee.label_weight*100);Y[`${V.ams_id}-${V.tray_id}`]=oe}}return Y},[f]),v=o?.serial_number??"",b=w.useCallback((Y,V,ee)=>{if(!p||!v)return null;const oe=(ee?.tray_uuid||ee?.tag_uid||wu(v,Y,V))?.toUpperCase(),he=oe?p[oe]:void 0;return yN(he)},[p,v]),g=s?.connected??!1,_=w.useRef([]);w.useEffect(()=>{s?.ams&&s.ams.length>0&&(_.current=s.ams)},[s?.ams]);const N=w.useMemo(()=>{const Y=s?.ams;return Y&&Y.length>0?Y:_.current??[]},[s?.ams]),C=w.useMemo(()=>N.filter(Y=>!Y.is_ams_ht),[N]),k=w.useMemo(()=>N.filter(Y=>Y.is_ams_ht),[N]),P=w.useMemo(()=>{const Y={};if(!p||!v)return Y;for(const V of C)for(let ee=0;ee<(V.tray?.length??0);ee++){const oe=V.tray[ee],he=b(V.id,ee,Bp(oe)?null:oe);he!==null&&(Y[`${V.id}-${ee}`]=he)}return Y},[p,v,C,b]),T=w.useRef(void 0),j=s?.tray_now;j!==void 0&&j!==255?T.current=j:j===255&&(T.current=void 0);const A=j!==void 0&&j!==255?j:T.current,F=o?.nozzle_count===2||s?.temperatures?.nozzle_2!==void 0,G=w.useMemo(()=>[...s?.vt_tray??[]].sort((Y,V)=>(Y.id??254)-(V.id??254)),[s?.vt_tray]),z=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,J=w.useRef({});w.useEffect(()=>{s?.ams_extruder_map&&Object.keys(s.ams_extruder_map).length>0&&(J.current=s.ams_extruder_map)},[s?.ams_extruder_map]);const I=s?.ams_extruder_map&&Object.keys(s.ams_extruder_map).length>0?s.ams_extruder_map:J.current,te=w.useCallback(Y=>{if(!F)return null;const V=I[String(Y)],ee=Y>=128?Y-128:Y;return(V!==void 0?V:ee)===1?"L":"R"},[F,I]),[se,Z]=w.useState(null),[de,ue]=w.useState(null),[me,W]=w.useState(null),[ae,ce]=w.useState(null),ge=w.useCallback((Y,V)=>f?.find(ee=>ee.ams_id===Number(Y)&&ee.tray_id===Number(V)),[f]),Ne=w.useCallback((Y,V,ee)=>{if(!p||!v)return;const oe=(ee?.tray_uuid||ee?.tag_uid||wu(v,Y,V))?.toUpperCase();return oe?p[oe]:void 0},[p,v]),H=ht({mutationFn:({printerId:Y,amsId:V,trayId:ee})=>fe.unassignSpool(Y,V,ee),onSuccess:()=>{r.invalidateQueries({queryKey:["spool-assignments",t]}),a(n("inventory.unassignSuccess","Spool unassigned"),"success"),ue(null)}}),X=ht({mutationFn:Y=>fe.unlinkSpool(Y),onSuccess:Y=>{a(n("spoolman.unlinkSuccess")||Y?.message,"success"),r.invalidateQueries({queryKey:["linked-spools"]}),r.invalidateQueries({queryKey:["unlinked-spools"]}),ue(null)},onError:Y=>{a(Y.message||n("spoolman.unlinkFailed"),"error")}}),D=w.useCallback(Y=>A===void 0?null:Y<=3&&Math.floor(A/4)===Y?A%4:Y>=128&&Y<=135&&A===Dx(Y,0,!1)?0:null,[A]),M=w.useCallback((Y,V,ee)=>{const oe=Y>=128?(Y-128)*4+V+64:Y*4+V,he=l?.[oe],pe=I[String(Y)],ie=Y>=128?Y-128:Y,L=pe!==void 0?pe:ie,R={amsId:Y,trayId:V,trayCount:ee&&Y>=128?1:4,tray:ee,trayType:ee?.tray_type||void 0,trayColor:ee?.tray_color||void 0,traySubBrands:ee?.tray_sub_brands||void 0,trayInfoIdx:ee?.tray_info_idx||void 0,extruderId:F?L:void 0,caliIdx:ee?.cali_idx,savedPresetId:he?.preset_id,location:`${l3(Y)} Slot ${V+1}`};ue(R)},[l,I,F]),U=w.useCallback(Y=>{const V=Y.id??254,ee=V-254,oe=l?.[1020+ee],he={amsId:255,trayId:ee,trayCount:1,tray:Bp(Y)?null:Y,trayType:Y.tray_type||void 0,trayColor:Y.tray_color||void 0,traySubBrands:Y.tray_sub_brands||void 0,trayInfoIdx:Y.tray_info_idx||void 0,extruderId:F?V===254?1:0:void 0,caliIdx:Y.cali_idx,savedPresetId:oe?.preset_id,location:F?V===254?"Ext-L":"Ext-R":"External"};ue(he)},[l,F]),K=w.useCallback(()=>{if(!de)return;const{tray:Y,location:V,...ee}=de;ue(null),Z(ee)},[de]),B=w.useCallback(()=>{if(!de||!t)return;const{amsId:Y,trayId:V,trayType:ee,trayColor:oe,location:he}=de;ue(null),W({printerId:t,amsId:Y,trayId:V,trayInfo:{type:ee||"",material:ee,color:oe?.slice(0,6)||"",location:he}})},[de,t]),re=w.useCallback(()=>{if(!de||!t)return;const{amsId:Y,trayId:V,tray:ee}=de,oe=(ee?.tray_uuid||ee?.tag_uid||wu(v,Y,V))?.toUpperCase()||"";ue(null),ce({tagUid:ee?.tag_uid||oe,trayUuid:ee?.tray_uuid||"",printerId:t,amsId:Y,trayId:V})},[de,t,v]),O=w.useCallback(()=>{if(!de||!t)return;const{amsId:Y,trayId:V}=de;H.mutate({printerId:t,amsId:Y,trayId:V})},[de,t,H]);w.useEffect(()=>{if(!g&&t){e({type:"warning",message:n("spoolbuddy.ams.printerDisconnected","Printer disconnected")});return}for(const Y of N)for(const V of Y.tray||[])if(V.remain!==null&&V.remain>=0&&V.remain<15&&V.tray_type){e({type:"warning",message:`Low Filament: ${V.tray_type} (${l3(Y.id)}) - ${V.remain}% remaining`});return}e(null)},[N,g,t,e,n]);const q=w.useMemo(()=>{const Y=[];for(const V of k){const ee=V.tray?.[0]||{id:0,tray_color:null,tray_type:"",tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},oe=b(V.id,0,Bp(ee)?null:ee),he=y[`${V.id}-0`]??null,pe=ee.remain!=null&&ee.remain>=0?ee.remain:null,ie=he===0&&pe!==null&&pe>0?null:he;Y.push({key:`ht-${V.id}`,label:l3(V.id),tray:ee,isEmpty:Bp(ee),isActive:D(V.id)===0,temp:V.temp,humidity:V.humidity,nozzleSide:te(V.id),effectiveFill:oe??ie??pe,onClick:()=>M(V.id,0,Bp(ee)?null:ee)})}for(const V of G){const ee=V.id??254,oe=F&&A===254?ee===254&&s?.active_extruder===1||ee===255&&s?.active_extruder===0:A===ee,he=ee-254,pe=b(255,he,Bp(V)?null:V),ie=y[`255-${he}`]??null,L=V.remain!=null&&V.remain>=0?V.remain:null,R=ie===0&&L!==null&&L>0?null:ie;Y.push({key:`ext-${ee}`,label:F?ee===254?n("printers.extL","Ext-L"):n("printers.extR","Ext-R"):n("printers.ext","Ext"),tray:V,isEmpty:Bp(V),isActive:oe,nozzleSide:null,effectiveFill:pe??R??L,onClick:()=>U(V)})}return Y},[k,G,F,A,s?.active_extruder,n,D,te,M,U,y,b]);return i.jsxs("div",{className:"h-full flex flex-col p-4",children:[i.jsx("div",{className:"flex-1 min-h-0",children:t?g?N.length===0&&G.length===0?i.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:i.jsxs("div",{className:"text-center text-white/50",children:[i.jsx(Ki,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-lg mb-2",children:n("spoolbuddy.ams.noData","No AMS detected")}),i.jsx("p",{className:"text-sm",children:n("spoolbuddy.ams.connectAms","Connect an AMS to see filament slots")})]})}):i.jsxs("div",{className:"flex flex-col gap-3 h-full",children:[i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:C.map(Y=>i.jsx(_le,{unit:Y,activeSlot:D(Y.id),onConfigureSlot:M,isDualNozzle:F,nozzleSide:te(Y.id),thresholds:z,fillOverrides:y,spoolmanFillOverrides:P},Y.id))}),q.length>0&&i.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:q.map(({key:Y,label:V,tray:ee,isEmpty:oe,isActive:he,temp:pe,humidity:ie,nozzleSide:L,effectiveFill:R,onClick:ne})=>{const ye=ort(ee.tray_color);return i.jsxs("div",{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${he?"ring-2 ring-bambu-green":""}`,onClick:ne,children:[i.jsxs("div",{className:"relative w-10 h-10 flex-shrink-0",children:[oe?i.jsx("div",{className:"w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center",children:i.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-gray-600"})}):i.jsxs("svg",{viewBox:"0 0 56 56",className:"w-full h-full",children:[i.jsx("circle",{cx:"28",cy:"28",r:"26",fill:ye}),i.jsx("circle",{cx:"28",cy:"28",r:"20",fill:ye,style:{filter:"brightness(0.85)"}}),i.jsx("ellipse",{cx:"20",cy:"20",rx:"6",ry:"4",fill:"white",opacity:"0.3"}),i.jsx("circle",{cx:"28",cy:"28",r:"8",fill:"#2d2d2d"}),i.jsx("circle",{cx:"28",cy:"28",r:"5",fill:"#1a1a1a"})]}),he&&i.jsx("div",{className:"absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full"})]}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"text-xs text-white/50 font-medium truncate",children:V}),L&&i.jsx(I5,{side:L})]}),i.jsx("div",{className:"text-sm text-white/80 truncate",children:oe?"Empty":ee.tray_type||"?"}),(pe!=null||ie!=null)&&i.jsxs("div",{className:"flex items-center gap-1.5",children:[pe!=null&&i.jsx(Sle,{temp:pe,goodThreshold:z?.tempGood,fairThreshold:z?.tempFair}),ie!=null&&i.jsx(wle,{humidity:ie,goodThreshold:z?.humidityGood,fairThreshold:z?.humidityFair})]})]}),!oe&&R!=null&&R>=0&&i.jsx("div",{className:"w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse",children:i.jsx("div",{className:"w-full rounded-full",style:{height:`${R}%`,backgroundColor:sx(R)}})})]},Y)})})]}):i.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:i.jsx("div",{className:"text-center text-white/50",children:i.jsx("p",{className:"text-lg mb-2",children:n("spoolbuddy.ams.printerDisconnected","Printer disconnected")})})}):i.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:i.jsxs("div",{className:"text-center text-white/50",children:[i.jsx("p",{className:"text-lg mb-2",children:n("spoolbuddy.ams.noPrinter","No printer selected")}),i.jsx("p",{className:"text-sm",children:n("spoolbuddy.ams.selectPrinter","Select a printer from the top bar")})]})})}),se&&t&&i.jsx(die,{isOpen:!!se,onClose:()=>Z(null),printerId:t,slotInfo:se,printerModel:srt(o?.model??null)||void 0,fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:["slotPresets",t]}),r.invalidateQueries({queryKey:["printerStatus",t]})}}),de&&t&&(()=>{const Y=ge(de.amsId,de.trayId),V=Ne(de.amsId,de.trayId,de.tray);return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>ue(null)}),i.jsxs("div",{className:"relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[de.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${de.trayColor.slice(0,6)}`}}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:de.location}),de.traySubBrands&&i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",de.traySubBrands,")"]})]}),i.jsx("button",{onClick:()=>ue(null),className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-2",children:[!u&&Y?.spool&&i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:n("inventory.assignedSpool","Assigned spool")}),i.jsxs("div",{className:"flex items-center gap-2",children:[Y.spool.rgba&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:`#${Y.spool.rgba.substring(0,6)}`}}),i.jsxs("span",{className:"text-sm text-white",children:[Y.spool.brand?`${Y.spool.brand} `:"",Y.spool.material,Y.spool.color_name?` - ${Y.spool.color_name}`:""]})]})]}),u&&V&&i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:n("spoolman.linkedSpool","Linked spool")}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("span",{className:"text-sm text-white",children:["Spoolman #",V.id,V.remaining_weight!=null?` (${Math.round(V.remaining_weight)}g)`:""]})})]}),i.jsxs("button",{onClick:K,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left",children:[i.jsx(vd,{className:"w-5 h-5 text-bambu-blue flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:n("configureAmsSlot.title")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("spoolbuddy.ams.configureDesc","Set filament preset, K-profile, and color")})]})]}),!u&&(Y?i.jsxs("button",{onClick:O,disabled:H.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left",children:[i.jsx(Bh,{className:"w-5 h-5 text-amber-400 flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-amber-400 font-medium",children:n("inventory.unassignSpool","Unassign")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("spoolbuddy.ams.unassignDesc","Remove inventory spool from this slot")})]})]}):i.jsxs("button",{onClick:B,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left",children:[i.jsx(Ii,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:n("inventory.assignSpool")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("spoolbuddy.ams.assignDesc","Track a spool from your inventory")})]})]})),u&&(V?.id?i.jsxs("button",{onClick:()=>X.mutate(V.id),disabled:X.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left",children:[i.jsx(Bh,{className:"w-5 h-5 text-amber-400 flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-amber-400 font-medium",children:n("spoolman.unlinkSpool")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("spoolbuddy.ams.unlinkDesc","Remove Spoolman link from this slot")})]})]}):i.jsxs("button",{onClick:re,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left",children:[i.jsx(Fu,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:n("spoolman.linkToSpoolman")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("spoolbuddy.ams.linkDesc","Link a Spoolman spool to this slot")})]})]}))]})]})]})})(),me&&i.jsxs(i.Fragment,{children:[i.jsx("style",{children:` - .sb-assign-wrap .relative.max-w-2xl { - max-height: 90vh; - display: flex; - flex-direction: column; + [data-sb-assign] [class*="max-w-2xl"] { + max-height: 90vh !important; + display: flex !important; + flex-direction: column !important; } - .sb-assign-wrap .relative.max-w-2xl > .p-4.space-y-4 { - flex: 1 1 0; - min-height: 0; - overflow-y: auto; + [data-sb-assign] [class*="max-w-2xl"] > [class*="space-y"] { + flex: 1 1 0 !important; + min-height: 0 !important; + overflow-y: auto !important; } - `}),i.jsx("div",{className:"sb-assign-wrap",children:i.jsx(cie,{isOpen:!!me,onClose:()=>{W(null),r.invalidateQueries({queryKey:["spool-assignments",t]})},printerId:me.printerId,amsId:me.amsId,trayId:me.trayId,trayInfo:me.trayInfo})})]}),ae&&i.jsx(lie,{isOpen:!!ae,onClose:()=>ce(null),tagUid:ae.tagUid,trayUuid:ae.trayUuid,printerId:ae.printerId,amsId:ae.amsId,trayId:ae.trayId})]})}function crt({type:t,deviceId:e,onClose:n}){const{t:r}=jt(),[a,s]=w.useState(!1),[o,l]=w.useState(""),[c,d]=w.useState(""),[u,m]=w.useState(!1);w.useEffect(()=>{const y=v=>{v.key==="Escape"&&!a&&n()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[a,n]);const p=w.useCallback(async()=>{s(!0),l(""),d(""),m(!0);try{l(r("spoolbuddy.diagnostic.queuing",`Queuing diagnostic on device... + [data-sb-assign] [class*="max-w-2xl"] > [class*="border-b"], + [data-sb-assign] [class*="max-w-2xl"] > [class*="border-t"] { + flex-shrink: 0 !important; + } + `}),i.jsx("div",{"data-sb-assign":"",children:i.jsx(cie,{isOpen:!!me,onClose:()=>{W(null),r.invalidateQueries({queryKey:["spool-assignments",t]})},printerId:me.printerId,amsId:me.amsId,trayId:me.trayId,trayInfo:me.trayInfo})})]}),ae&&i.jsx(lie,{isOpen:!!ae,onClose:()=>ce(null),tagUid:ae.tagUid,trayUuid:ae.trayUuid,printerId:ae.printerId,amsId:ae.amsId,trayId:ae.trayId})]})}function crt({type:t,deviceId:e,onClose:n}){const{t:r}=jt(),[a,s]=w.useState(!1),[o,l]=w.useState(""),[c,d]=w.useState(""),[u,m]=w.useState(!1);w.useEffect(()=>{const y=v=>{v.key==="Escape"&&!a&&n()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[a,n]);const p=w.useCallback(async()=>{s(!0),l(""),d(""),m(!0);try{l(r("spoolbuddy.diagnostic.queuing",`Queuing diagnostic on device... `)),await zi.queueDiagnostics(e,t);let y=null;const v=60;let b=0;for(;bsetTimeout(g,500));try{y=await zi.getDiagnosticResult(e,t);break}catch{b++,b%4===0&&l(g=>g+".")}}if(!y)throw new Error("Diagnostic timed out - device did not report results");l(y.output),y.success||d(`Exit code: ${y.exit_code}`)}catch(y){d(y instanceof Error?y.message:"Unknown error"),l("")}finally{s(!1)}},[t,e,r]),f=t==="scale"?r("spoolbuddy.diagnostic.scaleTitle","Scale Diagnostic"):t==="read_tag"?r("spoolbuddy.diagnostic.readTagTitle","Read Tag Diagnostic"):r("spoolbuddy.diagnostic.nfcTitle","NFC Reader Diagnostic");return i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in",onClick:n,children:i.jsxs("div",{className:"bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up",onClick:y=>y.stopPropagation(),children:[i.jsxs("div",{className:"flex justify-between items-center p-4 border-b border-zinc-700",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:f}),i.jsx("button",{onClick:n,className:"text-zinc-400 hover:text-white transition-colors","aria-label":"Close",children:i.jsx(qt,{size:20})})]}),i.jsx("div",{className:"flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm",children:a?i.jsxs("div",{className:"flex items-center gap-2 text-green-400",children:[i.jsx("div",{className:"animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full"}),i.jsx("span",{children:r("spoolbuddy.diagnostic.running","Running diagnostic on device...")})]}):o?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"text-green-400 whitespace-pre-wrap break-words",children:o}),c&&i.jsxs("div",{className:"text-red-400 mt-2",children:["❌ ",c]})]}):u?i.jsx("div",{children:c?i.jsxs("div",{className:"text-red-400",children:["ERROR: ",c]}):i.jsx("span",{className:"text-green-400",children:r("spoolbuddy.diagnostic.completed","Diagnostic completed successfully.")})}):i.jsxs("div",{className:"text-zinc-500",children:[r("spoolbuddy.diagnostic.clickStart",'Click "Run Diagnostic" to start the hardware diagnostic on')," ",e,"."]})}),i.jsxs("div",{className:"flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800",children:[i.jsx("button",{onClick:p,disabled:a,className:"flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors",children:a?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full"}),r("spoolbuddy.diagnostic.runningBtn","Running...")]}):u?i.jsxs(i.Fragment,{children:[i.jsx(Qge,{size:16}),r("spoolbuddy.diagnostic.runAgain","Run Again")]}):i.jsxs(i.Fragment,{children:[i.jsx(Ks,{size:16}),r("spoolbuddy.diagnostic.runBtn","Run Diagnostic")]})}),i.jsx("button",{onClick:n,className:"px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors",children:r("spoolbuddy.diagnostic.close","Close")})]})]})})}function drt(t){if(t<60)return`${t}s`;if(t<3600)return`${Math.floor(t/60)}m`;const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return`${e}h ${n}m`}function urt(t){if(!t)return"-";try{const e=new Date(t);return e.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+e.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}catch{return"-"}}const mrt=[{label:"Off",value:0},{label:"1m",value:60},{label:"2m",value:120},{label:"5m",value:300},{label:"10m",value:600},{label:"30m",value:1800}];function hrt({device:t}){const{t:e}=jt(),[n,r]=w.useState(null),[a,s]=w.useState(""),[o,l]=w.useState(""),[c,d]=w.useState(!1),[u,m]=w.useState(null);w.useEffect(()=>{!a&&t.backend_url&&s(t.backend_url)},[t.backend_url,a]);const p=async()=>{if(!a.trim()){m({type:"error",text:e("spoolbuddy.settings.systemFieldsRequired","Backend URL is required.")});return}d(!0),m(null);try{await zi.updateSystemConfig(t.device_id,a.trim(),o.trim()||void 0),m({type:"ok",text:e("spoolbuddy.settings.systemQueued","Config queued.")})}catch(f){m({type:"error",text:f instanceof Error?f.message:e("common.error","Error")})}finally{d(!1)}};return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-2",children:e("spoolbuddy.settings.nfcReader","NFC Reader")}),i.jsxs("div",{className:"space-y-1.5 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.type","Type")}),i.jsx("span",{className:"text-zinc-300 font-mono",children:t.nfc_reader_type||"N/A"})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.connection","Connection")}),i.jsx("span",{className:"text-zinc-300 font-mono",children:t.nfc_connection||"N/A"})]}),i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.status.status","Status")}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${t.nfc_ok?"bg-green-500":t.nfc_reader_type?"bg-red-500":"bg-zinc-600"}`}),i.jsx("span",{className:t.nfc_ok?"text-green-400":t.nfc_reader_type?"text-red-400":"text-zinc-500",children:t.nfc_ok?e("spoolbuddy.status.nfcReady","Ready"):t.nfc_reader_type?e("common.error","Error"):e("spoolbuddy.settings.notConnected","N/A")})]})]})]})]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-2",children:e("spoolbuddy.settings.deviceInfo","Device Info")}),i.jsxs("div",{className:"space-y-1.5 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.hostname","Host")}),i.jsx("span",{className:"text-zinc-300 truncate ml-2",children:t.hostname})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:"IP"}),i.jsx("span",{className:"text-zinc-300",children:t.ip_address})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.uptime","Uptime")}),i.jsx("span",{className:"text-zinc-300",children:drt(t.uptime_s)})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:"ID"}),i.jsx("span",{className:"text-zinc-400 font-mono truncate ml-2",children:t.device_id})]})]})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3 space-y-2",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300",children:e("spoolbuddy.settings.systemConfig","Backend & Auth")}),i.jsx("input",{value:a,onChange:f=>s(f.target.value),placeholder:"http://192.168.1.100:5000",className:"w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"password",value:o,onChange:f=>l(f.target.value),placeholder:e("spoolbuddy.settings.apiTokenPlaceholder","API token"),className:"flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs"}),i.jsx("button",{onClick:p,disabled:c,className:"px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100",children:e("spoolbuddy.settings.saveConfig","Save")})]}),u&&i.jsx("div",{className:`text-xs ${u.type==="ok"?"text-green-400":"text-red-400"}`,children:u.text})]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3 flex flex-col gap-2",children:[i.jsxs("button",{onClick:()=>r("nfc"),className:"flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2",children:[i.jsx(mQ,{className:"w-4 h-4 text-blue-300 shrink-0"}),i.jsx("span",{className:"text-xs font-medium text-blue-100",children:e("spoolbuddy.settings.nfcDiagnostic","NFC Diagnostic")})]}),i.jsxs("button",{onClick:()=>r("scale"),className:"flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2",children:[i.jsx(Wl,{className:"w-4 h-4 text-yellow-300 shrink-0"}),i.jsx("span",{className:"text-xs font-medium text-yellow-100",children:e("spoolbuddy.settings.scaleDiagnostic","Scale Diagnostic")})]}),i.jsxs("button",{onClick:()=>r("read_tag"),className:"flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2",children:[i.jsx(Ss,{className:"w-4 h-4 text-emerald-300 shrink-0"}),i.jsx("span",{className:"text-xs font-medium text-emerald-100",children:e("spoolbuddy.settings.readTagDiagnostic","Read Tag")})]})]})]}),n&&t&&i.jsx(crt,{type:n,deviceId:t.device_id,onClose:()=>r(null)})]})}function prt({device:t,onBrightnessChange:e,onBlankTimeoutChange:n}){const{t:r}=jt(),[a,s]=w.useState(t.display_brightness),[o,l]=w.useState(t.display_blank_timeout),[c,d]=w.useState(!1),u=w.useRef(void 0),m=w.useRef(void 0);w.useEffect(()=>{s(t.display_brightness),l(t.display_blank_timeout)},[t.display_brightness,t.display_blank_timeout]);const p=w.useCallback(()=>{d(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>d(!1),1500)},[]),f=w.useCallback((b,g)=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{zi.updateDisplay(t.device_id,b,g).then(()=>p()).catch(_=>console.error("Failed to update display:",_))},300)},[t.device_id,p]),y=b=>{s(b),e(b),f(b,o)},v=b=>{l(b),n(b),f(a,b)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300",children:r("spoolbuddy.settings.brightness","Brightness")}),c&&i.jsxs("span",{className:"text-xs text-green-400 flex items-center gap-1 animate-pulse",children:[i.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),r("spoolbuddy.settings.saved","Saved")]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("svg",{className:"w-4 h-4 text-zinc-500 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}),i.jsx("input",{type:"range",min:0,max:100,value:a,onChange:b=>y(parseInt(b.target.value)),className:"flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-sm font-mono text-zinc-400 w-10 text-right",children:[a,"%"]})]}),!t.has_backlight&&i.jsx("p",{className:"text-xs text-zinc-600 mt-2",children:r("spoolbuddy.settings.noBacklight","No DSI backlight detected. Brightness control requires a DSI display.")})]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-4",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-1",children:r("spoolbuddy.settings.screenBlank","Screen Blank Timeout")}),i.jsx("p",{className:"text-xs text-zinc-500 mb-3",children:r("spoolbuddy.settings.screenBlankDesc","Screen turns off after inactivity. Touch to wake.")}),i.jsx("div",{className:"grid grid-cols-3 gap-2",children:mrt.map(b=>i.jsx("button",{onClick:()=>v(b.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${o===b.value?"bg-green-600 text-white":"bg-zinc-700 text-zinc-300 hover:bg-zinc-600"}`,children:b.label},b.value))})]}),i.jsx("p",{className:"text-xs text-zinc-600 text-center",children:r("spoolbuddy.settings.displayNote","Brightness is applied as a software filter.")})]})}function frt({step:t,labels:e}){return i.jsxs("div",{className:"flex flex-col items-center w-16 shrink-0 pt-1",children:[i.jsx("div",{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${t==="tare"?"bg-green-600 text-white":"bg-green-600/20 text-green-400"}`,children:t==="weight"?i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):"1"}),i.jsx("span",{className:`text-[10px] mt-0.5 ${t==="tare"?"text-green-400 font-medium":"text-green-400/60"}`,children:e.tare}),i.jsx("div",{className:`w-px h-5 my-1 ${t==="weight"?"bg-green-600/40":"bg-zinc-700"}`}),i.jsx("div",{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${t==="weight"?"bg-green-600 text-white":"bg-zinc-700 text-zinc-500"}`,children:"2"}),i.jsx("span",{className:`text-[10px] mt-0.5 ${t==="weight"?"text-green-400 font-medium":"text-zinc-600"}`,children:e.weight})]})}function grt({device:t,weight:e,weightStable:n,rawAdc:r}){const{t:a}=jt(),[s,o]=w.useState("idle"),[l,c]=w.useState("500"),[d,u]=w.useState(null),[m,p]=w.useState(!1),[f,y]=w.useState(null),v=_=>{_==="backspace"?c(N=>N.slice(0,-1)||""):_==="."&&!l.includes(".")?c(N=>N+"."):_>="0"&&_<="9"&&c(N=>N==="0"?_:N+_)},b=async()=>{p(!0),y(null);try{await zi.tare(t.device_id),y({type:"ok",msg:a("spoolbuddy.settings.tareSet","Tare command sent. Waiting for device...")})}catch{y({type:"error",msg:a("spoolbuddy.settings.tareFailed","Failed to send tare command")})}finally{p(!1)}},g=async()=>{if(s==="tare"){p(!0),y(null);try{u(r),await zi.tare(t.device_id),y({type:"ok",msg:a("spoolbuddy.settings.zeroSet","Zero point set. Place known weight on scale.")}),o("weight")}catch{y({type:"error",msg:a("spoolbuddy.settings.tareFailed","Failed to send tare command")})}finally{p(!1)}}else if(s==="weight"){const _=parseFloat(l);if(r===null||!_||_<=0)return;p(!0),y(null);try{await zi.setCalibrationFactor(t.device_id,_,r,d??void 0),y({type:"ok",msg:a("spoolbuddy.settings.calibrationDone","Calibration complete!")}),o("idle")}catch{y({type:"error",msg:a("spoolbuddy.settings.calibrationFailed","Calibration failed")})}finally{p(!1)}}};return s==="idle"?i.jsxs("div",{className:"flex flex-col h-full",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3 mb-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${n?"bg-green-500":"bg-amber-500 animate-pulse"}`}),i.jsx("span",{className:"text-lg font-mono text-zinc-200",children:e!==null?`${e.toFixed(1)} g`:"-- g"})]}),i.jsxs("div",{className:"text-xs text-zinc-500 text-right",children:[i.jsxs("span",{children:[a("spoolbuddy.settings.tareOffset","Tare"),": ",t.tare_offset]}),i.jsx("span",{className:"mx-1.5",children:"·"}),i.jsxs("span",{children:[a("spoolbuddy.settings.calFactor","Factor"),": ",t.calibration_factor.toFixed(2)]})]})]}),t.last_calibrated_at&&i.jsxs("div",{className:"text-xs text-zinc-600 mt-1",children:[a("spoolbuddy.settings.lastCalibrated","Last calibrated"),": ",urt(t.last_calibrated_at)]})]}),f&&i.jsx("div",{className:`rounded-lg px-3 py-2 mb-3 text-sm ${f.type==="ok"?"bg-green-900/30 text-green-300 border border-green-800":"bg-red-900/30 text-red-300 border border-red-800"}`,children:f.msg}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:b,disabled:m,className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2",children:[m&&i.jsxs("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),a("spoolbuddy.weight.tare","Tare")]}),i.jsx("button",{onClick:()=>{o("tare"),y(null)},className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:a("spoolbuddy.weight.calibrate","Calibrate")})]})]}):i.jsxs("div",{className:"flex gap-3",children:[i.jsx(frt,{step:s,labels:{tare:a("spoolbuddy.weight.tare","Tare"),weight:a("spoolbuddy.settings.knownWeight","Known weight")}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5",children:[i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${n?"bg-green-500":"bg-amber-500 animate-pulse"}`}),i.jsx("span",{className:"text-sm font-mono text-zinc-200",children:e!==null?`${e.toFixed(1)} g`:"-- g"}),i.jsx("span",{className:`text-xs ml-auto ${n?"text-green-400":"text-amber-400"}`,children:n?a("spoolbuddy.settings.stable","Stable"):a("spoolbuddy.settings.settling","Settling...")})]}),f&&i.jsx("div",{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${f.type==="ok"?"bg-green-900/30 text-green-300 border border-green-800":"bg-red-900/30 text-red-300 border border-red-800"}`,children:f.msg}),s==="tare"?i.jsx("p",{className:"text-sm text-zinc-300 mb-3",children:a("spoolbuddy.settings.calStep1","Remove all items from the scale and press Set Zero.")}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx("span",{className:"text-xs text-zinc-400 shrink-0",children:a("spoolbuddy.settings.knownWeight","Known weight")}),i.jsxs("div",{className:"flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100",children:[l||"0",i.jsx("span",{className:"text-zinc-500 ml-1",children:"g"})]})]}),i.jsx("div",{className:"grid grid-cols-4 gap-1 mb-1.5",children:["7","8","9","backspace","4","5","6",".","1","2","3","0"].map(_=>i.jsx("button",{onClick:()=>v(_),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${_==="backspace"?"bg-zinc-700 text-zinc-300 hover:bg-zinc-600":"bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700"}`,children:_==="backspace"?"⌫":_},_))})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:()=>{o("idle"),y(null)},className:"flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]",children:a("common.cancel","Cancel")}),i.jsxs("button",{onClick:g,disabled:m,className:"flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2",children:[m&&i.jsxs("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),s==="tare"?a("spoolbuddy.settings.setZero","Set Zero"):a("spoolbuddy.settings.calibrateNow","Calibrate")]})]})]})]})}function brt({device:t}){const{t:e}=jt(),[n,r]=w.useState(null),[a,s]=w.useState(null),[o,l]=w.useState(!1),[c,d]=w.useState(!1),u=t.update_status==="pending"||t.update_status==="updating";w.useEffect(()=>{u&&n==="applying"&&r(null)},[u,n]),w.useEffect(()=>{const N=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener("spoolbuddy-online",N),()=>window.removeEventListener("spoolbuddy-online",N)},[u]);const{data:m,refetch:p}=et({queryKey:["spoolbuddy-update-check",t.device_id],queryFn:()=>zi.checkDaemonUpdate(t.device_id),staleTime:0}),{data:f}=et({queryKey:["spoolbuddy-ssh-key"],queryFn:()=>zi.getSSHPublicKey(),enabled:o,staleTime:1/0}),y=async()=>{r("checking"),s(null);try{await p()}finally{r(null)}},v=async()=>{r("applying"),s(null);try{await zi.triggerUpdate(t.device_id)}catch(N){s(N instanceof Error?N.message:"Failed to trigger update"),r(null)}},b=n!=null||u,g=()=>{f?.public_key&&(navigator.clipboard.writeText(f.public_key),d(!0),setTimeout(()=>d(!1),2e3))},_=t.firmware_version||(m?.current_version&&m.current_version!=="0.0.0"?m.current_version:null);return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3 space-y-3",children:[i.jsxs("div",{className:"flex justify-between items-center text-sm",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.currentVersion","Current Version")}),i.jsx("span",{className:"text-zinc-200 font-mono",children:_||i.jsx("span",{className:"text-zinc-500 italic text-xs",children:e("spoolbuddy.settings.versionPending","Waiting for daemon...")})})]}),b?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("svg",{className:"w-4 h-4 animate-spin text-green-400 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),i.jsx("span",{className:"text-green-300 text-xs",children:n==="checking"?e("spoolbuddy.settings.checking","Checking for updates..."):t.update_message||e("spoolbuddy.settings.updateWaiting","Updating...")})]}):t.update_status==="error"?i.jsx("p",{className:"text-xs text-red-300",children:t.update_message||e("spoolbuddy.settings.updateFailed","Update failed")}):a?i.jsx("p",{className:"text-xs text-red-300",children:a}):m?.update_available?i.jsxs("p",{className:"text-xs text-green-300",children:[e("spoolbuddy.settings.updateAvailable","Update available"),": ",_," → ",m.latest_version]}):null,!b&&(m?.update_available?i.jsx("button",{onClick:v,disabled:!t.online,className:"w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors",children:t.online?e("spoolbuddy.settings.applyUpdate","Apply Update"):e("spoolbuddy.settings.deviceOffline","Device Offline")}):i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:y,className:"flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors",children:e("spoolbuddy.settings.checkUpdates","Check for Updates")}),i.jsx("button",{onClick:v,disabled:!t.online,className:"px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors",children:e("spoolbuddy.settings.forceUpdate","Force Update")})]}))]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsxs("button",{onClick:()=>l(!o),className:"w-full flex justify-between items-center text-xs",children:[i.jsx("span",{className:"font-medium text-zinc-400",children:e("spoolbuddy.settings.sshSetup","SSH Setup")}),i.jsx("svg",{className:`w-3 h-3 text-zinc-500 transition-transform ${o?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),o&&i.jsxs("div",{className:"mt-2 space-y-2",children:[i.jsx("p",{className:"text-xs text-zinc-500",children:e("spoolbuddy.settings.sshDescription","SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.")}),f?.public_key?i.jsxs("div",{className:"relative",children:[i.jsx("pre",{className:"bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap",children:f.public_key}),i.jsx("button",{onClick:g,className:"absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors",children:c?e("common.copied","Copied!"):e("common.copy","Copy")})]}):i.jsx("span",{className:"text-[10px] text-zinc-500 italic",children:e("spoolbuddy.settings.sshKeyLoading","Loading...")})]})]})]})}function ZY({percent:t,color:e}){return i.jsx("div",{className:"w-full h-2 bg-zinc-700 rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all ${e}`,style:{width:`${Math.min(100,Math.max(0,t))}%`}})})}function xrt(t){const e=Math.floor(t/86400),n=Math.floor(t%86400/3600),r=Math.floor(t%3600/60);return e>0?`${e}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function yrt({device:t}){const{t:e}=jt(),n=t.system_stats;if(!n)return i.jsx("div",{className:"flex items-center justify-center h-32",children:i.jsx("p",{className:"text-sm text-zinc-500",children:e("spoolbuddy.settings.systemStatsWaiting","Waiting for system stats...")})});const r=n.memory,a=n.disk,s=(n.cpu_temp_c??0)>=80?"text-red-400":(n.cpu_temp_c??0)>=65?"text-amber-400":"text-green-400",o=(r?.percent??0)>=90?"bg-red-500":(r?.percent??0)>=70?"bg-amber-500":"bg-green-500",l=(a?.percent??0)>=90?"bg-red-500":(a?.percent??0)>=70?"bg-amber-500":"bg-green-500";return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-2",children:"CPU"}),i.jsxs("div",{className:"space-y-1.5 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.cores","Cores")}),i.jsx("span",{className:"text-zinc-300 font-mono",children:n.cpu_count??"-"})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.loadAvg","Load Avg")}),i.jsx("span",{className:"text-zinc-300 font-mono",children:n.load_avg?n.load_avg.join(" / "):"-"})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.temp","Temp")}),i.jsx("span",{className:`font-mono font-medium ${s}`,children:n.cpu_temp_c!=null?`${n.cpu_temp_c}°C`:"-"})]})]})]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-2",children:e("spoolbuddy.settings.memory","Memory")}),r?i.jsxs("div",{className:"space-y-1.5",children:[i.jsx(ZY,{percent:r.percent??0,color:o}),i.jsxs("div",{className:"space-y-1 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.used","Used")}),i.jsxs("span",{className:"text-zinc-300 font-mono",children:[r.used_mb," / ",r.total_mb," MB"]})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.available","Free")}),i.jsxs("span",{className:"text-zinc-300 font-mono",children:[r.available_mb," MB"]})]})]})]}):i.jsx("span",{className:"text-xs text-zinc-500",children:"-"})]})]}),i.jsx("div",{className:"bg-zinc-800 rounded-lg px-3 py-2",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 shrink-0",children:e("spoolbuddy.settings.disk","Disk")}),a?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex-1",children:i.jsx(ZY,{percent:a.percent??0,color:l})}),i.jsxs("span",{className:"text-xs text-zinc-300 font-mono shrink-0",children:[a.used_gb," / ",a.total_gb," GB"]})]}):i.jsx("span",{className:"text-xs text-zinc-500",children:"-"})]})}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-1.5",children:e("spoolbuddy.settings.osInfo","OS")}),i.jsxs("div",{className:"space-y-1 text-xs",children:[n.os?.os&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.distro","Distro")}),i.jsx("span",{className:"text-zinc-300 truncate ml-2",children:n.os.os})]}),n.os?.kernel&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.kernel","Kernel")}),i.jsx("span",{className:"text-zinc-300 font-mono truncate ml-2",children:n.os.kernel})]}),n.os?.arch&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.arch","Arch")}),i.jsx("span",{className:"text-zinc-300 font-mono",children:n.os.arch})]})]})]}),i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-3",children:[i.jsx("h3",{className:"text-sm font-semibold text-zinc-300 mb-1.5",children:e("spoolbuddy.settings.runtime","Runtime")}),i.jsxs("div",{className:"space-y-1 text-xs",children:[n.os?.python&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:"Python"}),i.jsx("span",{className:"text-zinc-300 font-mono",children:n.os.python})]}),n.system_uptime_s!=null&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:e("spoolbuddy.settings.systemUptime","Uptime")}),i.jsx("span",{className:"text-zinc-300",children:xrt(n.system_uptime_s)})]})]})]})]})]})}function vrt(){const{sbState:t,setDisplayBrightness:e,setDisplayBlankTimeout:n}=fw(),{t:r}=jt(),[a,s]=w.useState("device"),{data:o=[]}=et({queryKey:["spoolbuddy-devices"],queryFn:()=>zi.getDevices(),refetchInterval:1e4}),l=t.deviceId?o.find(d=>d.device_id===t.deviceId)??o[0]:o[0],c=[{id:"device",label:r("spoolbuddy.settings.tabDevice","Device")},{id:"display",label:r("spoolbuddy.settings.tabDisplay","Display")},{id:"scale",label:r("spoolbuddy.settings.tabScale","Scale")},{id:"updates",label:r("spoolbuddy.settings.tabUpdates","Updates")},{id:"system",label:r("spoolbuddy.settings.tabSystem","System")}];return i.jsxs("div",{className:"h-full flex flex-col p-4",children:[i.jsx("h1",{className:"text-xl font-semibold text-zinc-100 mb-3",children:r("spoolbuddy.nav.settings","Settings")}),i.jsx("div",{className:"flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4",children:c.map(d=>i.jsx("button",{onClick:()=>s(d.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${a===d.id?"bg-zinc-700 text-zinc-100":"text-zinc-500 hover:text-zinc-300"}`,children:d.label},d.id))}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:l?i.jsxs(i.Fragment,{children:[a==="device"&&i.jsx(hrt,{device:l}),a==="display"&&i.jsx(prt,{device:l,onBrightnessChange:e,onBlankTimeoutChange:n}),a==="scale"&&i.jsx(grt,{device:l,weight:t.weight,weightStable:t.weightStable,rawAdc:t.rawAdc}),a==="updates"&&i.jsx(brt,{device:l}),a==="system"&&i.jsx(yrt,{device:l})]}):i.jsx("div",{className:"flex items-center justify-center h-32",children:i.jsx("div",{className:"text-center text-zinc-500",children:i.jsx("p",{className:"text-sm",children:r("spoolbuddy.settings.noDevice","No SpoolBuddy device found")})})})})]})}function wrt({device:t,weight:e,weightStable:n,rawAdc:r}){const{t:a}=jt(),[s,o]=w.useState(!1),[l,c]=w.useState("idle"),[d,u]=w.useState("500"),[m,p]=w.useState(null),[f,y]=w.useState(!1),v=N=>{N==="backspace"?u(C=>C.slice(0,-1)||""):N==="."&&!d.includes(".")?u(C=>C+"."):N>="0"&&N<="9"&&u(C=>C==="0"?N:C+N)},b=async()=>{y(!0);try{await zi.tare(t.device_id)}catch(N){console.error("Failed to tare:",N)}finally{y(!1)}},g=()=>{c("tare")},_=async()=>{if(l==="tare"){o(!0);try{p(r),await zi.tare(t.device_id),c("weight")}catch(N){console.error("Failed to tare:",N)}finally{o(!1)}}else if(l==="weight"){const N=parseFloat(d);if(r===null||!N||N<=0)return;o(!0);try{await zi.setCalibrationFactor(t.device_id,N,r,m??void 0),c("idle")}catch(C){console.error("Failed to calibrate:",C)}finally{o(!1)}}};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"bg-zinc-800 rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-zinc-400",children:a("spoolbuddy.settings.currentWeight","Current weight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${n?"bg-green-500":"bg-amber-500 animate-pulse"}`}),i.jsx("span",{className:"text-lg font-mono text-zinc-200",children:e!==null?`${e.toFixed(1)} g`:"-- g"})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4 mt-3 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:a("spoolbuddy.settings.tareOffset","Tare offset")}),i.jsx("span",{className:"text-zinc-400 font-mono",children:t.tare_offset})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-zinc-500",children:a("spoolbuddy.settings.calFactor","Cal. factor")}),i.jsx("span",{className:"text-zinc-400 font-mono",children:t.calibration_factor.toFixed(2)})]})]})]}),l==="idle"?i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:b,disabled:f,className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]",children:f?"...":a("spoolbuddy.weight.tare","Tare")}),i.jsx("button",{onClick:g,className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]",children:a("spoolbuddy.weight.calibrate","Calibrate")})]}):i.jsxs("div",{className:"bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2",children:[i.jsx("div",{className:"text-sm font-medium text-zinc-200",children:l==="tare"?a("spoolbuddy.settings.calStep1","Step 1: Remove all items from the scale"):a("spoolbuddy.settings.calStep2","Step 2: Place known weight on scale")}),l==="weight"&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-zinc-400",children:a("spoolbuddy.settings.knownWeight","Known weight (g)")}),i.jsxs("div",{className:"flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100",children:[d||"0",i.jsx("span",{className:"text-zinc-500 ml-1",children:"g"})]})]}),i.jsx("div",{className:"grid grid-cols-4 gap-1",children:["7","8","9","backspace","4","5","6",".","1","2","3","0"].map(N=>i.jsx("button",{onClick:()=>v(N),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${N==="backspace"?"bg-zinc-700 text-zinc-300 hover:bg-zinc-600":"bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700"}`,children:N==="backspace"?"⌫":N},N))})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:()=>c("idle"),className:"flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]",children:a("common.cancel","Cancel")}),i.jsx("button",{onClick:_,disabled:s,className:"flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]",children:s?"...":l==="tare"?a("spoolbuddy.settings.setZero","Set Zero"):a("spoolbuddy.settings.calibrateNow","Calibrate")})]})]})]})}function Srt(){const{sbState:t}=fw(),{t:e}=jt(),n=Po(),{data:r=[]}=et({queryKey:["spoolbuddy-devices"],queryFn:()=>zi.getDevices(),refetchInterval:1e4}),a=t.deviceId?r.find(s=>s.device_id===t.deviceId)??r[0]:r[0];return i.jsxs("div",{className:"h-full flex flex-col p-4",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("button",{onClick:()=>n("/spoolbuddy/settings"),className:"p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors",children:i.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),i.jsx("h1",{className:"text-xl font-semibold text-zinc-100",children:e("spoolbuddy.settings.scaleCalibration","Scale Calibration")})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:a?i.jsx(wrt,{device:a,weight:t.weight,weightStable:t.weightStable,rawAdc:t.rawAdc}):i.jsx("div",{className:"flex items-center justify-center h-32",children:i.jsx("div",{className:"text-center text-zinc-500",children:i.jsx("p",{className:"text-sm",children:e("spoolbuddy.settings.noDevice","No SpoolBuddy device found")})})})})]})}const _rt=["PLA","PETG","ABS","ASA","TPU","PA","PC","PVA","HIPS"];function Nrt(){const{t}=jt(),{sbState:e}=fw(),[n,r]=w.useState("existing"),[a,s]=w.useState(null),[o,l]=w.useState(""),[c,d]=w.useState("idle"),[u,m]=w.useState(""),[p,f]=w.useState(!1),[y,v]=w.useState(!1),[b,g]=w.useState(null),{data:_=[],refetch:N}=et({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(!1),refetchInterval:1e4}),{data:C=[]}=et({queryKey:["spoolbuddy-devices"],queryFn:()=>zi.getDevices(),refetchInterval:5e3}),{data:k}=et({queryKey:["settings"],queryFn:fe.getSettings}),P=C[0],T=e.deviceOnline,j=go(k?.currency||"USD"),A=w.useMemo(()=>{let me;if(n==="existing")me=_.filter(W=>!W.tag_uid&&!W.archived_at);else if(n==="replace")me=_.filter(W=>(W.tag_uid||W.tray_uuid)&&!W.archived_at);else return[];if(o){const W=o.toLowerCase();me=me.filter(ae=>ae.material?.toLowerCase().includes(W)||ae.color_name?.toLowerCase().includes(W)||ae.brand?.toLowerCase().includes(W)||ae.subtype?.toLowerCase().includes(W))}return me},[_,n,o]),F=w.useCallback(me=>{const W=me.detail;(W.sak??W.data?.sak)===0&&(v(!0),g(W.tag_uid??W.data?.tag_uid??null))},[]),G=w.useCallback(me=>{const W=me.detail;v(!0),g(W.tag_uid??W.data?.tag_uid??null)},[]),z=w.useCallback(()=>{v(!1),g(null)},[]),J=w.useCallback(me=>{const W=me.detail;(W.spool_id===a?.id||W.data?.spool_id===a?.id)&&(d("success"),m(t("spoolbuddy.writeTag.writeSuccess","Tag written successfully!")),N(),setTimeout(()=>{d("idle"),s(null),m("")},5e3))},[a,t,N]),I=w.useCallback(me=>{const W=me.detail;(W.spool_id===a?.id||W.data?.spool_id===a?.id)&&(d("error"),m(W.message??W.data?.message??t("spoolbuddy.writeTag.writeFailed","Write failed")))},[a,t]);w.useEffect(()=>(window.addEventListener("spoolbuddy-unknown-tag",F),window.addEventListener("spoolbuddy-tag-matched",G),window.addEventListener("spoolbuddy-tag-removed",z),window.addEventListener("spoolbuddy-tag-written",J),window.addEventListener("spoolbuddy-tag-write-failed",I),()=>{window.removeEventListener("spoolbuddy-unknown-tag",F),window.removeEventListener("spoolbuddy-tag-matched",G),window.removeEventListener("spoolbuddy-tag-removed",z),window.removeEventListener("spoolbuddy-tag-written",J),window.removeEventListener("spoolbuddy-tag-write-failed",I)}),[F,G,z,J,I]),w.useEffect(()=>{s(null),d("idle"),m(""),l("")},[n]);const te=async()=>{if(!(!a||!P)){d("writing"),m(t("spoolbuddy.writeTag.waiting","Waiting for SpoolBuddy..."));try{await zi.writeTag(P.device_id,a.id)}catch{d("error"),m(t("spoolbuddy.writeTag.queueFailed","Failed to queue write command"))}}},se=async()=>{if(P){try{await zi.cancelWrite(P.device_id)}catch{}d("idle"),m("")}},Z=async()=>{if(!(!a||!JY(a))){f(!0),d("idle"),m("");try{await fe.linkTagToSpool(a.id,{tag_uid:"",tray_uuid:"",data_origin:"manual"}),await N(),s(null),d("success"),m(t("spoolbuddy.writeTag.untagSuccess","Tag removed from spool")),setTimeout(()=>{d("idle"),m("")},2500)}catch{d("error"),m(t("spoolbuddy.writeTag.untagFailed","Failed to remove tag from spool"))}finally{f(!1)}}},de=w.useCallback(me=>{s(me),d("idle"),m(""),N()},[N]),ue=a&&T&&c!=="writing"&&c!=="success";return i.jsxs("div",{className:"flex flex-col h-full",children:[i.jsx("div",{className:"flex border-b border-bambu-dark-tertiary shrink-0",children:[{key:"existing",label:t("spoolbuddy.writeTag.tabExisting","Existing Spool")},{key:"new",label:t("spoolbuddy.writeTag.tabNew","New Spool")},{key:"replace",label:t("spoolbuddy.writeTag.tabReplace","Replace Tag")}].map(me=>i.jsx("button",{onClick:()=>r(me.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${n===me.key?"text-bambu-green border-b-2 border-bambu-green bg-bambu-dark":"text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary"}`,children:me.label},me.key))}),i.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[i.jsx("div",{className:"flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary",children:n==="new"?i.jsx(Crt,{currencySymbol:j,onCreated:de,selectedSpool:a,t}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"p-3 shrink-0",children:i.jsx("input",{type:"text",value:o,onChange:me=>l(me.target.value),placeholder:t("spoolbuddy.writeTag.searchPlaceholder","Search by material, color, brand..."),className:"w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green"})}),i.jsx("div",{className:"flex-1 overflow-y-auto px-3 pb-3 space-y-2",children:A.length===0?i.jsx("div",{className:"text-center text-zinc-500 py-8 text-sm",children:n==="existing"?t("spoolbuddy.writeTag.noUntaggedSpools","No spools without tags"):t("spoolbuddy.writeTag.noTaggedSpools","No spools with tags")}):A.map(me=>i.jsx(krt,{spool:me,selected:a?.id===me.id,showTag:n==="replace",onClick:()=>{s(me),d("idle"),m("")}},me.id))})]})}),i.jsx("div",{className:"w-[340px] flex flex-col items-center justify-center p-6 shrink-0",children:i.jsx(Trt,{writeStatus:c,writeMessage:u,selectedSpool:a,tagOnReader:y,tagUid:b,deviceOnline:T,canWrite:!!ue,isReplace:n==="replace",canUntag:n==="replace"&&!!a&&JY(a),untagging:p,onWrite:te,onUntag:Z,onCancel:se,onRetry:()=>{d("idle"),m("")},t})})]})]})}function JY(t){return!!(t.tag_uid||t.tray_uuid)}function krt({spool:t,selected:e,showTag:n,onClick:r}){const a=t.rgba?`#${t.rgba.slice(0,6)}`:"#666",s=Math.max(0,t.label_weight-t.weight_used),o=t.label_weight>0?Math.round(s/t.label_weight*100):0;return i.jsxs("button",{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${e?"bg-bambu-green/15 border border-bambu-green/50":"bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent"}`,children:[i.jsx("div",{className:"w-8 h-8 rounded-full shrink-0 border border-white/10",style:{backgroundColor:a}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("span",{className:"text-sm font-medium text-white truncate",children:[t.brand?`${t.brand} `:"",t.material,t.subtype?` ${t.subtype}`:""]})}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-zinc-400",children:[t.color_name&&i.jsx("span",{children:t.color_name}),i.jsxs("span",{children:[s,"g / ",t.label_weight,"g (",o,"%)"]})]}),n&&t.tag_uid&&i.jsx("div",{className:"text-xs text-zinc-500 mt-0.5 font-mono",children:t.tag_uid})]}),e&&i.jsx("svg",{className:"w-5 h-5 text-bambu-green shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:i.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]})}function Crt({currencySymbol:t,onCreated:e,selectedSpool:n,t:r}){const[a,s]=w.useState("simple"),[o,l]=w.useState("filament"),[c,d]=w.useState(EL),[u,m]=w.useState({}),[p,f]=w.useState(!1),[y,v]=w.useState(1),[b,g]=w.useState(!1),[_,N]=w.useState(null),[C,k]=w.useState(!1),[P,T]=w.useState(!1),[j,A]=w.useState([]),[F,G]=w.useState([]),[z,J]=w.useState([]),[I,te]=w.useState([]),[se,Z]=w.useState(""),[de,ue]=w.useState([]),[me,W]=w.useState([]),[ae,ce]=w.useState(new Set),[ge,Ne]=w.useState(new Set);w.useEffect(()=>{ue(ule())},[]),w.useEffect(()=>{(async()=>{if(a==="full"){T(!0);try{const pe=await fe.getCloudStatus();if(k(pe.is_authenticated),pe.is_authenticated){const ie=await fe.getFilamentPresets();A(ie)}}catch{k(!1)}finally{T(!1)}fe.getSpoolCatalog().then(J).catch(()=>{}),fe.getColorCatalog().then(te).catch(()=>{}),fe.getLocalPresets().then(pe=>G(pe.filament)).catch(()=>{});try{const pe=await fe.getPrinters(),ie=await Promise.all(pe.map(R=>fe.getPrinterStatus(R.id).catch(()=>null))),L=[];for(let R=0;R({cali_idx:we.slot_id,filament_id:we.filament_id,setting_id:we.setting_id||"",name:we.name,k_value:parseFloat(we.k_value)||0,n_coef:parseFloat(we.n_coef)||0,extruder_id:we.extruder_id,nozzle_diameter:we.nozzle_diameter}))}catch{}L.push({printer:{...ne,connected:ve},calibrations:be})}W(L)}catch{}}})()},[a]),w.useEffect(()=>{me.length>0&&Ne(new Set(me.map(he=>String(he.printer.id))))},[me]);const H=w.useMemo(()=>cle(j,new Set,F),[j,F]),X=w.useMemo(()=>dle(c.slicer_filament,H),[c.slicer_filament,H]),D=w.useMemo(()=>{const he=lle(j,F),pe=I.map(ie=>ie.manufacturer?.trim()).filter(ie=>!!ie);return Array.from(new Set([...he,...pe])).sort((ie,L)=>ie.localeCompare(L))},[j,F,I]),M=w.useMemo(()=>{const he=I.map(pe=>pe.material?.trim()).filter(pe=>!!pe);return Array.from(new Set([...ale,...he])).sort((pe,ie)=>pe.localeCompare(ie))},[I]),U=w.useMemo(()=>{const he=[];for(const pe of I){const ie=pe.manufacturer?.trim(),L=pe.material?.trim();ie&&L&&he.push({brand:ie,material:L})}for(const pe of j){const ie=Zh(pe.name);ie.brand&&ie.material&&he.push({brand:ie.brand,material:ie.material})}for(const pe of F){const ie=Zh(pe.name),L=pe.filament_vendor?.trim()||ie.brand,R=ie.material;L&&R&&he.push({brand:L,material:R})}return he},[j,I,F]),K=w.useMemo(()=>{const he=new Map;for(const pe of U){const ie=pe.brand.toLowerCase(),L=pe.material.toLowerCase();he.has(ie)||he.set(ie,new Set),he.get(ie).add(L)}return he},[U]),B=w.useMemo(()=>{const he=new Map;for(const pe of U){const ie=pe.brand.toLowerCase(),L=pe.material.toLowerCase();he.has(L)||he.set(L,new Set),he.get(L).add(ie)}return he},[U]),re=w.useMemo(()=>{if(!c.material)return D;const he=c.material.toLowerCase(),pe=B.get(he);return!pe||pe.size===0?D:D.filter(ie=>pe.has(ie.toLowerCase()))},[D,c.material,B]),O=w.useMemo(()=>{if(!c.brand)return M;const he=c.brand.toLowerCase(),pe=K.get(he);return!pe||pe.size===0?M:M.filter(ie=>pe.has(ie.toLowerCase()))},[M,c.brand,K]),q=(he,pe)=>{d(ie=>({...ie,[he]:pe})),u[he]&&m(ie=>({...ie,[he]:void 0}))},Y=he=>{ue(pe=>mle(he,pe))},V=async he=>{if(ae.size===0){try{await fe.saveSpoolKProfiles(he,[])}catch{}return}const pe=[];for(const ie of ae){const[L,R,ne]=ie.split(":"),ye=parseInt(L),ve=parseInt(R),be=ne==="null"?0:parseInt(ne),Be=me.find(we=>we.printer.id===ye);if(Be){const we=Be.calibrations.find(Ae=>Ae.cali_idx===ve);we&&pe.push({printer_id:ye,extruder:be,nozzle_diameter:we.nozzle_diameter||"0.4",k_value:we.k_value,name:we.name||null,cali_idx:we.cali_idx,setting_id:we.setting_id||null})}}pe.length>0&&await fe.saveSpoolKProfiles(he,pe)},ee=async()=>{N(null);const he=ile(c,a==="simple"?!0:p);if(!he.isValid){m(he.errors),l("filament");return}const pe=X?.displayName||se||null,ie={material:c.material,subtype:c.subtype||null,brand:c.brand||null,color_name:c.color_name||null,rgba:c.rgba||null,label_weight:c.label_weight,core_weight:c.core_weight,core_weight_catalog_id:c.core_weight_catalog_id,weight_used:c.weight_used,slicer_filament:c.slicer_filament||null,slicer_filament_name:pe,nozzle_temp_min:null,nozzle_temp_max:null,note:c.note||null,cost_per_kg:c.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null};g(!0);try{if(y>1){const L=await fe.bulkCreateSpools(ie,y);for(const R of L)await V(R.id);L.length>0&&e(L[0])}else{const L=await fe.createSpool(ie);await V(L.id),e(L)}}catch{N(r("spoolbuddy.writeTag.createFailed","Failed to create spool"))}finally{g(!1)}},oe=`#${(c.rgba||"808080FF").slice(0,6)}`;return i.jsxs("div",{className:"p-3 space-y-3 overflow-y-auto h-full",children:[i.jsxs("div",{className:"flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-zinc-200",children:r("spoolbuddy.writeTag.viewMode","View")}),i.jsxs("div",{className:"flex rounded-lg overflow-hidden border border-bambu-dark-tertiary",children:[i.jsx("button",{type:"button",onClick:()=>s("simple"),className:`px-3 py-1.5 text-xs font-medium ${a==="simple"?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-zinc-400"}`,children:r("spoolbuddy.writeTag.simpleView","Simple")}),i.jsx("button",{type:"button",onClick:()=>s("full"),className:`px-3 py-1.5 text-xs font-medium ${a==="full"?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-zinc-400"}`,children:r("spoolbuddy.writeTag.fullView","Full")})]})]}),a==="simple"?n?i.jsxs("div",{className:"flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[i.jsx("div",{className:"w-12 h-12 rounded-full mb-4 border border-white/10",style:{backgroundColor:n.rgba?`#${n.rgba.slice(0,6)}`:"#666"}}),i.jsxs("p",{className:"text-white font-medium",children:[n.brand?`${n.brand} `:"",n.material]}),n.color_name&&i.jsx("p",{className:"text-zinc-400 text-sm",children:n.color_name}),i.jsxs("p",{className:"text-zinc-500 text-xs mt-1",children:[n.label_weight,"g"]}),i.jsx("p",{className:"text-bambu-green text-sm mt-4",children:r("spoolbuddy.writeTag.spoolCreated","Spool created! Ready to write.")})]}):i.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-zinc-400 mb-1",children:r("spoolbuddy.writeTag.material","Material")}),i.jsx("select",{value:c.material,onChange:he=>q("material",he.target.value),className:"w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green",children:_rt.map(he=>i.jsx("option",{value:he,children:he},he))})]}),i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("label",{className:"block text-xs text-zinc-400 mb-1",children:r("spoolbuddy.writeTag.colorName","Color Name")}),i.jsx("input",{type:"text",value:c.color_name,onChange:he=>q("color_name",he.target.value),placeholder:"Jade White",className:"w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-zinc-400 mb-1",children:r("spoolbuddy.writeTag.color","Color")}),i.jsx("input",{type:"color",value:oe,onChange:he=>q("rgba",he.target.value.replace("#","").toUpperCase()+"FF"),className:"w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-zinc-400 mb-1",children:r("spoolbuddy.writeTag.brand","Brand")}),i.jsx("input",{type:"text",value:c.brand,onChange:he=>q("brand",he.target.value),placeholder:"Polymaker",className:"w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-zinc-400 mb-1",children:r("spoolbuddy.writeTag.weight","Weight (g)")}),i.jsx("input",{type:"number",value:c.label_weight,onChange:he=>q("label_weight",parseInt(he.target.value)||0),min:0,max:1e4,className:"w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green"})]}),i.jsx("button",{onClick:ee,disabled:b||!c.material,className:"w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors",children:b?r("spoolbuddy.writeTag.creating","Creating..."):r("spoolbuddy.writeTag.createSpool","Create Spool")})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-zinc-200",children:r("inventory.quickAdd","Quick Add")}),i.jsx("button",{type:"button",onClick:()=>f(he=>!he),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${p?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),i.jsxs("div",{className:"flex border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsx("button",{onClick:()=>l("filament"),className:`flex-1 py-2.5 text-sm font-medium ${o==="filament"?"bg-bambu-green/15 text-bambu-green":"bg-bambu-dark-secondary text-zinc-400"}`,children:r("inventory.filamentInfoTab","Filament")}),!p&&i.jsx("button",{onClick:()=>l("pa-profile"),className:`flex-1 py-2.5 text-sm font-medium ${o==="pa-profile"?"bg-bambu-green/15 text-bambu-green":"bg-bambu-dark-secondary text-zinc-400"}`,children:r("inventory.paProfileTab","PA Profile")})]}),i.jsx("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3",children:o==="filament"?i.jsxs("div",{className:"space-y-4",children:[i.jsx(hle,{formData:c,updateField:q,cloudAuthenticated:C,loadingCloudPresets:P,presetInputValue:se,setPresetInputValue:Z,selectedPresetOption:X,filamentOptions:H,availableBrands:re,availableMaterials:O,quickAdd:p,quantity:y,onQuantityChange:v,errors:u}),i.jsx(ple,{formData:c,updateField:q,recentColors:de,onColorUsed:Y,catalogColors:I}),i.jsx(fle,{formData:c,updateField:q,spoolCatalog:z,currencySymbol:t})]}):i.jsx(gle,{formData:c,updateField:q,printersWithCalibrations:me,selectedProfiles:ae,setSelectedProfiles:ce,expandedPrinters:ge,setExpandedPrinters:Ne})})]}),_&&i.jsx("div",{className:"text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2",children:_}),a==="full"&&i.jsx("button",{onClick:ee,disabled:b,className:"w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors",children:b?r("spoolbuddy.writeTag.creating","Creating..."):r("spoolbuddy.writeTag.createSpool","Create Spool")}),a==="full"&&n&&i.jsxs("div",{className:"flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[i.jsx("div",{className:"w-12 h-12 rounded-full mb-4 border border-white/10",style:{backgroundColor:n.rgba?`#${n.rgba.slice(0,6)}`:"#666"}}),i.jsxs("p",{className:"text-white font-medium",children:[n.brand?`${n.brand} `:"",n.material]}),n.color_name&&i.jsx("p",{className:"text-zinc-400 text-sm",children:n.color_name}),i.jsxs("p",{className:"text-zinc-500 text-xs mt-1",children:[n.label_weight,"g"]}),i.jsx("p",{className:"text-bambu-green text-sm mt-4",children:r("spoolbuddy.writeTag.spoolCreated","Spool created! Ready to write.")})]})]})}function Trt({writeStatus:t,writeMessage:e,selectedSpool:n,tagOnReader:r,tagUid:a,deviceOnline:s,canWrite:o,isReplace:l,canUntag:c,untagging:d,onWrite:u,onUntag:m,onCancel:p,onRetry:f,t:y}){if(t==="success")return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[i.jsx("div",{className:"w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center",children:i.jsx("svg",{className:"w-8 h-8 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),i.jsx("p",{className:"text-green-400 font-medium",children:e}),n&&i.jsxs("p",{className:"text-zinc-400 text-sm",children:[n.brand?`${n.brand} `:"",n.material,n.color_name?` - ${n.color_name}`:""]})]});if(t==="error")return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[i.jsx("div",{className:"w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx("svg",{className:"w-8 h-8 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),i.jsx("p",{className:"text-red-400 font-medium",children:e}),i.jsx("button",{onClick:f,className:"px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors",children:y("spoolbuddy.writeTag.tryAgain","Try Again")})]});if(t==="writing")return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[i.jsxs("div",{className:"relative w-16 h-16",children:[i.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping"}),i.jsx("div",{className:"absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse"}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsx(jv,{className:"w-8 h-8 text-bambu-green"})})]}),i.jsx("p",{className:"text-bambu-green font-medium",children:y("spoolbuddy.writeTag.writing","Writing tag...")}),i.jsx("p",{className:"text-zinc-500 text-xs",children:e}),i.jsx("button",{onClick:p,className:"px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors",children:y("spoolbuddy.writeTag.cancel","Cancel")})]});if(!s)return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-3",children:[i.jsx(jv,{className:"w-12 h-12 text-zinc-600"}),i.jsx("p",{className:"text-zinc-500 text-sm",children:y("spoolbuddy.writeTag.deviceOffline","SpoolBuddy is offline")})]});if(!n)return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-3",children:[i.jsx(jv,{className:"w-12 h-12 text-zinc-600"}),i.jsx("p",{className:"text-zinc-400 text-sm",children:y("spoolbuddy.writeTag.selectSpool","Select a spool, then place a blank NTAG on the reader")})]});const v=n.rgba?`#${n.rgba.slice(0,6)}`:"#666";return i.jsxs("div",{className:"flex flex-col items-center text-center space-y-4 w-full",children:[i.jsx("div",{className:"relative w-16 h-16",children:r?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"absolute inset-0 rounded-full bg-bambu-green/10"}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsx(jv,{className:"w-8 h-8 text-bambu-green"})})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse"}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsx(jv,{className:"w-8 h-8 text-zinc-500"})})]})}),r?i.jsxs("div",{className:"space-y-1",children:[i.jsx("p",{className:"text-bambu-green text-sm font-medium",children:y("spoolbuddy.writeTag.tagReady","Tag detected — ready to write")}),a&&i.jsx("p",{className:"text-zinc-500 text-xs font-mono",children:a})]}):i.jsx("p",{className:"text-zinc-400 text-sm",children:y("spoolbuddy.writeTag.placeTag","Place an NTAG on the reader")}),i.jsxs("div",{className:"w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 rounded-full border border-white/10 shrink-0",style:{backgroundColor:v}}),i.jsxs("div",{className:"text-left min-w-0",children:[i.jsxs("p",{className:"text-white text-sm font-medium truncate",children:[n.brand?`${n.brand} `:"",n.material]}),n.color_name&&i.jsx("p",{className:"text-zinc-400 text-xs",children:n.color_name})]})]}),i.jsxs("div",{className:"text-xs text-zinc-500",children:[n.label_weight,"g"]})]}),l&&n.tag_uid&&i.jsx("p",{className:"text-yellow-500/80 text-xs",children:y("spoolbuddy.writeTag.replaceWarning","Old tag will be unlinked. New tag will replace it.")}),i.jsx("button",{onClick:u,disabled:!o,className:"w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm",children:l?y("spoolbuddy.writeTag.replaceTag","Replace Tag"):y("spoolbuddy.writeTag.writeTag","Write Tag")}),l&&c&&i.jsx("button",{onClick:m,disabled:d,className:"w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm",children:d?y("spoolbuddy.writeTag.untagging","Removing tag..."):y("spoolbuddy.writeTag.untagSpool","Untag Selected Spool")})]})}function jv({className:t}){return i.jsxs("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:[i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0"}),i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z"})]})}const Art=new xhe({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function eX({children:t}){return Nnt(),i.jsx(i.Fragment,{children:t})}function tX({children:t}){const{authEnabled:e,loading:n,user:r}=Ar();return n?i.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e&&!r?i.jsx(dx,{to:"/login",replace:!0}):i.jsx(i.Fragment,{children:t})}function c3({children:t}){const{authEnabled:e,loading:n,user:r,isAdmin:a}=Ar();return n?i.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e?r?a?i.jsx(i.Fragment,{children:t}):i.jsx(dx,{to:"/",replace:!0}):i.jsx(dx,{to:"/login",replace:!0}):i.jsx(i.Fragment,{children:t})}function Prt({children:t}){const{authEnabled:e,loading:n}=Ar();return n?i.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e?i.jsx(dx,{to:"/login",replace:!0}):i.jsx(i.Fragment,{children:t})}function Mrt(){return i.jsx(hxe,{children:i.jsx(wxe,{children:i.jsx(yhe,{client:Art,children:i.jsx(yxe,{children:i.jsx(Ime,{children:i.jsxs(hme,{children:[i.jsx(kr,{path:"/setup",element:i.jsx(Prt,{children:i.jsx(Snt,{})})}),i.jsx(kr,{path:"/login",element:i.jsx(wnt,{})}),i.jsx(kr,{path:"/camera/:printerId",element:i.jsx(qtt,{})}),i.jsx(kr,{path:"/overlay/:printerId",element:i.jsx(Ktt,{})}),i.jsxs(kr,{element:i.jsx(tX,{children:i.jsx(eX,{children:i.jsx(Int,{})})}),children:[i.jsx(kr,{path:"spoolbuddy",element:i.jsx(art,{})}),i.jsx(kr,{path:"spoolbuddy/ams",element:i.jsx(lrt,{})}),i.jsx(kr,{path:"spoolbuddy/write-tag",element:i.jsx(Nrt,{})}),i.jsx(kr,{path:"spoolbuddy/settings",element:i.jsx(vrt,{})}),i.jsx(kr,{path:"spoolbuddy/calibration",element:i.jsx(Srt,{})})]}),i.jsxs(kr,{element:i.jsx(tX,{children:i.jsx(eX,{children:i.jsx(Rxe,{})})}),children:[i.jsx(kr,{index:!0,element:i.jsx(RVe,{})}),i.jsx(kr,{path:"archives",element:i.jsx(TZe,{})}),i.jsx(kr,{path:"queue",element:i.jsx(met,{})}),i.jsx(kr,{path:"stats",element:i.jsx(Eet,{})}),i.jsx(kr,{path:"profiles",element:i.jsx(wtt,{})}),i.jsx(kr,{path:"maintenance",element:i.jsx(Ctt,{})}),i.jsx(kr,{path:"projects",element:i.jsx(Att,{})}),i.jsx(kr,{path:"projects/:id",element:i.jsx(Dtt,{})}),i.jsx(kr,{path:"inventory",element:i.jsx(hnt,{})}),i.jsx(kr,{path:"files",element:i.jsx(Utt,{})}),i.jsx(kr,{path:"settings",element:i.jsx(c3,{children:i.jsx(ott,{})})}),i.jsx(kr,{path:"groups/new",element:i.jsx(c3,{children:i.jsx(HY,{})})}),i.jsx(kr,{path:"groups/:id/edit",element:i.jsx(c3,{children:i.jsx(HY,{})})}),i.jsx(kr,{path:"users",element:i.jsx(dx,{to:"/settings?tab=users",replace:!0})}),i.jsx(kr,{path:"groups",element:i.jsx(dx,{to:"/settings?tab=users",replace:!0})}),i.jsx(kr,{path:"system",element:i.jsx(vnt,{})}),i.jsx(kr,{path:"notifications",element:i.jsx(_nt,{})}),i.jsx(kr,{path:"external/:id",element:i.jsx(Ytt,{})})]})]})})})})})})}lde.createRoot(document.getElementById("root")).render(i.jsx(w.StrictMode,{children:i.jsx(Mrt,{})})); diff --git a/static/index.html b/static/index.html index 92b3f514d..554baa53c 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +