"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"] = Jcqsfx;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _lodash = require("lodash");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _moment = _interopRequireDefault(require("moment"));
var _vmSubTitle = require("../../../vm-sub-title");
var _vmFilter = require("../../../vm-filter");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
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; }
function Jcqsfx(props) {
  var _a;
  var _useSettings = (0, _useSettings2["default"])(),
    chartFontColor = _useSettings.chartFontColor,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate,
    theme = _useSettings.theme;
  var code = props.code,
    setDate = props.setDate;
  var _useSetState = (0, _ahooks.useSetState)({
      startDate: sDate ? sDate : (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : (0, _moment["default"])().format('YYYY-MM-DD')
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate;
  var _BaseService$useTrend = _api.BaseService.useTrendInfo(code, startDate, endDate),
    trendRes = _BaseService$useTrend.trendRes;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  (0, _react.useEffect)(function () {
    setDate(startDate, endDate);
  }, [startDate, endDate]);
  var maxNum = null;
  if (((_a = trendRes === null || trendRes === void 0 ? void 0 : trendRes.values) === null || _a === void 0 ? void 0 : _a.length) > 0) {
    maxNum = (0, _lodash.max)((0, _lodash.flatten)(trendRes.values));
  }
  var option = {
    color: ['#1890FF'],
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        return params[0].name + '<br/>' + params[0].seriesName + ': ' + params[0].value + '吨';
      }
    },
    legend: {
      show: false
    },
    grid: {
      top: 28,
      left: 56,
      right: 42,
      bottom: 18,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: (trendRes === null || trendRes === void 0 ? void 0 : trendRes.names) || []
    },
    yAxis: {
      name: '吨',
      type: 'value',
      axisTick: {
        show: false
      },
      max: maxNum,
      nameTextStyle: {
        //y轴上方单位的颜色
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    },
    series: [{
      name: '进场量',
      type: 'line',
      data: (trendRes === null || trendRes === void 0 ? void 0 : trendRes.values) ? trendRes.values[0] : [],
      markLine: {
        data: [{
          yAxis: (trendRes === null || trendRes === void 0 ? void 0 : trendRes.values) && trendRes.values[1] ? trendRes.values[1][0] : 0,
          lineStyle: {
            normal: {
              color: '#FFE25D'
            }
          },
          name: '设计能力(吨/日)'
        }],
        lineStyle: {
          color: '#52C41A'
        },
        label: {
          show: true,
          position: 'insideEndTop',
          formatter: '{b}: {c}',
          color: theme === 'blue' ? '#fff' : chartFontColor,
          fontWeight: 'normal'
        }
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top--jcqsfx"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle.SubTitle2, {
    title: '进场趋势分析',
    extra: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
      onChange: function onChange(dates) {
        return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).format('YYYY-MM-DD'));
      }
    }))
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top--chart"
  }, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '100%',
      width: '100%'
    }
  })));
}
//# sourceMappingURL=Jcqsfx.js.map
