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 { useSetState } from 'ahooks';
import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import { VmFactor, VmProgress, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { CommonService } from "../../../_service";
import { BaseService } from "../../api";
import ChartJccc from "./ChartJccc";
import ChartJcqs from "./ChartJcqs";
import "./index.less";
import List from "./List";
import rjjclIcon from "../../imgs/rjjcl.svg";
import sjnlIcon from "../../imgs/sjnl.svg";
import zjcccIcon from "../../imgs/zjccc.svg";
import zjclIcon from "../../imgs/zjcl.svg";
import rjjclDark from "../../imgs/rjjcl_dark.svg";
import sjnlDark from "../../imgs/sjnl_dark.svg";
import zjcccDark from "../../imgs/zjccc_dark.svg";
import zjclDark from "../../imgs/zjcl_dark.svg";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Metering = function Metering(props) {
  var id = props.id;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var _useSetState = useSetState({
      startDate: sDate ? sDate : dayjs().subtract(30, 'days').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : dayjs().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 _CommonService$useBas = CommonService.useBaseInfo(id),
    code = _CommonService$useBas.code;
  var _BaseService$useTrend = BaseService.useTrendInfo(code, startDate, endDate),
    trendRes = _BaseService$useTrend.trendRes;
  var _BaseService$useSitua = 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 = dayjs(startDate);
    var eDate = dayjs(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__*/_jsxs("div", {
    className: "metering",
    children: [/*#__PURE__*/_jsx(Row, {
      gutter: [16, 16],
      children: /*#__PURE__*/_jsx(Col, {
        span: 24,
        children: /*#__PURE__*/_jsxs(VmWrapper, {
          title: "\u8FDB\u573A\u6C47\u603B\u5206\u6790",
          onChange: function onChange(key) {
            setState({
              tabKey: key
            });
          },
          needChange: true,
          dateValue: [dayjs(startDate), dayjs(endDate)],
          disabledDate: disabledDate,
          filterType: "rangePicker",
          defaultValue: [dayjs().subtract(1, 'M'), dayjs()],
          filterChange: function filterChange(dates) {
            return dates && handleDateChange(dayjs(dates[0]).format('YYYY-MM-DD'), dayjs(dates[1]).format('YYYY-MM-DD'));
          },
          children: [tabKey === 'chart' && /*#__PURE__*/_jsxs("div", {
            className: "metering-content-main",
            children: [/*#__PURE__*/_jsx(VmFactor, {
              name: "\u603B\u8FDB\u573A\u91CF",
              unit: "\u5428",
              fontType: "blue",
              value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.inWeight) || 0,
              img: isDark ? zjclDark : zjclIcon
            }), /*#__PURE__*/_jsx(VmFactor, {
              img: isDark ? zjcccDark : zjcccIcon,
              name: "\u603B\u8FDB\u573A\u8F66\u6B21",
              fontType: "green",
              value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.carNum) || 0,
              unit: "\u6B21"
            }), /*#__PURE__*/_jsx(VmFactor, {
              img: isDark ? rjjclDark : rjjclIcon,
              name: "\u65E5\u5747\u8FDB\u573A\u91CF",
              fontType: "cyan",
              value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.dailyInWeight) || 0,
              unit: "\u5428"
            }), /*#__PURE__*/_jsx(VmFactor, {
              img: isDark ? sjnlDark : sjnlIcon,
              name: "\u8BBE\u8BA1\u80FD\u529B",
              fontType: "yellow",
              value: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.handleAbility) || 0,
              unit: "\u5428/\u65E5"
            }), /*#__PURE__*/_jsxs("div", {
              className: "metering-content-main-avg",
              children: [/*#__PURE__*/_jsx("div", {
                className: "metering-content-main-avg-line"
              }), /*#__PURE__*/_jsxs("div", {
                className: "metering-content-main-avg-item",
                children: [/*#__PURE__*/_jsx("div", {
                  children: "\u65E5\u5747\u8D1F\u8377"
                }), /*#__PURE__*/_jsxs("div", {
                  className: "metering-content-main-avg-value",
                  children: [rate === null || rate === void 0 ? void 0 : rate.toFixed(2), /*#__PURE__*/_jsx("span", {
                    children: "%"
                  })]
                })]
              }), /*#__PURE__*/_jsx(VmProgress.Line, {
                rate: rate
              })]
            })]
          }), tabKey === 'list' && /*#__PURE__*/_jsx(List, {
            code: code,
            startDate: startDate,
            endDate: endDate
          })]
        })
      })
    }), tabKey === 'chart' && /*#__PURE__*/_jsx("div", {
      className: "metering-content-charts",
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [10, 10],
        children: [/*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(ChartJcqs, _objectSpread({}, trendRes))
        }), /*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(ChartJccc, {
            code: code,
            startDate: startDate,
            endDate: endDate
          })
        })]
      })
    })]
  });
};
export var MainItem = function MainItem(props) {
  var src = props.src,
    name = props.name,
    value = props.value,
    unit = props.unit;
  return /*#__PURE__*/_jsxs("div", {
    className: "metering-content-main-item",
    children: [/*#__PURE__*/_jsx("img", {
      src: src
    }), /*#__PURE__*/_jsxs("div", {
      children: [/*#__PURE__*/_jsx("div", {
        className: "metering-content-main-item--name",
        children: name
      }), /*#__PURE__*/_jsxs("div", {
        className: "metering-content-main-item--value",
        children: [/*#__PURE__*/_jsx("span", {
          children: value
        }), unit]
      })]
    })]
  });
};
export default Metering;