import { Text, Tooltip } from '@mantine/core'
import { MonitorState, MonitorTarget } from '@/uptime.types'
import { IconAlertCircle, IconCircleCheck } from '@tabler/icons-react'
import DetailChart from './DetailChart'
import DetailBar from './DetailBar'
import { getColor } from '@/util/color'
export default function MonitorDetail({
monitor,
state,
}: {
monitor: MonitorTarget
state: MonitorState
}) {
if (!state.latency[monitor.id])
return (
<>
{monitor.name}
No data available, please make sure you have deployed your workers with latest config and
check your worker status!
>
)
const statusIcon =
state.incident[monitor.id].slice(-1)[0].end === undefined ? (
) : (
)
let totalTime = Date.now() / 1000 - state.incident[monitor.id][0].start[0]
let downTime = 0
for (let incident of state.incident[monitor.id]) {
downTime += (incident.end ?? Date.now() / 1000) - incident.start[0]
}
const uptimePercent = (((totalTime - downTime) / totalTime) * 100).toPrecision(4)
// Conditionally render monitor name with or without hyperlink based on monitor.url presence
const monitorNameElement = (
{monitor.statusPageLink ? (
{statusIcon} {monitor.name}
) : (
<>
{statusIcon} {monitor.name}
>
)}
)
return (
<>
{monitor.tooltip ? (
{monitorNameElement}
) : (
monitorNameElement
)}
Overall: {uptimePercent}%
{!monitor.hideLatencyChart && }
>
)
}