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, Space, Spin } from 'antd';
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import { useMemo, useState } from 'react';
import { VmBarCharts, VmEmpty, VmProgress, VmTable, VmTag, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { LaneService } from "../../api";
import { buildIframeQuery } from "../../utils/url";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var getPercentInfo = function getPercentInfo(percent) {
  var colorList = ['#D9D9D9', '#D9D9D9'];
  var color = '#CCCCCC';
  var className = 'gray-text';
  if (percent >= 100) {
    colorList = ['#00B129', '#23EA51'];
    className = 'green-text';
    color = '#00EC47';
  } else if (percent > 80 && percent < 100) {
    colorList = ['#3A6DFF', '#00AEFF'];
    className = 'blue-text';
    color = '#09B9FF';
  } else if (percent > 50 && percent <= 80) {
    colorList = ['#FA8314', '#FAAD14'];
    className = 'orange-text';
    color = '#FFE100';
  } else if (percent > 0 && percent <= 50) {
    colorList = ['#FF3B3B', '#FF6464'];
    className = 'red-text';
    color = '#FF3E49';
  }
  return {
    colorList: colorList,
    className: className,
    color: color
  };
};
var Work = function Work(props) {
  var _workInfo$workInfo, _workInfo$workInfo2, _workInfo$workInfo3;
  var id = props.id,
    setIframeModalInfo = props.setIframeModalInfo,
    workTypeColorMap = props.workTypeColorMap,
    jcssInfo = props.jcssInfo;
  var _useSettings = useSettings(),
    date = _useSettings.date,
    theme = _useSettings.theme,
    isDark = _useSettings.isDark;
  var _useState = useState(date ? dayjs(date) : dayjs()),
    _useState2 = _slicedToArray(_useState, 2),
    day = _useState2[0],
    setDay = _useState2[1];
  var _useSetState = useSetState({
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var pagination = state.pagination;
  var _LaneService$useTaskL = LaneService.useTaskList(id, dayjs(day).format('YYYY-MM-DD'), pagination.current, jcssInfo.originTypeName === jcssInfo.typeName),
    taskPage = _LaneService$useTaskL.taskPage,
    taskLoading = _LaneService$useTaskL.loading;
  var _LaneService$useWorkI = LaneService.useWorkInfo(id, dayjs(day).format('YYYY-MM-DD')),
    workInfo = _LaneService$useWorkI.workInfo,
    loading = _LaneService$useWorkI.loading;
  var colorMap = {
    blue: '#1677FF',
    green: '#0FB964',
    yellow: '#FFAA00',
    purple: '#B894F9',
    orange: '#FF8746'
  };
  if (isDark) {
    colorMap.blue = '#009DFF';
  }
  var records = {
    total: (taskPage === null || taskPage === void 0 ? void 0 : taskPage.total) || 0,
    rows: (taskPage === null || taskPage === void 0 ? void 0 : taskPage.rows) || []
  };
  var pageChange = function pageChange(page) {
    setState({
      pagination: _objectSpread(_objectSpread({}, pagination), {}, {
        current: page
      })
    });
  };
  var columns = [{
    title: '车牌号',
    dataIndex: 'workCarCode',
    key: 'workCarCode',
    ellipsis: true,
    width: 90,
    fixed: 'left'
  }, {
    title: '车辆类型',
    dataIndex: 'carClassesName',
    key: 'carClassesName',
    width: 80,
    ellipsis: true
  }, {
    title: '车道类型',
    dataIndex: 'facilityTypeName',
    key: 'facilityTypeName',
    width: 100,
    ellipsis: true
  }, {
    title: '作业司机',
    dataIndex: 'driverName',
    key: 'driverName',
    width: 100,
    ellipsis: true
  }, {
    title: '作业时段',
    dataIndex: 'startTime',
    key: 'startTime',
    width: 120,
    ellipsis: true,
    render: function render(text, record) {
      return "".concat(text.slice(0, 5), " ~ ").concat(record.endTime.slice(0, 5));
    }
  }, {
    title: '作业类型',
    dataIndex: 'workTypeName',
    key: 'workTypeName',
    width: 80,
    ellipsis: true,
    render: function render(text) {
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: workTypeColorMap[text]
      });
    }
  }, {
    title: '作业趟数',
    dataIndex: 'workCount',
    key: 'workCount',
    width: 90,
    ellipsis: true,
    align: 'right'
  }, {
    title: '作业里程（km）',
    dataIndex: 'workMileage',
    key: 'workMileage',
    width: 130,
    ellipsis: true,
    align: 'right'
  }, {
    title: '完成率',
    dataIndex: 'completeRate',
    key: 'completeRate',
    width: 90,
    ellipsis: true,
    align: 'right',
    render: function render(text) {
      return "".concat(text, "%");
    }
  }, {
    title: '作业质量',
    dataIndex: 'workQuality',
    key: 'workQuality',
    width: 90,
    ellipsis: true,
    render: function render(text) {
      var colorMap = {
        优: '--green-color',
        良: '--yellow-color',
        差: '--red-color'
      };
      var imgMap = {
        优: require("../../imgs/\u4F18.png"),
        良: require("../../imgs/\u826F.png"),
        差: require("../../imgs/\u5DEE.png")
      };
      return text ? /*#__PURE__*/_jsxs(Row, {
        align: 'middle',
        children: [/*#__PURE__*/_jsx("img", {
          src: imgMap[text],
          alt: "",
          width: 16,
          height: 16,
          style: {
            marginRight: 4
          }
        }), /*#__PURE__*/_jsx("span", {
          style: {
            color: "var(".concat(colorMap[text], ")")
          },
          children: text
        })]
      }) : '-';
    }
  }, {
    title: '操作',
    dataIndex: 'track',
    key: 'track',
    width: 100,
    fixed: 'right',
    render: function render(_text, record) {
      return /*#__PURE__*/_jsx("a", {
        onClick: function onClick() {
          var prefix = '';
          var prefixList = location.pathname.split('/').filter(function (item) {
            return item;
          });
          if (prefixList.length === 2) {
            prefix = "/".concat(prefixList[0]);
          }
          var query = buildIframeQuery(location.href.split('?')[1], {
            carId: record.workCarId,
            theme: theme === 'blue' ? 'dark' : theme,
            startTime: dayjs(date).format('YYYY-MM-DD 00:00:00'),
            endTime: dayjs(date).format('YYYY-MM-DD 23:59:59')
          });
          var src = "".concat(prefix, "/carHistory/#/zyqsLaneHistory?").concat(query);
          setIframeModalInfo({
            title: '车辆轨迹',
            visible: true,
            src: src
          });
        },
        children: "\u67E5\u770B\u8F68\u8FF9"
      });
    }
  }];
  var tableProps = {
    pagination: _objectSpread(_objectSpread({}, pagination), {}, {
      total: records.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    columns: columns,
    indexFixed: true,
    rowKey: 'id',
    dataSource: records.rows,
    loading: taskLoading
  };
  var _useMemo = useMemo(function () {
      var planMileageList = [];
      var workMileageList = [];
      var xAxis = [];
      var completeRateList = [];
      (workInfo.workTypeSummary || []).forEach(function (item) {
        var name = item.name,
          workInfo = item.workInfo;
        var _ref = workInfo || {},
          planMileage = _ref.planMileage,
          workMileage = _ref.workMileage,
          completeRate = _ref.completeRate;
        xAxis.push(name);
        planMileageList.push(planMileage);
        workMileageList.push(workMileage);
        completeRateList.push({
          name: name,
          completeRate: completeRate
        });
      });
      return {
        dataList: [{
          name: '排班里程',
          data: planMileageList,
          color: 'geekblue'
        }, {
          name: '作业里程',
          data: workMileageList,
          color: 'green'
        }],
        xAxis: xAxis,
        completeRateList: completeRateList
      };
    }, [JSON.stringify(workInfo.workTypeSummary)]),
    dataList = _useMemo.dataList,
    xAxis = _useMemo.xAxis,
    completeRateList = _useMemo.completeRateList;
  var mileageList = [{
    name: '排班里程',
    value: workInfo === null || workInfo === void 0 || (_workInfo$workInfo = workInfo.workInfo) === null || _workInfo$workInfo === void 0 ? void 0 : _workInfo$workInfo.planMileage,
    icon: require("../../imgs/schedule.png")
  }, {
    name: '作业里程',
    value: workInfo === null || workInfo === void 0 || (_workInfo$workInfo2 = workInfo.workInfo) === null || _workInfo$workInfo2 === void 0 ? void 0 : _workInfo$workInfo2.workMileage,
    icon: require("../../imgs/work.png")
  }];
  return /*#__PURE__*/_jsxs("div", {
    className: 'vtx-road-info-right-wrap',
    children: [/*#__PURE__*/_jsx("div", {
      className: 'vtx-car-info-right-wrap-top',
      children: /*#__PURE__*/_jsx(VmWrapper, {
        filterType: "datePicker",
        dateValue: day,
        title: "\u4F5C\u4E1A\u6C47\u603B",
        filterChange: setDay,
        disabledDate: function disabledDate(current) {
          return current && current > dayjs().endOf('day');
        },
        children: loading ? /*#__PURE__*/_jsx(Row, {
          align: 'middle',
          justify: 'center',
          children: /*#__PURE__*/_jsx(Spin, {})
        }) : isEmpty(workInfo === null || workInfo === void 0 ? void 0 : workInfo.workInfo) && isEmpty(workInfo === null || workInfo === void 0 ? void 0 : workInfo.workTypeSummary) ? /*#__PURE__*/_jsx("div", {
          style: {
            height: 200
          },
          children: /*#__PURE__*/_jsx(VmEmpty, {
            imgStyle: {
              marginLeft: 0,
              transform: 'translateX(0%)'
            }
          })
        }) : /*#__PURE__*/_jsxs(Row, {
          gutter: [16, 16],
          children: [/*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsxs(Row, {
              align: 'middle',
              justify: 'flex-start',
              style: {
                marginLeft: 40
              },
              children: [/*#__PURE__*/_jsxs(Space, {
                size: 40,
                align: "center",
                children: [/*#__PURE__*/_jsx(VmProgress.Circle, {
                  rate: workInfo === null || workInfo === void 0 || (_workInfo$workInfo3 = workInfo.workInfo) === null || _workInfo$workInfo3 === void 0 ? void 0 : _workInfo$workInfo3.completeRate,
                  name: '完成率',
                  width: 80
                }), mileageList.map(function (item) {
                  return /*#__PURE__*/_jsxs("div", {
                    className: 'vtx-road-lane-mileage-item',
                    children: [/*#__PURE__*/_jsxs("div", {
                      children: [/*#__PURE__*/_jsx("span", {
                        className: 'vtx-road-lane-mileage-item-value',
                        children: item.value
                      }), /*#__PURE__*/_jsx("span", {
                        className: 'vtx-road-lane-mileage-item-unit',
                        children: "km"
                      })]
                    }), /*#__PURE__*/_jsxs(Row, {
                      align: "middle",
                      children: [/*#__PURE__*/_jsx("img", {
                        src: item.icon,
                        className: 'vtx-road-lane-mileage-item-img'
                      }), /*#__PURE__*/_jsx("span", {
                        children: item.name
                      })]
                    })]
                  }, item.name);
                })]
              }), completeRateList.map(function (item) {
                var _getPercentInfo = getPercentInfo(item.completeRate),
                  className = _getPercentInfo.className,
                  colorList = _getPercentInfo.colorList;
                return /*#__PURE__*/_jsxs("div", {
                  className: 'vtx-road-work-type-item',
                  children: [/*#__PURE__*/_jsx("div", {
                    children: item.name
                  }), /*#__PURE__*/_jsx("div", {
                    style: {
                      width: 200
                    },
                    children: /*#__PURE__*/_jsx(VmProgress.Line, {
                      width: '100%',
                      rate: item.completeRate,
                      name: item.name,
                      strokeColor: {
                        '0%': colorList[0],
                        '100%': colorList[1]
                      }
                    })
                  }), /*#__PURE__*/_jsxs("div", {
                    children: [/*#__PURE__*/_jsx("span", {
                      className: "vtx-road-work-type-item-value vtx-road-work-type-item-".concat(className),
                      children: item.completeRate
                    }), /*#__PURE__*/_jsx("span", {
                      className: "vtx-road-work-type-item-unit vtx-road-work-type-item-".concat(className),
                      children: "%"
                    })]
                  })]
                }, item.name);
              })]
            })
          }), /*#__PURE__*/_jsx(Col, {
            span: 12,
            children: !loading && isEmpty(workInfo === null || workInfo === void 0 ? void 0 : workInfo.workTypeSummary) ? /*#__PURE__*/_jsx("div", {
              style: {
                height: 200
              },
              children: /*#__PURE__*/_jsx(VmEmpty, {
                imgStyle: {
                  marginLeft: 0,
                  transform: 'translateX(0%)'
                }
              })
            }) : /*#__PURE__*/_jsx(VmBarCharts, {
              height: 216,
              loading: loading,
              dataList: dataList,
              xAxis: xAxis,
              unit: "km",
              yAxisList: [{
                key: '',
                unit: 'km',
                name: '(km)'
              }]
            })
          })]
        })
      })
    }), /*#__PURE__*/_jsx("div", {
      style: {
        flex: 1,
        minHeight: 0
      },
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: "\u4F5C\u4E1A\u660E\u7EC6",
        children: /*#__PURE__*/_jsx("div", {
          style: {
            width: '100%',
            height: '100%'
          },
          children: /*#__PURE__*/_jsx(VmTable, _objectSpread({}, tableProps))
        })
      })
    })]
  });
};
export default Work;