"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _antd = require("antd");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmSubTabs = _interopRequireWildcard(require("../../../vm-sub-tabs"));
var _vmInfoCollection = _interopRequireDefault(require("../../../vm-info-collection"));
var _TodayWork = _interopRequireDefault(require("./TodayWork"));
var _WorkStatic = _interopRequireDefault(require("./WorkStatic"));
var _Lcfx = _interopRequireDefault(require("./Lcfx"));
var _api = require("../../api");
require("./index.less");
var _refresh = _interopRequireDefault(require("../../imgs/refresh.png"));
var _position = _interopRequireDefault(require("../../imgs/position.png"));
var _todayWork = _interopRequireDefault(require("../../imgs/todayWork.png"));
var _todayOnline = _interopRequireDefault(require("../../imgs/todayOnline.png"));
var _refresh_light = _interopRequireDefault(require("../../../vtx-car-modal/imgs/refresh_light.png"));
var _position_light = _interopRequireDefault(require("../../../vtx-car-modal/imgs/position_light.png"));
var _todayWork_light = _interopRequireDefault(require("../../imgs/todayWork_light.png"));
var _todayOnline_light = _interopRequireDefault(require("../../imgs/todayOnline_light.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
var MAX_CONTENT_HEIGHT = document.body.clientHeight - 60 - 30;
var BaseInfo = function BaseInfo(props) {
  var _a;
  var id = props.id,
    employmentTypeCode = props.employmentTypeCode;
  var contentRef = (0, _react.useRef)(null);
  var _useSettings = (0, _useSettings2["default"])(),
    theme = _useSettings.theme,
    isDark = _useSettings.isDark;
  var _useSetState = (0, _ahooks.useSetState)({
      baseActiveKey: '1',
      activeKey: '1',
      contentStyle: {}
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var baseActiveKey = state.baseActiveKey,
    activeKey = state.activeKey,
    contentStyle = state.contentStyle;
  var _BaseService$useBaseI = _api.BaseService.useBaseInfo(id),
    baseInfo = _BaseService$useBaseI.baseInfo,
    info = _BaseService$useBaseI.info;
  var _BaseService$useWorkI = _api.BaseService.useWorkInfo(id, (0, _moment["default"])().format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')),
    workInfoRes = _BaseService$useWorkI.workInfoRes;
  // 今日作业，接口无数据代表无排班
  var _BaseService$useToday = _api.BaseService.useTodayWork(id, (0, _moment["default"])().format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')),
    todayWorkRes = _BaseService$useToday.todayWorkRes;
  var rigthTabs = [{
    name: "\u4F5C\u4E1A\u7EDF\u8BA1\uFF08".concat((0, _moment["default"])().startOf('M').format('MM-DD'), "~").concat((0, _moment["default"])().format('MM-DD'), "\uFF09"),
    key: '2',
    content: /*#__PURE__*/_react["default"].createElement(_WorkStatic["default"], {
      id: id
    })
  }];
  if ((todayWorkRes === null || todayWorkRes === void 0 ? void 0 : todayWorkRes.length) > 0) {
    rigthTabs.unshift({
      name: '今日作业',
      key: '1',
      content: /*#__PURE__*/_react["default"].createElement(_TodayWork["default"], {
        todayWorkRes: todayWorkRes
      })
    });
  }
  (0, _react.useEffect)(function () {
    if ((todayWorkRes === null || todayWorkRes === void 0 ? void 0 : todayWorkRes.length) > 0) {
      setState({
        activeKey: '1'
      });
    } else {
      setState({
        activeKey: '2'
      });
    }
  }, [JSON.stringify(todayWorkRes)]);
  (0, _react.useEffect)(function () {
    var _a;
    var contentHeight = ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0;
    if (contentHeight >= MAX_CONTENT_HEIGHT) {
      setState({
        contentStyle: {
          maxHeight: MAX_CONTENT_HEIGHT,
          overflowY: 'auto'
        }
      });
    } else {
      setState({
        contentStyle: {}
      });
    }
  }, [contentRef === null || contentRef === void 0 ? void 0 : contentRef.current]);
  var gifType = function gifType() {
    if (employmentTypeCode === null || employmentTypeCode === void 0 ? void 0 : employmentTypeCode.startsWith('zhzf')) {
      return '-zhzf';
    }
    if (employmentTypeCode === null || employmentTypeCode === void 0 ? void 0 : employmentTypeCode.startsWith('yl')) {
      return '-yl';
    }
    return '';
  };
  var baseTabContent = /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: baseInfo,
    gap: 8,
    isValueCenter: true
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base ".concat(theme)
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left",
    ref: contentRef,
    style: contentStyle
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--text"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: isDark ? _refresh["default"] : _refresh_light["default"]
  }), (info === null || info === void 0 ? void 0 : info.updateTime) || '--'), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--text"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: isDark ? _position["default"] : _position_light["default"]
  }), (info === null || info === void 0 ? void 0 : info.address) || '--'), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--online"
  }, (info === null || info === void 0 ? void 0 : info.statusName) || '--'), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--gif staff-base-left--gif".concat(gifType())
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: isDark ? _todayWork["default"] : _todayWork_light["default"]
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item-name"
  }, "\u4ECA\u65E5\u884C\u8D70"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item-value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, ((_a = workInfoRes === null || workInfoRes === void 0 ? void 0 : workInfoRes.totalMileage) === null || _a === void 0 ? void 0 : _a.toFixed(2)) || 0), "km")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: isDark ? _todayOnline["default"] : _todayOnline_light["default"]
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item-name"
  }, "\u4ECA\u65E5\u5728\u7EBF"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-left--pngs-item-value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, (workInfoRes === null || workInfoRes === void 0 ? void 0 : workInfoRes.onlineTimeStr) || '--'))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-right",
    style: contentStyle
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [10, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 10,
    xl: 10,
    lg: 24,
    md: 24
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-right-base"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs["default"], {
    onChange: function onChange(key) {
      setState({
        baseActiveKey: key
      });
    },
    activeKey: baseActiveKey
  }, [{
    name: '基本信息',
    key: '1',
    content: baseTabContent
  }].map(function (ele) {
    return /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
      subKey: ele.key,
      key: ele.key,
      tab: ele.name
    }, ele.content);
  })))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 14,
    xl: 14,
    lg: 24,
    md: 24
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-base-right-right"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs["default"], {
    onChange: function onChange(key) {
      setState({
        activeKey: key
      });
    },
    activeKey: activeKey
  }, rigthTabs.map(function (ele) {
    return /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
      key: ele.key,
      subKey: ele.key,
      tab: ele.name
    }, ele.content);
  })))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 24
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-wgfx"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u91CC\u7A0B\u5206\u6790"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "staff-wgfx-content"
  }, /*#__PURE__*/_react["default"].createElement(_Lcfx["default"], {
    id: id
  })))))));
};
var _default = exports["default"] = BaseInfo;
//# sourceMappingURL=index.js.map
