import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Descriptions, Divider } from "antd";
import { useEffect, useState } from "react";
import PreviewImg from "zy-react-library/components/PreviewImg";
import Table from "zy-react-library/components/Table";
import { UPLOAD_FILE_TYPE_ENUM } from "zy-react-library/enum/uploadFile/gwj";
import useDictionary from "zy-react-library/hooks/useDictionary";
import useGetFile from "zy-react-library/hooks/useGetFile";
import { getLabelName } from "zy-react-library/utils";
import { NS_BI_MARK_INFO } from "~/enumerate/namespace";

const FirePumpRoom = (props) => {
  const { getDictionary } = useDictionary();
  const { getFile } = useGetFile();

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

  const getData = async () => {
    const { data } = await props.firePumpRoomInfo({ id: props.id });
    const dictionaryData = await getDictionary({ dictValue: "fire_resource_contro_root_type" });
    const files = await getFile({
      eqType: UPLOAD_FILE_TYPE_ENUM[302],
      eqForeignKey: data.pumpRoomId,
    });
    setInfo({
      ...data,
      roomImages: files,
      pumpStatusName: getLabelName({
        list: dictionaryData,
        status: data.pumpRoomStatus,
        idKey: "dictValue",
        nameKey: "dictLabel",
      }),
    });
  };

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

  return (
    <div>
      <Divider titlePlacement="start">基本信息</Divider>
      <Descriptions
        bordered
        column={1}
        items={[
          { label: "消防泵房名称", children: info.pumpRoomName },
          { label: "消防泵房状态", children: info.pumpStatusName },
          { label: "负责人", children: info.principalName },
          { label: "负责人手机号", children: info.principalPhone },
          { label: "经度", children: info.lng },
          { label: "纬度", children: info.lat },
          {
            label: "消防泵房图片",
            children: info.roomImages && info.roomImages.length > 0 && <PreviewImg files={info.roomImages} />,
          },
        ]}
      />
      <Divider titlePlacement="start">设备信息</Divider>
      <Table
        columns={[
          { title: "设备编号", dataIndex: "deviceCode" },
          { title: "设备名称", dataIndex: "deviceName" },
          { title: "设备分类", dataIndex: "deviceCategory" },
          { title: "负责单位", dataIndex: "chargeUnit" },
          { title: "具体位置", dataIndex: "deviceLocation" },
          { title: "设备参数和规格", dataIndex: "paramsSpec" },
        ]}
        dataSource={info.devices || []}
        pagination={false}
        options={false}
        disabledResizer
      />
    </div>
  );
};

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