"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = WorkingHours;
var _react = _interopRequireDefault(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
 * 工时统计
 */

function WorkingHours(props) {
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor,
    theme = _useSettings.theme;
  var id = props.id,
    startDate = props.startDate,
    endDate = props.endDate;
  var _AttendanceService$us = _api.AttendanceService.useTimeAnalysis(id, startDate, endDate),
    attendTimeAnalysisRes = _AttendanceService$us.attendTimeAnalysisRes;
  var names = attendTimeAnalysisRes.names,
    values = attendTimeAnalysisRes.values;
  var option = {
    color: chartColor,
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        // params 是一个数组，包含了触发 tooltip 的所有数据点信息
        var res = params[0].name + '<br/>'; // 添加数据点的名称
        params.forEach(function (item) {
          res += item.seriesName + ' : ';
          res += item.value + ' 小时'; // 在这里添加单位
          res += '<br/>';
        });
        return res;
      }
    },
    legend: {
      show: true,
      itemWith: 6,
      itemHeight: 6,
      top: 20,
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 12
      }
    },
    grid: {
      left: 24,
      bottom: 12,
      right: 40,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: names || []
    },
    yAxis: [{
      name: '小时',
      type: 'value',
      nameTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisLine: {
        show: true
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: [{
      name: '每日工时',
      type: 'line',
      data: (values === null || values === void 0 ? void 0 : values.length) > 1 ? values[1] : [],
      markLine: {
        data: [{
          type: 'average',
          name: '平均工时'
        }],
        label: {
          show: true,
          position: 'insideEndTop',
          formatter: '{b}: {c}',
          color: theme === 'blue' ? '#fff' : chartFontColor,
          fontWeight: 'normal'
        },
        lineStyle: {
          color: '#76F8FA'
        }
      }
    }, {
      name: '请假时长',
      type: 'line',
      data: (values === null || values === void 0 ? void 0 : values.length) > 2 ? values[2] : []
    }, {
      name: '加班时长',
      type: 'line',
      data: (values === null || values === void 0 ? void 0 : values.length) > 3 ? values[3] : []
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    key: id,
    className: "staff-attend-workhours"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5DE5\u65F6\u7EDF\u8BA1"
  }), (names === null || names === void 0 ? void 0 : names.length) > 0 ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '220px',
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], null)));
}
//# sourceMappingURL=WorkingHours.js.map
