import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Descriptions } from "antd";
import { useEffect, useState } from "react";
import { getLabelName, isEmptyToWhether } from "zy-react-library/utils";
import { NS_BI_MARK_INFO } from "~/enumerate/namespace";

const SENSOR_ATTR_OPTIONS = [
  { bianma: "NUMBER", name: "数值类" },
  { bianma: "SWITCH", name: "开关类" },
];

const SENSOR_STATUS_OPTIONS = [
  { bianma: "NORMAL", name: "正常" },
  { bianma: "FAULT", name: "故障" },
  { bianma: "OFFLINE", name: "离线" },
  { bianma: "deactivate", name: "停用" },
];

const AlarmEquipment = (props) => {
  const [info, setInfo] = useState({});

  const getData = async () => {
    const { data } = await props.sensorDeviceInfo({ id: props.id });

    setInfo(data);
  };

  useEffect(() => {
    getData();
  }, []);

  return (
    <div>
      <Descriptions
        bordered
        column={1}
        items={[
          { label: "传感器编码", children: info.sensorCode },
          { label: "传感器名称", children: info.sensorName },
          { label: "传感器类型", children: info.sensorTypeName },
          { label: "传感器属性", children: getLabelName({ status: info.sensorAttr, list: SENSOR_ATTR_OPTIONS }) },
          { label: "传感器状态", children: getLabelName({ status: info.sensorStatus, list: SENSOR_STATUS_OPTIONS }) },
          { label: "安装位置", children: info.installPosition },
          { label: "出厂日期", children: info.factoryDate },
          { label: "是否阈值设定", children: isEmptyToWhether(info.thresholdFlag) },
        ]}
      />
    </div>
  );
};

export default Connect([NS_BI_MARK_INFO], true)(AlarmEquipment);
