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

function PositionModal(props) {
  const record = props.record || {};
  const hasPosition = record.positioningFlag === 1 && record.installPosition;

  return (
    <Modal
      destroyOnClose
      title="定位"
      open={props.open}
      cancelText="关闭"
      width={720}
      onCancel={props.onCancel}
      maskClosable={false}
      footer={(
        <div>
          <Button onClick={props.onCancel}>关闭</Button>
        </div>
      )}
    >
      {!hasPosition && (
        <Alert
          showIcon
          type="warning"
          message="当前传感器未配置有效定位信息"
          style={{ marginBottom: 16 }}
        />
      )}
      <Descriptions
        bordered
        column={2}
        labelStyle={{ width: 180 }}
        items={[
          { label: "传感器编码", children: record.sensorCode || "-", span: 2 },
          { label: "传感器名称", children: record.sensorName || "-", span: 2 },
          {
            label: "是否定位",
            children: getLabelName({ status: record.positioningFlag, list: YES_NO_OPTIONS }) || record.positioningFlag || "-",
            span: 2,
          },
          { label: "安装位置", children: record.installPosition || "-", span: 2 },
        ]}
      />
      <div style={{ marginTop: 16 }}>
        <StaticMapViewer longitude={record.longitude} latitude={record.latitude} />
      </div>
    </Modal>
  );
}

export default PositionModal;
