import { Button, Descriptions, Modal } from "antd";
import { getLabelName } from "zy-react-library/utils";
import { SENSOR_ATTR_OPTIONS } from "~/enumerate/constant";

function ViewModal(props) {
  const record = props.record || {};
  const isNumberAttr = record.sensorAttr === "NUMBER";
  const items = [
    { label: "传感器类型", children: record.typeName || "-" },
    {
      label: "传感器属性",
      children: getLabelName({ status: record.sensorAttr, list: SENSOR_ATTR_OPTIONS }) || record.sensorAttr || "-",
    },
  ];

  if (isNumberAttr) {
    items.push(
      { label: "计量单位", children: record.unitName || "-" },
      { label: "量程上限默认值", children: record.rangeMax || "-" },
      { label: "量程下限默认值", children: record.rangeMin || "-" },
      { label: "高高报警阈值默认值", children: record.thresholdHighHigh || "-" },
      { label: "高报警阈值默认值", children: record.thresholdHigh || "-" },
      { label: "低低报警阈值默认值", children: record.thresholdLowLow || "-" },
      { label: "低报警阈值默认值", children: record.thresholdLow || "-" },
    );
  }

  return (
    <Modal
      destroyOnClose
      title="查看"
      open={props.open}
      cancelText="关闭"
      width={640}
      onCancel={props.onCancel}
      maskClosable={false}
      footer={(
        <div>
          <Button onClick={props.onCancel}>关闭</Button>
        </div>
      )}
    >
      <Descriptions
        bordered
        column={1}
        labelStyle={{ width: 200 }}
        items={items}
      />
    </Modal>
  );
}

export default ViewModal;
