| 1 |
- import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,v as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useQuery-CCy0EwsM.js";import{Hn as o,Vn as s}from"./index-BoVbGTav.js";var c=e(n(),1),l=t();function u({device:e,weight:t,weightStable:n,rawAdc:a}){let{t:o}=i(),[s,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(`idle`),[p,m]=(0,c.useState)(`500`),[h,g]=(0,c.useState)(null),[_,v]=(0,c.useState)(!1),y=e=>{e===`backspace`?m(e=>e.slice(0,-1)||``):e===`.`&&!p.includes(`.`)?m(e=>e+`.`):e>=`0`&&e<=`9`&&m(t=>t===`0`?e:t+e)};return(0,l.jsxs)(`div`,{className:`space-y-4`,children:[(0,l.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,l.jsx)(`span`,{className:`text-sm text-zinc-400`,children:o(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,l.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,l.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),d===`idle`?(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:async()=>{v(!0);try{await r.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{v(!1)}},disabled:_,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:_?`...`:o(`spoolbuddy.weight.tare`,`Tare`)}),(0,l.jsx)(`button`,{onClick:()=>{f(`tare`)},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:o(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,l.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:d===`tare`?o(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):o(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),d===`weight`&&(0,l.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-xs text-zinc-400`,children:o(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,l.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:[p||`0`,(0,l.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,l.jsx)(`button`,{onClick:()=>y(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`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:e===`backspace`?`⌫`:e},e))})]}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:()=>f(`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:o(`common.cancel`,`Cancel`)}),(0,l.jsx)(`button`,{onClick:async()=>{if(d===`tare`){u(!0);try{g(a),await r.tare(e.device_id),f(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{u(!1)}}else if(d===`weight`){let t=parseFloat(p);if(a===null||!t||t<=0)return;u(!0);try{await r.setCalibrationFactor(e.device_id,t,a,h??void 0),f(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{u(!1)}}},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?`...`:d===`tare`?o(`spoolbuddy.settings.setZero`,`Set Zero`):o(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function d(){let{sbState:e}=o(),{t}=i(),n=s(),{data:c=[]}=a({queryKey:[`spoolbuddy-devices`],queryFn:()=>r.getDevices(),refetchInterval:1e4}),d=e.deviceId?c.find(t=>t.device_id===e.deviceId)??c[0]:c[0];return(0,l.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,l.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:(0,l.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,l.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,l.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,l.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d?(0,l.jsx)(u,{device:d,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,l.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,l.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,l.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}export{d as SpoolBuddyCalibrationPage};
|