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, Spin, Tooltip } from 'antd';
import classnames from 'classnames';
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import { useState } from 'react';
import { VmEmpty, VmProgress, VmTable, VmTag, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService } from "../../api";
import { buildIframeQuery } from "../../utils/url";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Work = function Work(props) {
  var id = props.id,
    setIframeModalInfo = props.setIframeModalInfo,
    workTypeColorMap = props.workTypeColorMap;
  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 _BaseService$useRecor = BaseService.useRecordService(id, dayjs(day).format('YYYY-MM-DD')),
    dataSource = _BaseService$useRecor.carWorkRecord;
  var _BaseService$useWorkO = BaseService.useWorkOverview(id, dayjs(day).format('YYYY-MM-DD')),
    workInfo = _BaseService$useWorkO.workInfo,
    loading = _BaseService$useWorkO.loading;
  var colorMap = {
    blue: '#1677FF',
    green: '#0FB964',
    yellow: '#FFAA00',
    purple: '#B894F9',
    orange: '#FF8746'
  };
  if (isDark) {
    colorMap.blue = '#009DFF';
  }
  var allWorkInfo = workInfo.find(function (item) {
    return item.workType === 'ALL';
  }) || {};
  var newWorkInfo = workInfo.filter(function (item) {
    return item.workType !== 'ALL';
  });
  var columns = [{
    title: '车牌号',
    dataIndex: 'carCode',
    key: 'carCode',
    ellipsis: true,
    width: 90,
    fixed: 'left',
    onCell: function onCell(record) {
      return {
        rowSpan: record.rowSpan || 0
      };
    }
  }, {
    title: '作业类型',
    dataIndex: 'workTypeName',
    key: 'workTypeName',
    width: 80,
    ellipsis: true,
    render: function render(text) {
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: workTypeColorMap[text]
      });
    }
  }, {
    title: '作业时段',
    dataIndex: 'ruleStartTime',
    key: 'ruleStartTime',
    width: 140,
    ellipsis: true,
    render: function render(text, record) {
      return text ? "".concat(dayjs(text).format('HH:mm:ss'), "~").concat(dayjs(record.ruleEndTime).format('HH:mm:ss')) : '-';
    }
  }, {
    title: '作业趟数',
    dataIndex: 'workCount',
    key: 'workCount',
    width: 80,
    align: 'right'
  }, {
    title: '作业里程(km)',
    dataIndex: 'realWorkMileage',
    key: 'realWorkMileage',
    width: 110,
    align: 'right'
  }, {
    title: /*#__PURE__*/_jsxs(Space, {
      children: ["\u6838\u7B97\u4F5C\u4E1A\u91CC\u7A0B(km)", /*#__PURE__*/_jsx(Tooltip, {
        title: "\u6838\u7B97\u4F5C\u4E1A\u91CC\u7A0B\uFF1A\u6839\u636E\u4F5C\u4E1A\u8DEF\u6BB5\u957F\u5EA6\u548C\u4F5C\u4E1A\u89C4\u5219\uFF0C\u540C\u4E00\u8DEF\u6BB5\u540C\u4E00\u65F6\u6BB5\u7684\u4F5C\u4E1A\u7C7B\u578B\u4E0B\uFF0C\u4E0D\u53EF\u8D85\u8FC7\u8BA1\u5212\u4F5C\u4E1A\u91CC\u7A0B\u3002",
        children: /*#__PURE__*/_jsx(QuestionCircleOutlined, {})
      })]
    }),
    dataIndex: 'workMileage',
    key: 'workMileage',
    width: 160,
    align: 'right'
  }, {
    title: '操作',
    dataIndex: 'track',
    key: 'track',
    width: 80,
    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.carId,
            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'),
            roadId: record.roadId
          });
          var src = "".concat(prefix, "/carHistory/#/zyqsHistory?").concat(query);
          setIframeModalInfo({
            title: '车辆轨迹',
            visible: true,
            src: src
          });
        },
        children: "\u67E5\u770B\u8F68\u8FF9"
      });
    }
  }];
  var tableProps = {
    pagination: {
      defaultCurrent: 1,
      total: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) || 0
    },
    columns: columns,
    indexFixed: true,
    isIndex: false,
    rowKey: 'index',
    dataSource: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) > 0 ? dataSource.map(function (ele, index) {
      return _objectSpread(_objectSpread({}, ele), {}, {
        index: index
      });
    }) : []
  };
  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) ? /*#__PURE__*/_jsx("div", {
          style: {
            height: 200
          },
          children: /*#__PURE__*/_jsx(VmEmpty, {
            imgStyle: {
              marginLeft: 0,
              transform: 'translateX(0%)'
            }
          })
        }) : /*#__PURE__*/_jsxs("div", {
          className: "vtx-road-work-wrap",
          children: [/*#__PURE__*/_jsxs("div", {
            className: "road-work-left",
            children: [/*#__PURE__*/_jsx("div", {
              className: "all-rate-wrap",
              children: /*#__PURE__*/_jsx(VmProgress.Circle, {
                rate: allWorkInfo.rate,
                name: '完成率'
              })
            }), /*#__PURE__*/_jsxs("div", {
              children: [/*#__PURE__*/_jsxs("div", {
                className: "left-info",
                children: [/*#__PURE__*/_jsx("img", {
                  src: isDark ? require("../../imgs/dark_real.png") : require("../../imgs/real.png"),
                  width: 24,
                  height: 24
                }), /*#__PURE__*/_jsxs("div", {
                  children: [/*#__PURE__*/_jsx("span", {
                    className: "left-info-label",
                    children: "\u8BA1\u5212/\u6838\u7B97\u91CC\u7A0B\uFF1A"
                  }), /*#__PURE__*/_jsxs("span", {
                    className: classnames('left-info-value', {
                      dark: isDark
                    }),
                    children: [allWorkInfo.planMileage, "/", allWorkInfo.workMileage]
                  }), /*#__PURE__*/_jsx("span", {
                    className: classnames('left-info-unit', {
                      dark: isDark
                    }),
                    children: "\u516C\u91CC"
                  })]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "left-info",
                children: [/*#__PURE__*/_jsx("img", {
                  src: isDark ? require("../../imgs/dark_valid.png") : require("../../imgs/valid.png"),
                  width: 24,
                  height: 24
                }), /*#__PURE__*/_jsxs("div", {
                  children: [/*#__PURE__*/_jsx("span", {
                    className: "left-info-label",
                    children: "\u8BA1\u5212/\u6709\u6548\u8D9F\u6B21\uFF1A"
                  }), /*#__PURE__*/_jsxs("span", {
                    className: classnames('left-info-value', {
                      dark: isDark
                    }),
                    children: [allWorkInfo.planCount, "/", allWorkInfo.workCount]
                  }), /*#__PURE__*/_jsx("span", {
                    className: classnames('left-info-unit', {
                      dark: isDark
                    }),
                    children: "\u8D9F"
                  })]
                })]
              })]
            })]
          }), /*#__PURE__*/_jsx("div", {
            className: "road-work-right",
            children: newWorkInfo.map(function (item) {
              return /*#__PURE__*/_jsxs("div", {
                className: "road-work-right-item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-work-right-item-left",
                  children: [/*#__PURE__*/_jsxs("div", {
                    className: "road-work-right-item-left-info",
                    children: [/*#__PURE__*/_jsx("span", {
                      className: "work-type",
                      children: item.workTypeStr
                    }), /*#__PURE__*/_jsxs("span", {
                      className: "work-rate",
                      children: [/*#__PURE__*/_jsx("span", {
                        className: classnames('work-rate-value', workTypeColorMap[item.workTypeStr], {
                          dark: isDark
                        }),
                        children: item.rate
                      }), /*#__PURE__*/_jsx("span", {
                        className: classnames('work-rate-unit', workTypeColorMap[item.workTypeStr], {
                          dark: isDark
                        }),
                        children: "%"
                      })]
                    })]
                  }), /*#__PURE__*/_jsx(VmProgress.Line, {
                    rate: item.rate,
                    width: '100%',
                    strokeColor: colorMap[workTypeColorMap[item.workTypeStr]]
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  children: [/*#__PURE__*/_jsx("div", {
                    className: 'left-info',
                    children: /*#__PURE__*/_jsxs("div", {
                      children: [/*#__PURE__*/_jsx("span", {
                        className: "left-info-label",
                        children: "\u8BA1\u5212/\u6838\u7B97\u91CC\u7A0B\uFF1A"
                      }), /*#__PURE__*/_jsxs("span", {
                        className: classnames('left-info-value', {
                          dark: isDark
                        }),
                        children: [item.planMileage, "/", item.workMileage]
                      }), /*#__PURE__*/_jsx("span", {
                        className: classnames('left-info-unit', {
                          dark: isDark
                        }),
                        children: "\u516C\u91CC"
                      })]
                    })
                  }), /*#__PURE__*/_jsx("div", {
                    className: 'left-info',
                    children: /*#__PURE__*/_jsxs("div", {
                      children: [/*#__PURE__*/_jsx("span", {
                        className: "left-info-label",
                        children: "\u8BA1\u5212/\u6709\u6548\u8D9F\u6B21\uFF1A"
                      }), /*#__PURE__*/_jsxs("span", {
                        className: classnames('left-info-value', {
                          dark: isDark
                        }),
                        children: [item.planCount, "/", item.workCount]
                      }), /*#__PURE__*/_jsx("span", {
                        className: classnames('left-info-unit', {
                          dark: isDark
                        }),
                        children: "\u8D9F"
                      })]
                    })
                  })]
                })]
              }, item.workType);
            })
          })]
        })
      })
    }), /*#__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;