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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
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); }
import { Col } from 'antd';
import { keyBy } from 'lodash';
import { useContext } from 'react';
import { VmInfoCollection, VmMap, VmTitle, VmWrapper } from "../../../_components";
import VmFactorList from "../../../_components/vm-factor-list";
import useSettings from "../../../_hooks/useSettings";
import { Unmanned } from "../../content";
import darkRunIcon from "../../imgs/factor/dark_run.png";
import darkSpeedIcon from "../../imgs/factor/dark_speed.png";
import runIcon from "../../imgs/factor/run.png";
import speedIcon from "../../imgs/factor/speed.png";
import { CarContext } from "../../index";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Info = function Info(_ref) {
  var _info$geoLocation;
  var _ref$showQrCode = _ref.showQrCode,
    showQrCode = _ref$showQrCode === void 0 ? false : _ref$showQrCode,
    _ref$extraList = _ref.extraList,
    extraList = _ref$extraList === void 0 ? [] : _ref$extraList,
    _ref$showListImg = _ref.showListImg,
    showListImg = _ref$showListImg === void 0 ? true : _ref$showListImg;
  var _useContext = useContext(CarContext),
    info = _useContext.info,
    detail = _useContext.detail,
    showFields = _useContext.showFields,
    id = _useContext.id;
  var showFieldsMap = keyBy(showFields, 'dataKey') || {};
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var data = [{
    key: 'belongUnitName'
  }, {
    key: 'useUnitName'
  }, {
    key: 'bidSectionName'
  }, {
    key: 'divisionName'
  }, {
    key: 'manageStaffName'
  }, {
    key: 'contact'
  }, {
    key: 'contactWay'
  }, {
    key: 'invoiceCode'
  }, {
    key: 'certificateCode'
  }, {
    key: 'drivingLicenseCode'
  }].filter(function (item) {
    var _showFieldsMap$item$k;
    return (_showFieldsMap$item$k = showFieldsMap[item.key]) === null || _showFieldsMap$item$k === void 0 ? void 0 : _showFieldsMap$item$k.isVisible;
  }).map(function (item) {
    var _showFieldsMap$item$k2;
    return _objectSpread(_objectSpread({}, item), {}, {
      label: (_showFieldsMap$item$k2 = showFieldsMap[item.key]) === null || _showFieldsMap$item$k2 === void 0 ? void 0 : _showFieldsMap$item$k2.displayName,
      value: detail === null || detail === void 0 ? void 0 : detail[item.key]
    });
  });
  if (showQrCode) {
    data.push({
      label: '车辆二维码',
      key: 'qrCode',
      value: detail.qrCode,
      componentType: 'qrCode'
    });
  }
  var _ref2 = info !== null && info !== void 0 && (_info$geoLocation = info.geoLocation) !== null && _info$geoLocation !== void 0 && _info$geoLocation.lngLats ? info.geoLocation.lngLats.split(',') : [],
    _ref3 = _slicedToArray(_ref2, 2),
    lng = _ref3[0],
    lat = _ref3[1];
  var mapPoints = lng && lat ? [{
    lng: lng,
    lat: lat,
    icon: 'CAR',
    name: info.carCode,
    type: 'point',
    id: info.carCode
  }] : [];
  var list = [{
    name: '今日行驶',
    unit: 'km',
    value: (info === null || info === void 0 ? void 0 : info.accuMileage) || 0,
    img: showListImg ? isDark ? darkRunIcon : runIcon : null,
    fontType: 'blue'
  }, {
    name: '当前速度',
    unit: 'km/h',
    value: (info === null || info === void 0 ? void 0 : info.gpsSpeed) || 0,
    img: showListImg ? isDark ? darkSpeedIcon : speedIcon : null,
    fontType: 'blue'
  }].concat(_toConsumableArray(extraList));
  return /*#__PURE__*/_jsx(Col, {
    flex: '400px',
    style: {
      height: '100%'
    },
    children: /*#__PURE__*/_jsxs(VmWrapper, {
      title: '基本信息',
      children: [/*#__PURE__*/_jsx(VmInfoCollection, {
        width: '100%',
        data: data
      }), /*#__PURE__*/_jsx(VmTitle, {
        title: '实时信息',
        time: info === null || info === void 0 ? void 0 : info.equipmentTime
      }), (info === null || info === void 0 ? void 0 : info.driveMode) === 'unmanned' ? /*#__PURE__*/_jsx(Unmanned.Monitor, {
        carId: id
      }) : /*#__PURE__*/_jsx(VmFactorList, {
        list: list,
        style: {
          justifyContent: 'space-around'
        }
      }), /*#__PURE__*/_jsx("div", {
        className: 'vm-car-map-wrap',
        children: /*#__PURE__*/_jsx(VmMap, {
          mapPoints: mapPoints,
          mapType: 'wgs84',
          mapCenter: [lng, lat],
          address: info === null || info === void 0 ? void 0 : info.address
        })
      })]
    })
  });
};
export default Info;