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 FireControlRoom = (props) => {
  const { getDictionary } = useDictionary();
  const { getFile } = useGetFile();

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

  const getData = async () => {
    const { data } = await props.fireControlRoomInfo({ 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.roomId,
    });
    setInfo({
      ...data,
      roomImages: files,
      roomStatusName: getLabelName({
        list: dictionaryData,
        status: data.roomStatus,
        idKey: "dictValue",
        nameKey: "dictLabel",
      }),
    });
  };

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

  return (
    <div>
      <Divider titlePlacement="start">基本信息</Divider>
      <Descriptions
        bordered
        column={1}
        items={[
          { label: "消防控制室名称", children: info.roomName },
          { label: "消防控制室状态", children: info.roomStatusName },
          { 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: "deviceName" },
          { title: "设备型号", dataIndex: "deviceModel" },
          { title: "设备数量", dataIndex: "deviceQty" },
          { title: "设备位置", dataIndex: "deviceLocation" },
        ]}
        dataSource={info.devices || []}
        pagination={false}
        options={false}
        disabledResizer
      />
      <Divider titlePlacement="start">人员信息</Divider>
      <Table
        columns={[
          { title: "人员姓名", dataIndex: "personName" },
          { title: "人员手机号", dataIndex: "personPhone" },
          { title: "人员值班情况", dataIndex: "dutyDesc" },
        ]}
        dataSource={info.persons || []}
        pagination={false}
        options={false}
        disabledResizer
      />
    </div>
  );
};

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