function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { VtxImage } from '@vtx/components';
import { getVtxToken } from '@vtx/utils';
import { useSetState } from 'ahooks';
import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import { useRef } from 'react';
import { VmEmpty, VmFilter, VmInfoCollection, VmPieCharts, VmTitle, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { DownIcon, UpIcon } from "../../../_util/iconSvgHtml";
import { BaseService } from "../../api";
import "./index.less";

// svg大小比png2倍还大，不如使用2次png
import { sumBy } from 'lodash';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var BaseInfo = function BaseInfo(props) {
  var _throwAnalysis$garbag, _alarmAnalysis$violat;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var id = props.id,
    photos = props.photos,
    baseInfo = props.baseInfo;
  var _useSetState = useSetState({
      dateType: 'datePicker',
      date: dayjs()
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var dateType = state.dateType,
    date = state.date;
  var imgRef = useRef(null);
  var formatType = {
    datePicker: 'day',
    monthPicker: 'month',
    yearPicker: 'year'
  };
  var _BaseService$useDevic = BaseService.useDeviceInfo(id),
    devices = _BaseService$useDevic.devices;
  var _BaseService$useThrow = BaseService.useThrowInfo(id, formatType[dateType], date.startOf(formatType[dateType]).format('YYYY-MM-DD'), date.endOf(formatType[dateType]).format('YYYY-MM-DD')),
    throwAnalysis = _BaseService$useThrow.throwAnalysis;
  var _BaseService$useAlarm = BaseService.useAlarmInfo(id, formatType[dateType], date.startOf(formatType[dateType]).format('YYYY-MM-DD'), date.endOf(formatType[dateType]).format('YYYY-MM-DD')),
    alarmAnalysis = _BaseService$useAlarm.alarmAnalysis;
  return /*#__PURE__*/_jsxs("div", {
    className: "tfd-base",
    children: [/*#__PURE__*/_jsx("div", {
      className: "tfd-base-left",
      children: /*#__PURE__*/_jsxs(VmWrapper, {
        title: "\u57FA\u672C\u4FE1\u606F",
        children: [/*#__PURE__*/_jsx("div", {
          className: "base-top-img",
          ref: imgRef,
          children: photos !== null && photos !== void 0 && photos.length ? /*#__PURE__*/_jsx("div", {
            style: {
              padding: '0 12px 12px'
            },
            children: /*#__PURE__*/_jsx(VtxImage, {
              src: "/cloudFile/common/downloadFile?id=".concat(photos[0].id, "&token=").concat(getVtxToken('token')),
              alt: photos[0].name,
              isDark: true,
              style: {
                maxWidth: '340px',
                height: 207,
                overflow: 'hidden'
              }
            }, photos[0].id)
          }) : /*#__PURE__*/_jsx(VmEmpty, {
            type: "NO_PICTURE",
            style: {
              height: 207
            }
          })
        }), /*#__PURE__*/_jsxs("div", {
          className: "base-top--base",
          style: {
            height: 382
          },
          children: [/*#__PURE__*/_jsx(VmInfoCollection, {
            data: baseInfo,
            horizontal: true,
            ellipsis: true,
            padding: '0 12px 12px'
          }), /*#__PURE__*/_jsx(VmTitle, {
            title: "\u8BBE\u5907\u60C5\u51B5"
          }), (devices === null || devices === void 0 ? void 0 : devices.length) > 0 ? /*#__PURE__*/_jsx("div", {
            className: "tfd-equipment",
            children: devices.map(function (ele, index) {
              return /*#__PURE__*/_jsxs("div", {
                className: "tfd-equipment-item",
                children: [/*#__PURE__*/_jsx("img", {
                  src: require("../../imgs/".concat(IMG[ele.typeCode]).concat(isDark ? '' : '_light').concat(ele.statusCode === 'ONLINE' ? '_online' : '', ".png"))
                }), /*#__PURE__*/_jsx("div", {
                  children: ele.name
                })]
              }, index);
            })
          }) : /*#__PURE__*/_jsx(VmEmpty, {
            type: "NO_DATA",
            text: "\u6682\u65E0\u8BBE\u5907",
            style: {
              height: 120
            }
          })]
        })]
      })
    }), /*#__PURE__*/_jsx("div", {
      className: "tfd-base-right",
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [16, 16],
        children: [/*#__PURE__*/_jsx(Col, {
          span: 24,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: "",
            filterType: dateType,
            filterChange: function filterChange(date) {
              setState({
                date: date
              });
            },
            style: {
              height: 52
            },
            headerStyle: {
              height: 52,
              borderBottom: 'unset'
            },
            showContent: false,
            dateValue: date,
            extra: /*#__PURE__*/_jsx("div", {
              style: {
                position: 'absolute',
                right: 200,
                top: 0,
                borderRadius: 10,
                background: 'rgba(12,154,255,0.99)'
              },
              children: /*#__PURE__*/_jsx(VmFilter.VMSelect, {
                value: dateType,
                options: [{
                  label: '日',
                  value: 'datePicker'
                }, {
                  label: '月',
                  value: 'monthPicker'
                }, {
                  label: '年',
                  value: 'yearPicker'
                }],
                onChange: function onChange(key) {
                  setState({
                    dateType: key
                  });
                }
              })
            })
          })
        }), /*#__PURE__*/_jsx(Col, {
          span: 24,
          children: /*#__PURE__*/_jsxs(VmWrapper, {
            title: "\u6295\u653E\u91CF\u5206\u6790",
            style: {
              height: 265
            },
            children: [/*#__PURE__*/_jsx(VmPieCharts, {
              height: 160,
              dataList: (throwAnalysis === null || throwAnalysis === void 0 || (_throwAnalysis$garbag = throwAnalysis.garbageValues) === null || _throwAnalysis$garbag === void 0 ? void 0 : _throwAnalysis$garbag.map(function (ele) {
                return _objectSpread(_objectSpread({}, ele), {}, {
                  name: ele.garbageTypeName,
                  value: ele.value
                });
              })) || [],
              name: '投放量',
              title: "\u6295\u653E\u91CF(".concat(dateType === 'datePicker' ? 'kg' : '吨', ")"),
              total: sumBy(throwAnalysis === null || throwAnalysis === void 0 ? void 0 : throwAnalysis.garbageValues, 'value'),
              loading: false,
              unit: dateType === 'datePicker' ? 'kg' : '吨',
              innerRadius: ['65%', '85%'],
              outerRadius: ['85%', '95%'],
              legendConfig: {
                right: '8%'
              },
              nameLength: 8
            }), /*#__PURE__*/_jsxs("div", {
              className: "tfd-base-right-compare",
              children: ["\u4E0E\u8FD130\u5929\u65E5\u5747\u503C\u6BD4", (throwAnalysis === null || throwAnalysis === void 0 ? void 0 : throwAnalysis.rate) || 0, "%", (throwAnalysis === null || throwAnalysis === void 0 ? void 0 : throwAnalysis.rate) < 0 && /*#__PURE__*/_jsx(DownIcon, {
                fill: '#f5222d'
              }), (throwAnalysis === null || throwAnalysis === void 0 ? void 0 : throwAnalysis.rate) > 0 && /*#__PURE__*/_jsx(UpIcon, {
                fill: '#0fb964'
              })]
            })]
          })
        }), /*#__PURE__*/_jsx(Col, {
          span: 24,
          children: /*#__PURE__*/_jsxs(VmWrapper, {
            title: "\u8FDD\u89C4\u5206\u6790",
            style: {
              height: 265
            },
            children: [/*#__PURE__*/_jsx(VmPieCharts, {
              height: 160,
              dataList: (alarmAnalysis === null || alarmAnalysis === void 0 || (_alarmAnalysis$violat = alarmAnalysis.violationValues) === null || _alarmAnalysis$violat === void 0 ? void 0 : _alarmAnalysis$violat.map(function (ele) {
                return _objectSpread(_objectSpread({}, ele), {}, {
                  name: ele.violationTypeName,
                  value: ele.count
                });
              })) || [],
              name: '违规类型',
              title: "\u5408\u8BA1(\u6B21)",
              total: sumBy(alarmAnalysis === null || alarmAnalysis === void 0 ? void 0 : alarmAnalysis.garbageValues, 'value'),
              loading: false,
              unit: "\u6B21",
              innerRadius: ['65%', '85%'],
              outerRadius: ['85%', '95%'],
              legendConfig: {
                right: '12%'
              },
              nameLength: 8
            }), /*#__PURE__*/_jsxs("div", {
              className: "tfd-base-right-compare",
              children: ["\u4E0E\u8FD130\u5929\u65E5\u5747\u503C\u6BD4", (alarmAnalysis === null || alarmAnalysis === void 0 ? void 0 : alarmAnalysis.rate) || 0, "%", (alarmAnalysis === null || alarmAnalysis === void 0 ? void 0 : alarmAnalysis.rate) < 0 && /*#__PURE__*/_jsx(DownIcon, {
                fill: '#f5222d'
              }), (alarmAnalysis === null || alarmAnalysis === void 0 ? void 0 : alarmAnalysis.rate) > 0 && /*#__PURE__*/_jsx(UpIcon, {
                fill: '#0fb964'
              })]
            })]
          })
        })]
      })
    })]
  });
};
export default BaseInfo;
var IMG = {
  SMALL_WEIGHING_MACHINE: 'xdb',
  INTELLIGENT_DELIVERY_MACHINE: 'zntfj',
  ELECTRONIC_SCALE: 'dzc',
  POINT_CHANGER: 'jfdhj',
  BAG_HAIR_MACHINE: 'fdj',
  CAMERA: 'sxt'
};