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 { sumBy } from 'lodash';
import { VmFilter, VmInfoCollection, VmLineCharts, VmMap, VmPieCharts, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService, ThrowService } from "../../api";
import { UNIT } from "../ThrowRecord";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var BaseInfo = function BaseInfo(props) {
  var _mapCenter, _info$geometryInfo3, _mapCenter2, _data$, _data$2, _data$3, _data$4;
  var id = props.id,
    info = props.info,
    baseInfo = props.baseInfo,
    mapPoints = props.mapPoints,
    customMapInfo = props.customMapInfo;
  var _useSettings = useSettings(),
    theme = _useSettings.theme,
    mapInfo = _useSettings.mapInfo;
  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 mapCenter = props.mapCenter || [];
  var _mapPoints = mapPoints;
  if (!(((_mapCenter = mapCenter) === null || _mapCenter === void 0 ? void 0 : _mapCenter.length) > 0)) {
    var _info$geometryInfo;
    if ((info === null || info === void 0 || (_info$geometryInfo = info.geometryInfo) === null || _info$geometryInfo === void 0 ? void 0 : _info$geometryInfo.type) === 'point') {
      var _info$geometryInfo2;
      mapCenter = (_info$geometryInfo2 = info.geometryInfo) === null || _info$geometryInfo2 === void 0 || (_info$geometryInfo2 = _info$geometryInfo2.lngLats) === null || _info$geometryInfo2 === void 0 ? void 0 : _info$geometryInfo2.split(',');
    } else {
      mapCenter = [mapInfo === null || mapInfo === void 0 ? void 0 : mapInfo.longitude, mapInfo === null || mapInfo === void 0 ? void 0 : mapInfo.latitude];
    }
  }
  if (!(mapPoints && (mapPoints === null || mapPoints === void 0 ? void 0 : mapPoints.length) > 0) && (info === null || info === void 0 || (_info$geometryInfo3 = info.geometryInfo) === null || _info$geometryInfo3 === void 0 ? void 0 : _info$geometryInfo3.type) === 'point') {
    var _info$geometryInfo4;
    _mapPoints = ((_info$geometryInfo4 = info.geometryInfo) === null || _info$geometryInfo4 === void 0 || (_info$geometryInfo4 = _info$geometryInfo4.lngLats) === null || _info$geometryInfo4 === void 0 || (_info$geometryInfo4 = _info$geometryInfo4.split(';')) === null || _info$geometryInfo4 === void 0 || (_info$geometryInfo4 = _info$geometryInfo4.map(function (item) {
      return item.split(',');
    })) === null || _info$geometryInfo4 === void 0 ? void 0 : _info$geometryInfo4.map(function (item, index) {
      return {
        id: "mapPoints_".concat(index),
        lng: item[0],
        lat: item[1],
        icon: 'SHXQ',
        color: '#44D77A'
      };
    })) || [];
  }
  var formatType = {
    datePicker: 'day',
    monthPicker: 'month',
    yearPicker: 'year'
  };
  var _ThrowService$useSumm = ThrowService.useSummaryInfo(id, date.startOf(formatType[dateType]).format('YYYY-MM-DD 00:00:00'), date.endOf(formatType[dateType]).format('YYYY-MM-DD 23:59:59')),
    data = _ThrowService$useSumm.data,
    loading = _ThrowService$useSumm.loading;
  var _BaseService$useTrend = BaseService.useTrendInfo(id, date.startOf(formatType[dateType]).format('YYYY-MM-DD'), date.endOf(formatType[dateType]).format('YYYY-MM-DD'), formatType[dateType]),
    trendXData = _BaseService$useTrend.trendXData,
    trendData = _BaseService$useTrend.trendData,
    trendLoading = _BaseService$useTrend.trendLoading;
  return /*#__PURE__*/_jsxs("div", {
    className: "shxq-base ".concat(theme),
    children: [/*#__PURE__*/_jsx("div", {
      className: "shxq-base-left",
      children: /*#__PURE__*/_jsxs(VmWrapper, {
        title: "\u57FA\u672C\u4FE1\u606F",
        children: [/*#__PURE__*/_jsx(VmInfoCollection, {
          data: baseInfo,
          gap: 8,
          ellipsis: true,
          isValueCenter: true
        }), /*#__PURE__*/_jsx("div", {
          className: "shxq-base-map",
          children: ((_mapCenter2 = mapCenter) === null || _mapCenter2 === void 0 ? void 0 : _mapCenter2.length) > 0 && /*#__PURE__*/_jsx(VmMap, _objectSpread({
            mapCenter: mapCenter,
            mapType: (mapInfo === null || mapInfo === void 0 ? void 0 : mapInfo.mapType) || 'bmap',
            mapPoints: _mapPoints,
            geometryType: "polygon",
            address: info === null || info === void 0 ? void 0 : info.address
          }, customMapInfo))
        })]
      })
    }), /*#__PURE__*/_jsx("div", {
      className: "shxq-base-right",
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [16, 16],
        children: [/*#__PURE__*/_jsx(Col, {
          span: 24,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: "\u6295\u653E\u60C5\u51B5\u7EDF\u8BA1",
            filterType: dateType,
            filterChange: function filterChange(date) {
              setState({
                date: date
              });
            },
            dateValue: date,
            extra: /*#__PURE__*/_jsx("div", {
              style: {
                position: 'absolute',
                right: 188,
                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
                  });
                }
              })
            }),
            contentStyle: {
              position: 'relative'
            },
            children: /*#__PURE__*/_jsx(VmPieCharts, {
              height: 172,
              dataList: data === null || data === void 0 ? void 0 : data.map(function (ele) {
                return {
                  name: ele.garbageTypeName,
                  value: ele.value,
                  rate: ele.rate
                };
              }),
              name: '投放总量',
              title: "\u603B\u91CF(".concat(dateType !== 'datePicker' && (data === null || data === void 0 || (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.statisticType) === 'THROW_WEIGHT' ? '吨' : UNIT[(data === null || data === void 0 || (_data$2 = data[0]) === null || _data$2 === void 0 ? void 0 : _data$2.statisticType) || 'THROW_WEIGHT'], ")"),
              total: sumBy(data, 'value'),
              loading: loading,
              unit: dateType !== 'datePicker' && (data === null || data === void 0 || (_data$3 = data[0]) === null || _data$3 === void 0 ? void 0 : _data$3.statisticType) === 'THROW_WEIGHT' ? '吨' : UNIT[data === null || data === void 0 || (_data$4 = data[0]) === null || _data$4 === void 0 ? void 0 : _data$4.statisticType],
              innerRadius: ['60%', '80%'],
              outerRadius: ['80%', '90%'],
              legendConfig: {
                right: '20%'
              },
              nameLength: 10
            })
          })
        }), /*#__PURE__*/_jsx(Col, {
          span: 24,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: "\u6295\u653E\u91CF\u8D8B\u52BF\u5206\u6790",
            style: {
              height: 328
            },
            children: /*#__PURE__*/_jsx(VmLineCharts, {
              xAxis: trendXData,
              dataList: trendData,
              unit: dateType === 'datePicker' ? 'kg' : '吨',
              loading: trendLoading,
              legendOption: {
                width: '95%'
              }
            })
          })
        })]
      })
    })]
  });
};
export default BaseInfo;