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 dayjs from 'dayjs';
import { keyBy } from 'lodash';
import { useContext, useState } from 'react';
import { VmBarCharts, VmCalendar, VmCalendarInner, VmTable, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { JzljService } from "../../../api";
import lds_dark from "../../../imgs/jzlj/rl_lds_dark.png";
import lds_light from "../../../imgs/jzlj/rl_lds_light.png";
import yl_dark from "../../../imgs/jzlj/rl_yl_dark.png";
import yl_light from "../../../imgs/jzlj/rl_yl_light.png";
import { CarContext } from "../../../index";
import "./index.less";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export default function RunCalendar() {
  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 _JzljService$useYxfx = JzljService.useYxfx({
      id: id,
      startDate: month.startOf('M').format('YYYY-MM-DD'),
      endDate: month.endOf('M').format('YYYY-MM-DD')
    }),
    _JzljService$useYxfx$ = _JzljService$useYxfx.yxfxData,
    yxfxData = _JzljService$useYxfx$ === void 0 ? [] : _JzljService$useYxfx$,
    loading = _JzljService$useYxfx.loading;
  var keyByDate = keyBy(yxfxData || [], 'date');
  var lds_icon = lds_light;
  var yl_icon = yl_light;
  if (isDark) {
    lds_icon = lds_dark;
    yl_icon = yl_dark;
  }
  var _JzljService$useUnit = JzljService.useUnit(),
    unitStr = _JzljService$useUnit.unitStr;
  var columns = [{
    title: '日期',
    dataIndex: 'date',
    key: 'date',
    width: 100
  }, {
    title: '联单数(次)',
    dataIndex: 'count',
    key: 'count',
    width: 100
  }, {
    title: "\u8FD0\u91CF(".concat(unitStr, ")"),
    dataIndex: 'weight',
    key: 'weight',
    width: 100
  }];
  var tableProps = {
    pagination: false,
    height: 440,
    dataSource: yxfxData
  };
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var item = keyByDate[date];
    if (!item) {
      return null;
    }
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: lds_icon,
        value: item.count + ' 次',
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: yl_icon,
        value: item.weight + " ".concat(unitStr),
        style: {
          width: '139px',
          justifyContent: 'space-between'
        }
      })]
    });
  };
  return /*#__PURE__*/_jsx("div", {
    className: "vtx-jzlj-car-run-calendar",
    children: /*#__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__*/_jsx("div", {
          className: "vtx-jzlj-car-run-calendar-head",
          children: [{
            name: '联单数(次)',
            img: lds_icon,
            type: 'blue'
          }, {
            name: "\u8FD0\u91CF(".concat(unitStr, ")"),
            img: yl_icon,
            type: 'green'
          }].map(function (item, index) {
            return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
              value: item.name
            }), index);
          })
        }), /*#__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: yxfxData.map(function (item) {
            return "\u2000".concat(item.count);
          })
        }],
        xAxis: yxfxData.map(function (item) {
          return item.date;
        }),
        yAxisList: [{
          key: "\u2000",
          unit: '次',
          name: '联单数(次)'
        }, {
          key: '',
          unit: unitStr,
          name: "\u8FD0\u91CF(".concat(unitStr, ")")
        }],
        unit: unitStr,
        lineList: [{
          name: '运量',
          data: yxfxData.map(function (item) {
            return item.weight;
          }),
          yAxisIndex: 1
        }],
        loading: loading
      })]
    })
  });
}