"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 _index = require("../../index");
var _api = require("../../api");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _moment = _interopRequireDefault(require("moment"));
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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 _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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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; }
var Charts = function Charts(_ref) {
  var times = _ref.times;
  var _useContext = (0, _react.useContext)(_index.RestaurantContext),
    id = _useContext.id,
    garbageType = _useContext.garbageType;
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor;
  var day = (0, _moment["default"])(times[1]).diff(times[0], 'day');
  var dayList = [];
  for (var index = 0; index <= day; index++) {
    dayList.push((0, _moment["default"])(times[0]).add(index, 'day').format('MM-DD'));
  }
  var rows = _api.BasicService.detailList({
    id: id,
    startTime: times[0].format('YYYY-MM-DD 00:00:00'),
    endTime: times[1].format('YYYY-MM-DD 23:59:59'),
    garbageType: garbageType
  });
  var periodList = _api.BasicService.getPeriodList({
    restaurantId: id,
    startDay: times[0].format('YYYY-MM-DD'),
    endDay: times[1].format('YYYY-MM-DD')
  });
  var today = (0, _moment["default"])().format('YYYY-MM-DD');
  var lineOption = {
    color: chartColor,
    tooltip: {
      trigger: 'item',
      formatter: function formatter(val) {
        return val.value[3] + ': ' + val.value[2] + 'kg';
      }
    },
    legend: {
      top: '5%'
    },
    grid: {
      // top: 58,
      left: 24,
      bottom: 12,
      right: 40,
      containLabel: true
    },
    xAxis: {
      name: '日期',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLine: {
        show: true
      },
      axisLabel: {
        color: chartFontColor,
        formatter: function formatter(val) {
          return (0, _moment["default"])(val).format('MM-DD');
        }
      },
      data: dayList
    },
    yAxis: [{
      name: '时间',
      min: new Date((0, _moment["default"])().startOf('date').valueOf()),
      max: new Date((0, _moment["default"])().endOf('date').valueOf()),
      type: 'time',
      nameTextStyle: {
        color: chartFontColor
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: chartFontColor,
        formatter: function formatter(val) {
          return (0, _moment["default"])(val).format('HH:mm');
        }
      },
      axisLine: {
        show: true
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: [{
      type: 'scatter',
      data: rows === null || rows === void 0 ? void 0 : rows.map(function (item) {
        return [(0, _moment["default"])(item.weighTime).format('MM-DD'), (0, _moment["default"])(item.weighTime).format("".concat(today, " HH:mm:ss")), item.netWeight, item.weighTime];
      }),
      symbolSize: 20
    }].concat(_toConsumableArray(periodList.map(function (item) {
      return {
        name: item.name,
        data: [],
        markArea: {
          data: [[{
            yAxis: (0, _moment["default"])(item.startTime, 'HH:mm:ss').format("".concat(today, " HH:mm:ss"))
          }, {
            yAxis: (0, _moment["default"])(item.endTime, 'HH:mm:ss').format("".concat(today, " HH:mm:ss"))
          }]],
          tooltip: {
            show: true,
            formatter: function formatter() {
              return item.name;
            }
          }
        },
        type: 'bar',
        tooltip: {
          show: false
        }
      };
    })))
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      background: '#fff',
      height: 400
    }
  }, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: lineOption,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '100%',
      width: '100%'
    }
  }));
};
var _default = exports["default"] = Charts;
//# sourceMappingURL=Charts.js.map
