import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import classNames from 'classnames';
import { NoiseLevelsIcon } from '../../../lib/icons/NoiseLevels.js';
import { NoiseLevelsRedIcon } from '../../../lib/icons/NoiseLevelsRed.js';
export function NoiseLevelStatus({ device, }) {
    const isActivated = (device?.properties?.currently_triggering_noise_threshold_ids ?? [])
        ?.length > 0;
    return (_jsxs(_Fragment, { children: [_jsxs("span", { className: 'seam-label', children: [t.noiseLevel, ":"] }), _jsxs("div", { className: 'seam-device-status', children: [isActivated ? _jsx(NoiseLevelsRedIcon, {}) : _jsx(NoiseLevelsIcon, {}), _jsxs("span", { className: classNames('seam-text', isActivated && 'seam-text-danger'), children: [getNoiseLevel(device), isActivated && ` (${t.noisy})`] })] })] }));
}
function toNoiseString(value) {
    if (typeof value === 'string' || typeof value === 'number') {
        return `${Number(value).toFixed(0)} ${t.decibel}`;
    }
    return t.unknown;
}
function getNoiseLevel(device) {
    const isMinut = device.device_type === 'minut_sensor';
    const isNoiseAware = device.device_type === 'noiseaware_activity_zone';
    if (isMinut) {
        return toNoiseString(device?.properties?.minut_metadata?.latest_sensor_values?.sound?.value);
    }
    if (isNoiseAware) {
        if (device?.properties?.noiseaware_metadata?.noise_level_nrs === -1) {
            return t.noiseAwareDefault;
        }
        return toNoiseString(device?.properties?.noiseaware_metadata?.noise_level_decibel);
    }
    return toNoiseString(undefined);
}
const t = {
    noiseLevel: 'Noise level',
    unknown: 'Unknown',
    decibel: 'dB',
    noiseAwareDefault: '0-40 dB',
    noisy: 'noisy',
};
//# sourceMappingURL=NoiseLevelStatus.js.map