"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _utils = require("@vtx/utils");
var _util = require("../../../util");
var _components = require("@vtx/components");
var _antd = require("antd");
var _vmInfoCollection = _interopRequireDefault(require("../../../vm-info-collection"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _vmSubTitle = require("../../../vm-sub-title");
var _Jcqsfx = _interopRequireDefault(require("./Jcqsfx"));
var _Situation = _interopRequireDefault(require("./Situation"));
var _AlarmDetail = _interopRequireDefault(require("./AlarmDetail"));
var _api = require("../../api");
var _RealtimeMonitor = _interopRequireDefault(require("./RealtimeMonitor"));
require("./index.less");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
var BaseInfo = function BaseInfo(props) {
  var _a;
  var info = props.info,
    photos = props.photos,
    code = props.code;
  var nowDate = (0, _moment["default"])().format('YYYY-MM-DD');
  var _useSetState = (0, _ahooks.useSetState)({
      startDate: (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'),
      endDate: nowDate,
      startDateAlarm: (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'),
      endDateAlarm: nowDate,
      basicHeight: 380
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var imgRef = (0, _react.useRef)(null);
  var startDateAlarm = state.startDateAlarm,
    endDateAlarm = state.endDateAlarm,
    basicHeight = state.basicHeight;
  var fields = _api.BaseService.getFields(info === null || info === void 0 ? void 0 : info.typeCode);
  var _BaseService$useSitua = _api.BaseService.useSituationAlarm(code, nowDate, nowDate),
    situationAlarmRes = _BaseService$useSitua.situationAlarmRes;
  var _BaseService$useMonit = _api.BaseService.useMonitorCarExeception(code, nowDate, situationAlarmRes),
    execeptionCar = _BaseService$useMonit.execeptionCar;
  var _BaseService$useMonit2 = _api.BaseService.useMonitorPointExeception(code, situationAlarmRes),
    execeptionPoint = _BaseService$useMonit2.execeptionPoint;
  var contentHeight = ((_a = imgRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0;
  (0, _react.useEffect)(function () {
    if (contentHeight >= 0) {
      setState({
        basicHeight: 738 - contentHeight
      });
    }
  }, [contentHeight]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-baseContent"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [10, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 7
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top-img",
    ref: imgRef
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle.SubTitle2, {
    title: "\u5168\u666F\u56FE",
    extra: (execeptionPoint || execeptionCar) && (/*#__PURE__*/_react["default"].createElement("div", {
      className: "base-top-desc-exec"
    }, execeptionPoint || execeptionCar || '-'))
  }), photos.length ? (/*#__PURE__*/_react["default"].createElement("div", {
    style: {
      padding: '0 12px 12px'
    }
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxImage, {
    key: photos[0].id,
    src: "/cloudFile/common/downloadFile?id=".concat(photos[0].id, "&token=").concat((0, _utils.getVtxToken)('token')),
    alt: photos[0].name,
    isDark: true,
    style: {
      maxWidth: '340px',
      overflow: 'hidden'
    }
  }))) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: 240
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top--base",
    style: {
      height: basicHeight
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle.SubTitle2, {
    title: "\u57FA\u672C\u4FE1\u606F"
  }), /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: (0, _util.getFieldRender)(fields, info),
    horizontal: true,
    width: "50%",
    ellipsis: true,
    padding: '0 12px 12px'
  }))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 17
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom--left"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle.SubTitle2, {
    title: "\u5B9E\u65F6\u8FD0\u884C\u60C5\u51B5(".concat((0, _moment["default"])().format('YYYY-MM-DD'), ")")
  }), /*#__PURE__*/_react["default"].createElement(_Situation["default"], {
    code: code,
    alarm: situationAlarmRes
  })), /*#__PURE__*/_react["default"].createElement(_Jcqsfx["default"], {
    code: code,
    setDate: function setDate(start, end) {
      setState({
        startDate: start,
        endDate: end
      });
    }
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom"
  }, situationAlarmRes >= 0 ? (/*#__PURE__*/_react["default"].createElement(_RealtimeMonitor["default"], {
    code: code
  })) : (/*#__PURE__*/_react["default"].createElement(_AlarmDetail["default"], {
    code: code,
    startDate: startDateAlarm,
    endDate: endDateAlarm,
    setState: setState
  })))))));
};
var _default = exports["default"] = BaseInfo;
//# sourceMappingURL=index.js.map
