import{Ct as e,g as t,j as n,k as r,l as i,o as a,r as o,s,u as c,xt as l}from"./runtime-core.esm-bundler-C5QBTNWE.js";import{t as u}from"./system-DbBvxitf.js";import{t as d}from"./index-DTUpsCzx.js";var f={class:`space-y-4`},p={class:`glass-card rounded-[15px] p-4 sm:p-6`},m={class:`mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4`},h={class:`text-xs uppercase tracking-wide text-content-muted`},g={class:`mt-2 text-lg font-semibold text-content-heading dark:text-white`},_={key:0,class:`glass-card rounded-[15px] p-5 text-content-muted`},v={class:`flex flex-wrap items-center justify-between gap-3`},y={class:`text-lg font-semibold text-content-heading dark:text-white`},b={class:`text-sm text-content-muted`},x={class:`mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2`},S={class:`text-sm`},C={class:`ml-2 text-content-heading dark:text-white`},w={key:0,class:`text-sm`},T={class:`ml-2 text-red-600 dark:text-red-300`},E={class:`mt-4 overflow-x-auto rounded-[12px] border border-stroke-subtle dark:border-white/10`},D={class:`min-w-full text-sm`},O={class:`px-3 py-2 font-medium text-content-heading dark:text-white`},k={class:`px-3 py-2 text-content-muted break-all`},A={key:0},j={key:1,class:`glass-card rounded-[15px] p-5 text-content-muted`},M=t({name:`SensorsView`,__name:`Sensors`,setup(t){let M=u(),N=a(()=>M.stats?.sensors??null),P=a(()=>N.value?.readings??[]),F=a(()=>{let e=N.value;return e?[{label:`Enabled`,value:e.enabled?`Yes`:`No`},{label:`Running`,value:e.running?`Yes`:`No`},{label:`Configured / Loaded`,value:`${e.configured??0} / ${e.loaded??0}`},{label:`Poll Interval`,value:typeof e.poll_interval_seconds==`number`?`${e.poll_interval_seconds.toFixed(1)}s`:`n/a`}]:[{label:`Enabled`,value:`n/a`},{label:`Running`,value:`n/a`},{label:`Configured`,value:`n/a`},{label:`Poll Interval`,value:`n/a`}]}),I=e=>{if(e==null)return`n/a`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return Number.isFinite(e)?String(e):`n/a`;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}},L=e=>{if(!e)return`n/a`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},R=async()=>{await M.fetchStats()};return d(async()=>{await M.fetchStats()},{intervalMs:1e4,immediate:!0}),(t,a)=>(r(),c(`div`,f,[s(`div`,p,[s(`div`,{class:`flex items-start justify-between gap-4`},[a[0]||=s(`div`,null,[s(`h1`,{class:`text-xl sm:text-2xl font-semibold text-content-heading dark:text-white`},`Sensors`),s(`p`,{class:`mt-1 text-sm text-content-muted`},` Live sensor summary from the existing stats API. `)],-1),s(`button`,{class:`rounded-[10px] border border-stroke-subtle dark:border-white/10 px-3 py-2 text-sm hover:bg-black/5 dark:hover:bg-white/5`,onClick:R},` Refresh `)]),s(`div`,m,[(r(!0),c(o,null,n(F.value,t=>(r(),c(`div`,{key:t.label,class:`rounded-[12px] border border-stroke-subtle dark:border-white/10 p-3`},[s(`p`,h,e(t.label),1),s(`p`,g,e(t.value),1)]))),128))])]),N.value?i(``,!0):(r(),c(`div`,_,` Sensor data is not available yet. Ensure the repeater has started and stats are loading. `)),(r(!0),c(o,null,n(P.value,(t,u)=>(r(),c(`div`,{key:`${t.name||`sensor`}-${u}`,class:`glass-card rounded-[15px] p-4 sm:p-5`},[s(`div`,v,[s(`div`,null,[s(`h2`,y,e(t.name||`Sensor ${u+1}`),1),s(`p`,b,`Type: `+e(t.type||`unknown`),1)]),s(`span`,{class:l([`rounded-full px-3 py-1 text-xs font-semibold`,t.ok?`bg-green-100 text-green-700 dark:bg-green-500/20 dark:text-green-300`:`bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-300`])},e(t.ok?`OK`:`Error`),3)]),s(`div`,x,[s(`div`,S,[a[1]||=s(`span`,{class:`text-content-muted`},`Timestamp:`,-1),s(`span`,C,e(L(t.timestamp)),1)]),t.error?(r(),c(`div`,w,[a[2]||=s(`span`,{class:`text-content-muted`},`Error:`,-1),s(`span`,T,e(t.error),1)])):i(``,!0)]),s(`div`,E,[s(`table`,D,[a[4]||=s(`thead`,{class:`bg-black/5 dark:bg-white/5`},[s(`tr`,null,[s(`th`,{class:`px-3 py-2 text-left text-content-muted`},`Field`),s(`th`,{class:`px-3 py-2 text-left text-content-muted`},`Value`)])],-1),s(`tbody`,null,[(r(!0),c(o,null,n(t.data||{},(t,n)=>(r(),c(`tr`,{key:String(n),class:`border-t border-stroke-subtle dark:border-white/10`},[s(`td`,O,e(n),1),s(`td`,k,e(I(t)),1)]))),128)),!t.data||Object.keys(t.data).length===0?(r(),c(`tr`,A,[...a[3]||=[s(`td`,{class:`px-3 py-3 text-content-muted`,colspan:`2`},`No fields in payload`,-1)]])):i(``,!0)])])])]))),128)),N.value&&P.value.length===0?(r(),c(`div`,j,` Sensors are configured but no readings are available yet. `)):i(``,!0)]))}});export{M as default};