93 lines
3.4 KiB
Vue
93 lines
3.4 KiB
Vue
<script setup lang="ts">
|
|
import { LIVE_LABELS, liveAge, scenarioLabel } from '#shared/live'
|
|
import type { LiveConnection } from '#shared/live'
|
|
import MiniBar from '~/components/use-cases/MiniBar.vue'
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
status: LiveConnection
|
|
scenarioId: string
|
|
sensorCount: number
|
|
cadenceMin: number | null
|
|
lastEventAt: string
|
|
}>(),
|
|
{ cadenceMin: null, lastEventAt: '' },
|
|
)
|
|
|
|
const now = ref(Date.now())
|
|
let timer: ReturnType<typeof setInterval> | undefined
|
|
|
|
onMounted(() => {
|
|
now.value = Date.now()
|
|
timer = setInterval(() => {
|
|
now.value = Date.now()
|
|
}, 1000)
|
|
})
|
|
onBeforeUnmount(() => {
|
|
if (timer) clearInterval(timer)
|
|
})
|
|
|
|
const age = computed(() => (props.lastEventAt ? liveAge(props.lastEventAt, now.value) : 'SSR payload'))
|
|
const isLive = computed(() => props.status === 'live')
|
|
const statusLabel = computed(() =>
|
|
isLive.value ? 'SCENARIO STREAM: LIVE' : `SCENARIO STREAM: ${LIVE_LABELS[props.status].toUpperCase()}`,
|
|
)
|
|
const coveragePct = computed(() => (props.sensorCount > 0 ? Math.min(100, (props.sensorCount / 8) * 100) : 0))
|
|
</script>
|
|
|
|
<template>
|
|
<section
|
|
aria-label="Live telemetry"
|
|
class="relative flex w-full flex-col items-start justify-between gap-4 overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-3.5 shadow-sm md:flex-row md:items-center"
|
|
>
|
|
<div class="absolute inset-y-0 left-0 w-1" :class="isLive ? 'bg-[#00C3CD]' : 'bg-[#475569]'" aria-hidden="true" />
|
|
<div class="flex flex-wrap items-center gap-4 pl-2">
|
|
<div
|
|
class="flex items-center gap-2 rounded border px-2.5 py-1"
|
|
:class="
|
|
isLive
|
|
? 'border-[#00C3CD]/30 bg-[#00C3CD]/15'
|
|
: 'border-white/10 bg-white/[0.06]'
|
|
"
|
|
>
|
|
<span
|
|
class="h-2 w-2 rounded-full"
|
|
:class="isLive ? 'animate-pulse bg-[#00C3CD]' : 'bg-[#94A3B8]'"
|
|
aria-hidden="true"
|
|
/>
|
|
<span
|
|
class="text-[11px] font-bold tracking-wider"
|
|
:class="isLive ? 'text-[#00C3CD]' : 'text-[#94A3B8]'"
|
|
>
|
|
{{ statusLabel }}
|
|
</span>
|
|
</div>
|
|
<span class="flex items-center gap-1.5 text-xs text-white md:text-sm">
|
|
<span class="text-[#94A3B8]">Sensor nodes:</span>
|
|
{{ sensorCount }} counted
|
|
</span>
|
|
<span class="hidden text-[#64748B] sm:inline" aria-hidden="true">•</span>
|
|
<span class="hidden items-center gap-1.5 text-xs text-[#94A3B8] sm:flex md:text-sm">
|
|
Cadence:
|
|
<span class="font-mono text-white">{{ cadenceMin ? `${cadenceMin} min` : '—' }}</span>
|
|
</span>
|
|
<span class="hidden text-[#64748B] lg:inline" aria-hidden="true">•</span>
|
|
<span class="hidden text-xs text-[#94A3B8] lg:inline md:text-sm">
|
|
Scenario:
|
|
<span class="font-mono text-[#00C3CD]">{{ scenarioLabel(scenarioId) }}</span>
|
|
</span>
|
|
</div>
|
|
|
|
<div class="flex w-full items-center justify-between gap-4 pl-2 md:w-auto md:justify-end md:pl-0">
|
|
<div class="flex w-36 flex-col gap-1">
|
|
<div class="flex items-center justify-between text-[11px] text-[#94A3B8]">
|
|
<span>Sensor coverage</span>
|
|
<span class="font-mono font-semibold text-white">{{ sensorCount }}/8</span>
|
|
</div>
|
|
<MiniBar :value="coveragePct" label="Sensor coverage" />
|
|
</div>
|
|
<span class="shrink-0 text-[11px] font-medium text-[#94A3B8]">Updated {{ age }}</span>
|
|
</div>
|
|
</section>
|
|
</template>
|