"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 _vmWrapper = _interopRequireDefault(require("../../../vm-wrapper"));
var _vmFilter = require("../../../vm-filter");
var _vmInfoCollection = _interopRequireDefault(require("../../../vm-info-collection"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _Jcqsfx = _interopRequireDefault(require("./Jcqsfx"));
var _Qyjcl = _interopRequireDefault(require("./Qyjcl"));
var _Situation = _interopRequireDefault(require("./Situation"));
var _RealtimeMonitor = _interopRequireDefault(require("./RealtimeMonitor"));
var _api = require("../../api");
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,
    hasLm = props.hasLm,
    realtimeMonitor = props.realtimeMonitor;
  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,
      basicHeight: 380
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var imgRef = (0, _react.useRef)(null);
  var startDate = state.startDate,
    endDate = state.endDate;
  var fields = _api.BaseService.getFields(info === null || info === void 0 ? void 0 : info.typeCode);
  var _BaseService$useSitua = _api.BaseService.useSituation(code, nowDate),
    situationRes = _BaseService$useSitua.situationRes;
  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(_antd.Row, {
    gutter: [16, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 7
  }, /*#__PURE__*/_react["default"].createElement(_vmWrapper["default"], {
    title: "\u57FA\u672C\u4FE1\u606F",
    needChange: false
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top-img",
    ref: imgRef
  }, 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',
      height: 220,
      overflow: 'hidden'
    }
  }))) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: 220
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top--base",
    style: {
      height: 382
    }
  }, /*#__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
  }, hasLm && (/*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [16, 16],
    style: {
      marginBottom: 10
    }
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_vmWrapper["default"], {
    title: "\u5B9E\u65F6\u8FDB\u573A\u60C5\u51B5",
    needChange: false
  }, /*#__PURE__*/_react["default"].createElement(_Situation["default"], {
    situationRes: situationRes
  }), ' ')), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 16
  }, /*#__PURE__*/_react["default"].createElement(_vmWrapper["default"], {
    title: "\u533A\u57DF\u8FDB\u573A\u91CF\u5206\u6790",
    needChange: false,
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      defaultValue: [(0, _moment["default"])().subtract(1, 'M'), (0, _moment["default"])()],
      onChange: function onChange(dates) {
        return dates && setState({
          startDate: (0, _moment["default"])(dates[0]).format('YYYY-MM-DD'),
          endDate: (0, _moment["default"])(dates[1]).format('YYYY-MM-DD')
        });
      }
    })
  }, /*#__PURE__*/_react["default"].createElement(_Qyjcl["default"], {
    code: code,
    startDate: startDate,
    endDate: endDate
  }))))), (realtimeMonitor === null || realtimeMonitor === void 0 ? void 0 : realtimeMonitor.length) > 0 ? (/*#__PURE__*/_react["default"].createElement(_RealtimeMonitor["default"], {
    realtimeMonitor: realtimeMonitor,
    hasLm: hasLm
  })) : null, hasLm && !(realtimeMonitor === null || realtimeMonitor === void 0 ? void 0 : realtimeMonitor.length) ? (
  /*#__PURE__*/
  // 仅有计量
  _react["default"].createElement(_Jcqsfx["default"], {
    code: code,
    startDate: startDate,
    endDate: endDate
  })) : null)));
};
var _default = exports["default"] = BaseInfo;
//# sourceMappingURL=index.js.map
