import type { NoiseThreshold } from '@seamapi/types/connect' import { ZonedTime } from 'zoned-time' import { formatTime, formatTimeZone } from 'lib/dates.js' import { ArrowRightIcon } from 'lib/icons/ArrowRight.js' import type { NoiseSensorDevice } from 'lib/seam/noise-sensors/noise-sensor-device.js' import { useNoiseThresholds } from 'lib/seam/noise-sensors/use-noise-thresholds.js' import { DetailRow } from 'lib/ui/layout/DetailRow.js' import { DetailSection } from 'lib/ui/layout/DetailSection.js' import { DetailSectionGroup } from 'lib/ui/layout/DetailSectionGroup.js' import { LoadingToast } from 'lib/ui/LoadingToast/LoadingToast.js' interface NoiseThresholdsListProps { device: NoiseSensorDevice } export function NoiseThresholdsList({ device, }: NoiseThresholdsListProps): JSX.Element { const { noiseThresholds, isInitialLoading } = useNoiseThresholds({ device_id: device.device_id, }) return (
{t.minutTooltipFirst} {t.minutTooltipSecond}
) : ( t.tooltip ) } >

{getTimeZoneCaption(device, noiseThresholds)}

) } function Content({ noiseThresholds, }: { noiseThresholds: NoiseThreshold[] | undefined }): JSX.Element | JSX.Element[] { if (noiseThresholds == null || noiseThresholds.length === 0) { return ( {t.none}} /> ) } return noiseThresholds?.map((noiseThreshold) => ( {noiseThreshold.name !== '' && ( {noiseThreshold.name} )}
{formatTime(noiseThreshold.starts_daily_at)} {formatTime(noiseThreshold.ends_daily_at)}
} >

{noiseThreshold.noise_threshold_decibels} {t.decibel}

)) } const getTimeZoneCaption = ( device: NoiseSensorDevice, thresholds: NoiseThreshold[] | undefined ): string | null => { if (device.location?.timezone != null) { return `${t.allTimesIn} ${formatTimeZone(device.location.timezone)}` } const firstThreshold = thresholds?.[0] if (firstThreshold != null) { const zonedTime = ZonedTime.from(firstThreshold.starts_daily_at) return `${t.allTimesIn} ${formatTimeZone(zonedTime.timeZone)}` } return null } const t = { noiseThresholds: 'Noise thresholds', tooltip: 'A noise threshold is the highest noise level (in dB) you want to allow for a given time range in the day.', minutTooltipFirst: 'A noise threshold is the highest noise level (in dB) you want to allow.', minutTooltipSecond: 'Quiet hours is a separate threshold that takes effect only for a specified time range.', none: 'None', loading: 'Loading...', decibel: 'dB', allTimesIn: 'All times in', }