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 classnames from 'classnames';
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import { useEffect, useMemo, useState } from 'react';
import { VmBarCharts, VmFactor, VmLineCharts, VmWrapper } from "../../../_components";
import { VMSelect } from "../../../_components/vm-filter";
import useSettings from "../../../_hooks/useSettings";
import { LaneService } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Statistical = function Statistical(_ref) {
  var id = _ref.id;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var _useSetState = useSetState({
      startDate: sDate ? sDate : dayjs().startOf('M'),
      endDate: eDate ? eDate : dayjs()
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = dayjs(state.startDate).format('YYYY-MM-DD');
  var endDate = dayjs(state.endDate).format('YYYY-MM-DD');
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    shiftId = _useState2[0],
    setShiftId = _useState2[1];
  var _LaneService$useWorkS = LaneService.useWorkSummary(id, startDate, endDate),
    workSummary = _LaneService$useWorkS.workSummary;
  var totalWorkInfo = workSummary.totalWorkInfo,
    completeRate = workSummary.completeRate,
    shiftInfoWorkInfos = workSummary.shiftInfoWorkInfos,
    facilityTypeWorkInfos = workSummary.facilityTypeWorkInfos;
  var _ref2 = totalWorkInfo || {},
    days = _ref2.days,
    workMileage = _ref2.workMileage,
    planMileage = _ref2.planMileage;
  useEffect(function () {
    if (!isEmpty(shiftInfoWorkInfos)) {
      setShiftId(shiftInfoWorkInfos[0].id);
    }
  }, [shiftInfoWorkInfos]);
  var facilityTypeData = useMemo(function () {
    var xAxis = [];
    var dataList = [];
    (facilityTypeWorkInfos || []).forEach(function (item, index) {
      var facilityTypeName = item.facilityTypeName,
        dayWorkInfos = item.dayWorkInfos;
      var data = [];
      dayWorkInfos.forEach(function (dayItem) {
        data.push(dayItem.completeRate);
        if (index === 0) {
          xAxis.push(dayItem.date);
        }
      });
      dataList.push({
        name: facilityTypeName,
        data: data,
        smooth: true,
        symbol: 'none'
      });
    });
    return {
      xAxis: xAxis,
      dataList: dataList
    };
  }, [facilityTypeWorkInfos]);
  var shiftData = useMemo(function () {
    var shiftInfo = (shiftInfoWorkInfos || []).find(function (item) {
      return item.id === shiftId;
    });
    if (shiftInfo) {
      var xAxis = [];
      var planMileageList = [];
      var workMileageList = [];
      (shiftInfo.dayWorkInfos || []).forEach(function (item) {
        xAxis.push(item.date);
        planMileageList.push(item.planMileage);
        workMileageList.push(item.workMileage);
      });
      return {
        xAxis: xAxis,
        dataList: [{
          name: '排班里程',
          data: planMileageList,
          color: 'geekblue'
        }, {
          name: '作业里程',
          data: workMileageList,
          color: 'green'
        }]
      };
    }
    return {};
  }, [shiftInfoWorkInfos, shiftId]);
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    children: [/*#__PURE__*/_jsx(Col, {
      span: 24,
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '作业汇总分析',
        filterType: 'rangePicker',
        filterChange: function filterChange(date) {
          setState({
            startDate: date[0],
            endDate: date[1]
          });
        },
        dateValue: [state.startDate, state.endDate],
        children: /*#__PURE__*/_jsxs(Row, {
          align: 'middle',
          justify: 'center',
          children: [/*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsxs(Row, {
              gutter: [26, 26],
              align: 'middle',
              justify: 'center',
              children: [/*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '排班天数',
                  unit: '天',
                  fontType: 'cyan',
                  value: days,
                  img: isDark ? require("../../imgs/factor/dark_over_rate.png") : require("../../imgs/factor/over_rate.png")
                })
              }), /*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '排班总里程',
                  unit: '公里',
                  fontType: 'blue',
                  value: planMileage,
                  img: isDark ? require("../../imgs/factor/dark_plan_mileage.png") : require("../../imgs/factor/plan_mileage.png")
                })
              }), /*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '作业总里程',
                  unit: '公里',
                  fontType: 'green',
                  value: workMileage,
                  img: isDark ? require("../../imgs/factor/dark_valid_mileage.png") : require("../../imgs/factor/valid_mileage.png")
                })
              })]
            })
          }), /*#__PURE__*/_jsxs(Col, {
            span: 12,
            children: [/*#__PURE__*/_jsxs(Row, {
              align: 'middle',
              justify: 'space-between',
              style: {
                fontWeight: 600,
                fontSize: 16,
                marginBottom: 10
              },
              children: [/*#__PURE__*/_jsx("div", {
                children: "\u5E73\u5747\u5B8C\u6210\u7387"
              }), /*#__PURE__*/_jsxs("div", {
                children: [totalWorkInfo === null || totalWorkInfo === void 0 ? void 0 : totalWorkInfo.completeRate, "%"]
              })]
            }), /*#__PURE__*/_jsxs("div", {
              className: classnames('road-statistic-summary-main-rate', {
                'road-statistic-summary-main-rate-dark': isDark
              }),
              children: [/*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--red-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '<50%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_yellow: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completeRate === null || completeRate === void 0 ? void 0 : completeRate.rate1Days) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--yellow-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '50%≤完成率<80%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_blue: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completeRate === null || completeRate === void 0 ? void 0 : completeRate.rate2Days) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--blue-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '80%≤完成率<100%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_green: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completeRate === null || completeRate === void 0 ? void 0 : completeRate.rate3Days) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--green-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '=100%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_blue: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completeRate === null || completeRate === void 0 ? void 0 : completeRate.rate4Days) || 0
                  }), "\u5929"]
                })]
              })]
            })]
          })]
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 24,
      flex: 'auto',
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [16, 16],
        children: [/*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '班次完成情况分析',
            extraLeft: /*#__PURE__*/_jsx(VMSelect, {
              options: (shiftInfoWorkInfos || []).filter(function (item) {
                return item.startTime && item.endTime;
              }).map(function (item) {
                return {
                  label: "".concat(item.name, "(").concat(item.startTime.slice(0, 5), " ~ ").concat(item.endTime.slice(0, 5), ")"),
                  value: item.id
                };
              }),
              value: shiftId,
              onChange: setShiftId,
              allowClear: false
            }),
            children: /*#__PURE__*/_jsx(VmBarCharts, {
              height: 299,
              dataList: shiftData.dataList,
              xAxis: shiftData.xAxis,
              unit: "km",
              yAxisList: [{
                key: '',
                unit: 'km',
                name: '(km)'
              }]
            })
          })
        }), /*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '车道完成情况分析',
            children: /*#__PURE__*/_jsx(VmLineCharts, {
              dataList: facilityTypeData.dataList,
              xAxis: facilityTypeData.xAxis,
              unit: '%',
              height: 299,
              legendOption: {
                left: 'center'
              }
            })
          })
        })]
      })
    })]
  });
};
export default Statistical;