export function renderAlarmCurrentValue(record) {
  if (!record || record.currentValue == null || record.currentValue === "") {
    return "-";
  }

  if (record.sensorAttr !== "NUMBER") {
    return Number(record.currentValue) === 1 ? "开" : "关";
  }

  const currentValue = Number(record.currentValue);
  const thresholdHighHigh = Number(record.thresholdHighHigh);
  const thresholdHigh = Number(record.thresholdHigh);
  const thresholdLowLow = Number(record.thresholdLowLow);
  const thresholdLow = Number(record.thresholdLow);

  let suffix = "";
  let color = "";

  if (
    (Number.isFinite(thresholdHighHigh) && currentValue > thresholdHighHigh)
    || (Number.isFinite(thresholdHigh) && currentValue > thresholdHigh)
  ) {
    suffix = " ↑";
    color = "red";
  }
  else if (
    (Number.isFinite(thresholdLowLow) && currentValue < thresholdLowLow)
    || (Number.isFinite(thresholdLow) && currentValue < thresholdLow)
  ) {
    suffix = " ↓";
    color = "red";
  }

  const unit = record.unitName ? ` ${record.unitName}` : "";
  const content = `${record.currentValue}${unit}${suffix}`;
  return color ? <span style={{ color }}>{content}</span> : content;
}
