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 dayjs from 'dayjs';
import { VmEmpty, VmFactor, VmLineCharts, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { AttendanceService } from "../../api";
import { sum } from 'lodash';
import levelTime from "../../imgs/time_level.png";
import levelTimeDark from "../../imgs/time_level_dark.png";
import overTime from "../../imgs/time_over.png";
import overTimeDark from "../../imgs/time_over_dark.png";
import sumTime from "../../imgs/time_sum.png";
import sumTimeDark from "../../imgs/time_sum_dark.png";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function WorkingHours(props) {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var id = props.id,
    service = props.service;
  var _useSetState = useSetState({
      startDate: dayjs().startOf('M'),
      endDate: dayjs()
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate;
  var _AttendanceService$us = AttendanceService.useTimeAnalysis(id, startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD'), service),
    attendTimeAnalysisRes = _AttendanceService$us.attendTimeAnalysisRes;
  var names = attendTimeAnalysisRes.names,
    values = attendTimeAnalysisRes.values;
  var handleDateChange = function handleDateChange(dates) {
    setState({
      startDate: dates[0],
      endDate: dates[1]
    });
  };
  var val1 = (values === null || values === void 0 ? void 0 : values.length) > 1 ? values[1] : 0;
  var val2 = (values === null || values === void 0 ? void 0 : values.length) > 2 ? values[2] : 0;
  var val3 = (values === null || values === void 0 ? void 0 : values.length) > 3 ? values[3] : 0;
  return /*#__PURE__*/_jsx("div", {
    className: "staff-attend-workhours",
    children: /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u5DE5\u65F6\u7EDF\u8BA1",
      dateValue: [dayjs(startDate), dayjs(endDate)],
      filterType: "rangePicker",
      filterChange: function filterChange(dates) {
        return dates && handleDateChange(dates);
      },
      children: (names === null || names === void 0 ? void 0 : names.length) > 0 ? /*#__PURE__*/_jsxs("div", {
        className: "staff-attend-workhours-wrap",
        children: [/*#__PURE__*/_jsx("div", {
          className: "staff-attend-workhours-left",
          children: [{
            value: sum(val1),
            img: sumTime,
            imgDark: sumTimeDark,
            name: '总工时',
            fontType: 'blue'
          }, {
            value: sum(val2),
            img: levelTime,
            imgDark: levelTimeDark,
            name: '请假时长',
            fontType: 'cyan'
          }, {
            value: sum(val3),
            img: overTime,
            imgDark: overTimeDark,
            name: '加班时长',
            fontType: 'green'
          }].map(function (ele, index) {
            var _ele$value;
            return /*#__PURE__*/_jsx(VmFactor, _objectSpread(_objectSpread({
              type: "sm"
            }, ele), {}, {
              value: (_ele$value = ele.value) === null || _ele$value === void 0 ? void 0 : _ele$value.toFixed(2),
              unit: 'h',
              img: ele["img".concat(isDark ? 'Dark' : '')]
            }), index);
          })
        }), /*#__PURE__*/_jsx("div", {
          className: "staff-attend-workhours-right",
          children: /*#__PURE__*/_jsx(VmLineCharts, {
            unit: "\u5C0F\u65F6",
            height: 200,
            xAxis: names || [],
            gridOption: {
              top: 32
            },
            dataList: [{
              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: '#FFAA00',
                  fontWeight: 'normal'
                }
              }
            }]
          })
        })]
      }) : /*#__PURE__*/_jsx(VmEmpty, {
        type: "NO_CAHRT"
      })
    })
  }, id);
}