"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.MainItem = void 0;
var _react = _interopRequireDefault(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _antd = require("antd");
var _vmFilter = require("../../../vm-filter");
var _ChartJccc = _interopRequireDefault(require("./ChartJccc"));
var _ChartJcqs = _interopRequireDefault(require("./ChartJcqs"));
var _List = _interopRequireDefault(require("./List"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
require("./index.less");
var _vmWrapper = _interopRequireDefault(require("../../../vm-wrapper"));
var _zjcl = _interopRequireDefault(require("../../imgs/zjcl.svg"));
var _zjccc = _interopRequireDefault(require("../../imgs/zjccc.svg"));
var _rjjcl = _interopRequireDefault(require("../../imgs/rjjcl.svg"));
var _sjnl = _interopRequireDefault(require("../../imgs/sjnl.svg"));
var _zjcl_dark = _interopRequireDefault(require("../../imgs/zjcl_dark.svg"));
var _zjccc_dark = _interopRequireDefault(require("../../imgs/zjccc_dark.svg"));
var _rjjcl_dark = _interopRequireDefault(require("../../imgs/rjjcl_dark.svg"));
var _sjnl_dark = _interopRequireDefault(require("../../imgs/sjnl_dark.svg"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 Metering = function Metering(props) {
  var id = props.id;
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var _useSetState = (0, _ahooks.useSetState)({
      startDate: sDate ? sDate : (0, _moment["default"])().subtract(30, 'days').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : (0, _moment["default"])().format('YYYY-MM-DD'),
      tabKey: '1'
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate,
    tabKey = state.tabKey;
  var _BaseService$useBaseI = _api.BaseService.useBaseInfo(id),
    code = _BaseService$useBaseI.code;
  var _BaseService$useTrend = _api.BaseService.useTrendInfo(code, startDate, endDate),
    trendRes = _BaseService$useTrend.trendRes;
  var _BaseService$useSitua = _api.BaseService.useSituationSummary(code, startDate, endDate),
    situationRes = _BaseService$useSitua.situationRes;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  var disabledDate = function disabledDate(current) {
    var sdate = (0, _moment["default"])(startDate);
    var eDate = (0, _moment["default"])(endDate);
    var tooLate = sdate && current.diff(sdate, 'month') > 2;
    var tooEarly = eDate && eDate.diff(current, 'month') > 2;
    return !!tooEarly || !!tooLate;
  };
  var rate = ((situationRes === null || situationRes === void 0 ? void 0 : situationRes.dailyInWeight) || 0) / ((situationRes === null || situationRes === void 0 ? void 0 : situationRes.handleAbility) || 1) * 100;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [16, 16]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 24
  }, /*#__PURE__*/_react["default"].createElement(_vmWrapper["default"], {
    title: "\u8FDB\u573A\u6C47\u603B\u5206\u6790",
    onChange: function onChange(key) {
      setState({
        tabKey: key
      });
    },
    extra: /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
      disabledDate: disabledDate,
      onChange: function onChange(dates) {
        return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).format('YYYY-MM-DD'));
      }
    }))
  }, tabKey === 'chart' && (/*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main"
  }, /*#__PURE__*/_react["default"].createElement(MainItem, {
    src: isDark ? _zjcl_dark["default"] : _zjcl["default"],
    name: "\u603B\u8FDB\u573A\u91CF",
    value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.inWeight) || 0,
    unit: "\u5428"
  }), /*#__PURE__*/_react["default"].createElement(MainItem, {
    src: isDark ? _zjccc_dark["default"] : _zjccc["default"],
    name: "\u603B\u8FDB\u573A\u8F66\u6B21",
    value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.carNum) || 0,
    unit: "\u6B21"
  }), /*#__PURE__*/_react["default"].createElement(MainItem, {
    src: isDark ? _rjjcl_dark["default"] : _rjjcl["default"],
    name: "\u65E5\u5747\u8FDB\u573A\u91CF",
    value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.dailyInWeight) || 0,
    unit: "\u5428"
  }), /*#__PURE__*/_react["default"].createElement(MainItem, {
    src: isDark ? _sjnl_dark["default"] : _sjnl["default"],
    name: "\u8BBE\u8BA1\u80FD\u529B",
    value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.handleAbility) || 0,
    unit: "\u5428/\u65E5"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-avg"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-avg-line"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-avg-item"
  }, /*#__PURE__*/_react["default"].createElement("div", null, "\u65E5\u5747\u8D1F\u8377"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-avg-value"
  }, rate === null || rate === void 0 ? void 0 : rate.toFixed(2), /*#__PURE__*/_react["default"].createElement("span", null, "%"))), /*#__PURE__*/_react["default"].createElement(_antd.Progress, {
    percent: rate,
    strokeColor: rate > 100 ? {
      from: '#FF5861',
      to: '#FF000E'
    } : isDark ? {
      from: '#139DFF',
      to: '#00FFF6'
    } : '#1677FF',
    status: "active",
    showInfo: false
  })))), tabKey === 'list' && (/*#__PURE__*/_react["default"].createElement(_List["default"], {
    code: code,
    startDate: startDate,
    endDate: endDate
  }))))), tabKey === 'chart' && (/*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-charts"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [10, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-charts-jcqs"
  }, /*#__PURE__*/_react["default"].createElement(_ChartJcqs["default"], Object.assign({}, trendRes)))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-charts-jccc"
  }, /*#__PURE__*/_react["default"].createElement(_ChartJccc["default"], {
    code: code,
    startDate: startDate,
    endDate: endDate
  })))))));
};
var MainItem = exports.MainItem = function MainItem(props) {
  var src = props.src,
    name = props.name,
    value = props.value,
    unit = props.unit;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-item"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: src
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-item--name"
  }, name), /*#__PURE__*/_react["default"].createElement("div", {
    className: "metering-content-main-item--value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, value), unit)));
};
var _default = exports["default"] = Metering;
//# sourceMappingURL=index.js.map
