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 { QuestionCircleOutlined } from '@ant-design/icons';
import { Row, Space, Tooltip } from 'antd';
import dayjs from 'dayjs';
import { keyBy } from 'lodash';
import { useContext, useState } from 'react';
import { VmBarCharts, VmCalendar, VmCalendarInner, VmCalendarPercent, VmTable, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { LjsyService } from "../../../api";
import darkPointIcon from "../../../imgs/calendar/dark_point.png";
import lightPointIcon from "../../../imgs/calendar/point.png";
import darkTrashIcon from "../../../imgs/dark_trash.png";
import darkUnplannedIcon from "../../../imgs/dark_unplanned_point.png";
import darkWeightIcon from "../../../imgs/dark_weight.png";
import lightTrashIcon from "../../../imgs/trash.png";
import lightUnplannedIcon from "../../../imgs/unplanned_point.png";
import lightWeightIcon from "../../../imgs/weight.png";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var StaticInfo = function StaticInfo() {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState('calendar'),
    _useState2 = _slicedToArray(_useState, 2),
    type = _useState2[0],
    setType = _useState2[1];
  var _useContext = useContext(CarContext),
    id = _useContext.id;
  var _useState3 = useState(dayjs()),
    _useState4 = _slicedToArray(_useState3, 2),
    month = _useState4[0],
    setMonth = _useState4[1];
  var _LjsyService$useGetWo = LjsyService.useGetWorkInfo({
      carId: id,
      startDate: month.startOf('M').format('YYYY-MM-DD'),
      endDate: dayjs().isSame(month, 'month') ? dayjs().format('YYYY-MM-DD') : month.endOf('M').format('YYYY-MM-DD')
    }),
    taskDaySummary = _LjsyService$useGetWo.taskDaySummary,
    loading = _LjsyService$useGetWo.loading;
  var keyByDate = keyBy(taskDaySummary || [], 'date');
  var unplannedIcon = lightUnplannedIcon;
  var pointIcon = lightPointIcon;
  var trashIcon = lightTrashIcon;
  var weightIcon = lightWeightIcon;
  if (isDark) {
    unplannedIcon = darkUnplannedIcon;
    pointIcon = darkPointIcon;
    trashIcon = darkTrashIcon;
    weightIcon = darkWeightIcon;
  }
  var columns = [{
    title: '作业日期',
    dataIndex: 'date',
    key: 'date',
    sorter: function sorter(a, b) {
      return a.date > b.date ? 1 : -1;
    },
    width: 120
  }, {
    title: '计划收集点位（个）',
    dataIndex: 'planCollectPointNum',
    key: 'planCollectPointNum',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    width: 160
  }, {
    title: '计划内已收（个）',
    dataIndex: 'taskCollectPointNum',
    key: 'taskCollectPointNum',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    width: 160
  }, {
    title: '计划内未收（个）',
    dataIndex: 'taskNoCollectPointNum',
    key: 'taskNoCollectPointNum',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    width: 160
  }, {
    title: '计划外已收（个）',
    dataIndex: 'noneTaskCollectPointNum',
    key: 'noneTaskCollectPointNum',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    width: 160
  }, {
    title: '收集桶数（桶）',
    dataIndex: 'bucketNum',
    key: 'bucketNum',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    width: 160
  }, {
    title: '收集重量（kg）',
    dataIndex: 'weight',
    key: 'weight',
    render: function render(text) {
      return /*#__PURE__*/_jsx("span", {
        children: text !== null && text !== void 0 ? text : '-'
      });
    },
    align: 'right',
    width: 160
  }, {
    title: /*#__PURE__*/_jsxs(Space, {
      children: [/*#__PURE__*/_jsx("span", {
        children: "\u4EFB\u52A1\u5B8C\u6210\u7387"
      }), /*#__PURE__*/_jsx(Tooltip, {
        title: '任务完成率=计划内已收/计划收集点位',
        children: /*#__PURE__*/_jsx(QuestionCircleOutlined, {})
      })]
    }),
    dataIndex: 'completeRate',
    key: 'completeRate',
    align: 'right',
    render: function render(text) {
      return /*#__PURE__*/_jsxs("span", {
        children: [text, "%"]
      });
    },
    width: 160
  }];
  var tableProps = {
    pagination: false,
    dataSource: _.orderBy(taskDaySummary, 'date', 'desc')
  };
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var item = keyByDate[date];
    if (!item) {
      return null;
    }
    var planCollectPointNum = item.planCollectPointNum,
      noneTaskCollectPointNum = item.noneTaskCollectPointNum,
      bucketNum = item.bucketNum,
      taskCollectPointNum = item.taskCollectPointNum,
      weight = item.weight,
      completeRate = item.completeRate;
    var pointInfo = null;
    var collectInfo = null;
    if (planCollectPointNum && noneTaskCollectPointNum) {
      pointInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: pointIcon,
        content: /*#__PURE__*/_jsxs(Row, {
          justify: 'space-between',
          align: 'middle',
          style: {
            flex: 1
          },
          children: [/*#__PURE__*/_jsxs("div", {
            children: [/*#__PURE__*/_jsx("span", {
              style: {
                color: 'var(--green-color)'
              },
              children: taskCollectPointNum
            }), "/", /*#__PURE__*/_jsx("span", {
              children: planCollectPointNum
            })]
          }), /*#__PURE__*/_jsxs(Row, {
            style: {
              flex: 1
            },
            align: 'middle',
            justify: 'end',
            children: [/*#__PURE__*/_jsx("img", {
              src: unplannedIcon,
              width: 16,
              height: 16
            }), /*#__PURE__*/_jsx("span", {
              style: {
                marginLeft: 8
              },
              children: noneTaskCollectPointNum
            })]
          })]
        }),
        style: {
          width: '139px',
          justifyContent: 'flex-start',
          margin: '8px 0'
        }
      });
    } else if (planCollectPointNum) {
      pointInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: pointIcon,
        value: /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx("span", {
            style: {
              color: 'var(--green-color)'
            },
            children: taskCollectPointNum
          }), "/", /*#__PURE__*/_jsx("span", {
            children: planCollectPointNum
          })]
        }),
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      });
    } else if (noneTaskCollectPointNum) {
      pointInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: unplannedIcon,
        value: noneTaskCollectPointNum,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      });
    }
    if (weight && bucketNum) {
      collectInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: trashIcon,
        content: /*#__PURE__*/_jsxs(Row, {
          justify: 'space-between',
          align: 'middle',
          style: {
            flex: 1
          },
          children: [/*#__PURE__*/_jsx("div", {
            children: bucketNum
          }), /*#__PURE__*/_jsxs(Row, {
            style: {
              flex: 1
            },
            align: 'middle',
            justify: 'end',
            children: [/*#__PURE__*/_jsx("img", {
              src: weightIcon,
              width: 16,
              height: 16
            }), /*#__PURE__*/_jsx("span", {
              style: {
                marginLeft: 8
              },
              children: weight
            })]
          })]
        }),
        style: {
          width: '139px',
          justifyContent: 'flex-start',
          margin: '8px 0'
        }
      });
    } else if (bucketNum) {
      collectInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: trashIcon,
        value: bucketNum,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      });
    } else if (weight) {
      collectInfo = /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: weightIcon,
        value: weight,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      });
    }
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [planCollectPointNum ? /*#__PURE__*/_jsx(VmCalendarPercent, {
        percent: completeRate,
        color: 'blue'
      }) : null, pointInfo, collectInfo]
    });
  };
  return /*#__PURE__*/_jsxs(VmWrapper, {
    title: '作业分析',
    needChange: true,
    showCalendar: true,
    onChange: setType,
    filterType: "monthPicker",
    dateValue: month,
    filterChange: setMonth,
    disabledDate: function disabledDate(current) {
      return current && current > dayjs().endOf('M');
    },
    children: [type === 'calendar' && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsxs("div", {
        className: 'vtx-car-calendar-head',
        children: [[{
          name: '计划内已收/应收(个)',
          img: pointIcon,
          type: 'green'
        }, {
          name: '计划外已收(个)',
          img: unplannedIcon,
          type: 'green'
        }, {
          name: '垃圾桶数(桶)',
          img: trashIcon,
          type: 'blue'
        }, {
          name: '垃圾重量(kg)',
          img: weightIcon,
          type: 'blue'
        }].map(function (item, index) {
          return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
            value: item.name
          }), index);
        }), /*#__PURE__*/_jsxs(Space, {
          children: [/*#__PURE__*/_jsx("div", {
            className: 'vtx-car-calendar-complete-legend'
          }), /*#__PURE__*/_jsx("div", {
            children: "\u4EFB\u52A1\u5B8C\u6210\u7387"
          })]
        })]
      }), /*#__PURE__*/_jsx("div", {
        style: {
          flex: 1,
          minHeight: 0
        },
        children: /*#__PURE__*/_jsx(VmCalendar, {
          dateCellRender: dateCellRender,
          value: month
        })
      })]
    }), type === 'list' && /*#__PURE__*/_jsx(VmTable, _objectSpread({
      columns: columns,
      rowKey: "id"
    }, tableProps)), type === 'chart' && /*#__PURE__*/_jsx(VmBarCharts, {
      dataList: [{
        name: '计划收集点位',
        data: _.map(taskDaySummary, 'planCollectPointNum'),
        color: 'geekblue'
      }, {
        name: '计划内已收',
        data: _.map(taskDaySummary, 'taskCollectPointNum'),
        color: 'green'
      }, {
        name: '计划外已收',
        data: _.map(taskDaySummary, 'noneTaskCollectPointNum'),
        color: 'blue'
      }],
      xAxis: _.map(taskDaySummary, 'date'),
      yAxisList: [{
        key: '',
        unit: '个',
        name: '(个)'
      }, {
        key: "\u2000",
        unit: '%',
        name: '(%)'
      }],
      unit: '个',
      lineList: [{
        name: '任务完成率',
        data: _.map(taskDaySummary, function (item) {
          return "\u2000".concat(item.completeRate);
        }),
        color: isDark ? '#13F97A' : '#0FB964',
        yAxisIndex: 1
      }],
      loading: loading
    })]
  });
};
export default StaticInfo;