import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import { VmInfoCollection, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { deviceServce } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Sbzj = function Sbzj(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    id = _ref.id,
    title = _ref.title;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var prefix = "".concat(classPrefix, "-sbzj");
  var data = deviceServce.useGetList({
    throwPointId: id
  });
  // const data = [
  //   { name: 'AI BOX', img: 'aibox' },
  //   { name: '安卓屏', img: 'android' },
  //   { name: '屋外摄像头', img: 'sbzj_video' },
  //   { name: '屋内摄像头', img: 'sbzj_video' },
  //   { name: '屋顶摄像头', img: 'sbzj_video' },
  //   { name: '摄像头', img: 'sbzj_video' },
  // ];
  var imgs = {
    AI_BOX: 'aibox',
    ANDROID_SCREEN: 'android',
    SHUTTER_DOOR: 'jlm',
    LIGHT: 'deng',
    CAMERA: 'sbzj_video'
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "".concat(prefix),
    children: [/*#__PURE__*/_jsx(VmWrapper, {
      title: "\u8BBE\u5907\u603B\u89C8",
      style: {
        marginBottom: 16
      },
      children: /*#__PURE__*/_jsxs("div", {
        className: "".concat(prefix, "-overview"),
        children: [/*#__PURE__*/_jsxs("div", {
          className: "".concat(prefix, "-overview-top"),
          children: [/*#__PURE__*/_jsx("img", {
            src: require("../../imgs/sbzj_tfd".concat(isDark ? '' : '_light', ".png"))
          }), /*#__PURE__*/_jsx("div", {
            children: title
          }), /*#__PURE__*/_jsx("div", {
            className: "".concat(prefix, "-overview-top-dashed")
          })]
        }), /*#__PURE__*/_jsx("div", {
          className: "".concat(prefix, "-overview-dashedBox")
        }), /*#__PURE__*/_jsx("div", {
          className: "".concat(prefix, "-overview-devices"),
          children: data === null || data === void 0 ? void 0 : data.map(function (ele, index) {
            var img = imgs[ele.deviceType] || 'sbzj_video';
            return /*#__PURE__*/_jsxs("div", {
              className: "".concat(prefix, "-overview-devices-item"),
              children: [/*#__PURE__*/_jsx("img", {
                src: require("../../imgs/".concat(img).concat(isDark ? '' : '_light', ".png"))
              }), /*#__PURE__*/_jsx("div", {
                className: "".concat(prefix, "-overview-devices-item-name"),
                children: ele.name
              }), index !== 0 && index !== data.length - 1 && /*#__PURE__*/_jsx("div", {
                className: "".concat(prefix, "-overview-devices-item-dashed")
              })]
            }, ele.img);
          })
        })]
      })
    }), /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u8BBE\u5907\u4FE1\u606F",
      children: /*#__PURE__*/_jsx(Row, {
        gutter: [32, 20],
        children: data === null || data === void 0 ? void 0 : data.map(function (ele, index) {
          return /*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsx(VmWrapper, {
              title: ele.name,
              children: /*#__PURE__*/_jsx(VmInfoCollection, {
                width: "50%",
                horizontal: true,
                data: [{
                  label: '累计工作时长',
                  value: ele.cumulativeWorkingTimeStr,
                  key: '1'
                }, {
                  label: '可用率',
                  value: "".concat(keepTwoNumRate(ele.availability), "%"),
                  key: '2'
                }, {
                  label: '最后心跳时间',
                  value: ele.lastHeartTime,
                  key: '3'
                }, {
                  label: '在线状态',
                  value: ele.status === 'online' ? '上线' : '下线',
                  key: '4',
                  color: ele.status === 'online' ? '#00B85C' : ''
                }, {
                  label: '最后上传数据时间',
                  value: ele.lastDataTime,
                  key: '5'
                }, {
                  label: '无数据时长',
                  value: ele.lastDataTime ? noDataTime(ele.lastDataTime) : '--',
                  key: '6',
                  color: ele.status === 'online' ? '#FF9500' : ''
                }]
              })
            })
          }, index);
        })
      })
    })]
  });
};
export default Sbzj;
export var keepTwoNumRate = function keepTwoNumRate(num) {
  var rate = num * 100;
  var str = "".concat(rate);
  if (str.includes('.')) {
    var answerStr = rate.toFixed(2);
    var i = 1;
    while (['.', '0'].includes(answerStr[answerStr.length - 1]) && i <= 3) {
      i++;
      answerStr = answerStr.substring(0, answerStr.length - 1);
    }
    return answerStr;
  } else {
    return "".concat(rate);
  }
};
var noDataTime = function noDataTime(time) {
  return dayjs(dayjs().diff(dayjs(time))).format('H小时mm分钟');
};