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 { Space } from 'antd';
import dayjs from 'dayjs';
import { useState } from 'react';
import { VmCalendar, VmCalendarInner, VmCalendarPercent, VmWrapper } from "../../../_components";
import { VMSelect } from "../../../_components/vm-filter";
import useSettings from "../../../_hooks/useSettings";
import { LaneService } from "../../api";
import darkWorkMileageIcon from "../../imgs/calendar/dark_green_mileage.png";
import darkMileageIcon from "../../imgs/calendar/dark_mileage.png";
import lightWorkMileageIcon from "../../imgs/calendar/green_mileage.png";
import lightMileageIcon from "../../imgs/calendar/mileage.png";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var Calendar = function Calendar(_ref) {
  var id = _ref.id;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState(dayjs()),
    _useState2 = _slicedToArray(_useState, 2),
    month = _useState2[0],
    setMonth = _useState2[1];
  var _useState3 = useState(undefined),
    _useState4 = _slicedToArray(_useState3, 2),
    workTypeCodes = _useState4[0],
    setWorkTypeCodes = _useState4[1];
  var _useState5 = useState(undefined),
    _useState6 = _slicedToArray(_useState5, 2),
    facilityTypeCodes = _useState6[0],
    setFacilityTypeCodes = _useState6[1];
  var _LaneService$useCalen = LaneService.useCalendar({
      id: id,
      startDate: dayjs(month).startOf('month').format('YYYY-MM-DD'),
      endDate: dayjs(month).endOf('month').format('YYYY-MM-DD'),
      workTypeCodes: workTypeCodes,
      facilityTypeCodes: facilityTypeCodes
    }),
    calendarInfo = _LaneService$useCalen.calendarInfo;
  var workTypeCodeList = LaneService.useGetParams('param_zyqs_workingType');
  var _LaneService$useGetLa = LaneService.useGetLaneList(),
    laneList = _LaneService$useGetLa.laneList;
  var mileageIcon = lightMileageIcon;
  var workMileageIcon = lightWorkMileageIcon;
  if (isDark) {
    mileageIcon = darkMileageIcon;
    workMileageIcon = darkWorkMileageIcon;
  }
  var dateCellRender = function dateCellRender(value) {
    var date = dayjs(value).format('YYYY-MM-DD');
    var info = calendarInfo[date];
    var _ref2 = info || {},
      planMileage = _ref2.planMileage,
      workMileage = _ref2.workMileage,
      completeRate = _ref2.completeRate;
    var color = 'gray';
    if (completeRate > 0 && completeRate <= 50) {
      color = 'red';
    } else if (completeRate > 50 && completeRate <= 80) {
      color = 'yellow';
    } else if (completeRate > 80 && completeRate < 100) {
      color = 'blue';
    } else if (completeRate >= 100) {
      color = 'green';
    }
    return info && /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx(VmCalendarPercent, {
        percent: completeRate,
        color: color
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "blue",
        img: mileageIcon,
        value: planMileage,
        style: {
          width: '139px',
          justifyContent: 'space-between',
          margin: '8px 0'
        }
      }), /*#__PURE__*/_jsx(VmCalendarInner, {
        type: "green",
        img: workMileageIcon,
        value: workMileage,
        style: {
          width: '139px',
          justifyContent: 'space-between'
        }
      })]
    });
  };
  return /*#__PURE__*/_jsxs(VmWrapper, {
    title: '作业分析',
    extraLeft: /*#__PURE__*/_jsxs(Space, {
      children: [/*#__PURE__*/_jsx(VMSelect, {
        options: laneList,
        style: {
          width: 160
        },
        placeholder: "\u8BF7\u9009\u62E9\u8F66\u9053",
        onChange: setFacilityTypeCodes,
        value: facilityTypeCodes,
        allowClear: true
      }), /*#__PURE__*/_jsx(VMSelect, {
        options: workTypeCodeList,
        style: {
          width: 160
        },
        placeholder: "\u8BF7\u9009\u62E9\u4F5C\u4E1A\u7C7B\u578B",
        onChange: setWorkTypeCodes,
        value: workTypeCodes,
        allowClear: true
      })]
    }),
    filterType: "monthPicker",
    dateValue: month,
    filterChange: setMonth,
    disabledDate: function disabledDate(current) {
      return current && current > dayjs().endOf('M');
    },
    children: [/*#__PURE__*/_jsxs("div", {
      className: 'vtx-road-calendar-head',
      children: [[{
        name: '排班里程（km）',
        img: mileageIcon,
        type: 'blue'
      }, {
        name: '作业里程（km）',
        img: workMileageIcon,
        type: 'green'
      }].map(function (item, index) {
        return /*#__PURE__*/_jsx(VmCalendarInner, _objectSpread(_objectSpread({}, item), {}, {
          value: item.name
        }), index);
      }), /*#__PURE__*/_jsxs(Space, {
        children: [/*#__PURE__*/_jsx("div", {
          children: "\u5B8C\u6210\u7387\uFF1A"
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-road-calendar-complete-legend',
          style: {
            background: 'var(--gray-color)'
          }
        }), /*#__PURE__*/_jsx("div", {
          children: "0%"
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-road-calendar-complete-legend',
          style: {
            background: 'var(--red-color)'
          }
        }), /*#__PURE__*/_jsx("div", {
          children: "(0%-50%]"
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-road-calendar-complete-legend',
          style: {
            background: 'var(--yellow-color)'
          }
        }), /*#__PURE__*/_jsx("div", {
          children: "(50%-80%]"
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-road-calendar-complete-legend',
          style: {
            background: 'var(--blue-color)'
          }
        }), /*#__PURE__*/_jsx("div", {
          children: "(80%-100%]"
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-road-calendar-complete-legend',
          style: {
            background: 'var(--green-color)'
          }
        }), /*#__PURE__*/_jsx("div", {
          children: "100%"
        })]
      })]
    }), /*#__PURE__*/_jsx("div", {
      style: {
        flex: 1,
        minHeight: 0
      },
      children: /*#__PURE__*/_jsx(VmCalendar, {
        dateCellRender: dateCellRender,
        value: month
      })
    })]
  });
};
export default Calendar;