"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 echarts = _interopRequireWildcard(require("echarts"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _api = require("../../api");
var _vmEmpty = _interopRequireDefault(require("../../../vm-empty"));
var _vmFilter = require("../../../vm-filter");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
require("./index.less");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 Jczbqs(props) {
  var _a, _b, _c, _d, _e;
  var _useSettings = (0, _useSettings2["default"])(),
    chartFontColor = _useSettings.chartFontColor,
    theme = _useSettings.theme,
    isDark = _useSettings.isDark;
  var deviceId = props.deviceId,
    deviceName = props.deviceName,
    realtimeRes = props.realtimeRes,
    startDate = props.startDate,
    endDate = props.endDate;
  var _useSetState = (0, _ahooks.useSetState)({
      value: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var value = state.value;
  (0, _react.useEffect)(function () {
    var _a;
    setState({
      value: (_a = realtimeRes === null || realtimeRes === void 0 ? void 0 : realtimeRes[0]) === null || _a === void 0 ? void 0 : _a.monitorItemCode
    });
  }, [realtimeRes]);
  var _BaseService$useJczbq = _api.BaseService.useJczbqsfx(value, deviceId, (0, _moment["default"])(startDate).format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])(endDate).format('YYYY-MM-DD 23:59:59')),
    timeSumData = _BaseService$useJczbq.timeSumData;
  var option = {
    color: ['#1890FF'],
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        var _a, _b;
        return params[0].name + '<br/>' + params[0].seriesName + ': ' + params[0].value + ((_b = (_a = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.extraData) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.unit) || '';
      }
    },
    legend: {
      show: false
    },
    grid: {
      top: 28,
      left: 56,
      right: 42,
      bottom: 32,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: (timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.names) || []
    },
    yAxis: {
      name: ((_b = (_a = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.extraData) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.unit) || '',
      type: 'value',
      axisTick: {
        show: false
      },
      min: 0,
      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: (_d = (_c = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.extraData) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.monitorItemName,
      type: 'line',
      data: (timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.values) ? timeSumData.values[0] : [],
      smooth: true,
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
          offset: 0,
          color: theme === 'blue' ? 'rgba(0,157,255,0.1)' : 'rgba(22, 119, 255, 0.10)'
        }, {
          offset: 0.5,
          color: theme === 'blue' ? 'rgba(0,157,255,0.3)' : 'rgba(22, 119, 255, 0.30)'
        }, {
          offset: 1,
          color: theme === 'blue' ? 'rgba(0,157,255,0.75)' : 'rgba(22, 119, 255, 0.75)'
        }])
      }
    }],
    dataZoom: [{
      // 这个dataZoom组件，默认控制x轴。
      type: 'slider',
      start: 0,
      end: 100,
      borderColor: isDark ? 'rgba(0, 157, 255, 0.5)' : 'rgba(22, 119, 255, 0.5)',
      // handleIcon:
      //     'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
      handleSize: '150%',
      height: 16,
      handleStyle: {
        color: '#fff',
        shadowBlur: 3,
        shadowColor: 'rgba(0, 0, 0, 0.4)',
        shadowOffsetX: 2,
        shadowOffsetY: 2
      },
      showDataShadow: false,
      showDetail: false,
      backgroundColor: isDark ? 'rgba(0, 157, 255, 0.5)' : 'rgba(22, 119, 255, 0.2)',
      bottom: 10
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-condition-trend"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "df-condition-trend-head"
  }, /*#__PURE__*/_react["default"].createElement("div", null, deviceName || ''), /*#__PURE__*/_react["default"].createElement(_vmFilter.VMSelect, {
    value: value,
    onChange: function onChange(val) {
      setState({
        value: val
      });
    },
    options: realtimeRes === null || realtimeRes === void 0 ? void 0 : realtimeRes.map(function (item) {
      return {
        value: item.monitorItemCode,
        label: item.monitorItemName
      };
    }),
    style: {
      width: 150
    },
    placeholder: "\u8BF7\u9009\u62E9",
    allowClear: false
  })), ((_e = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.values) === null || _e === void 0 ? void 0 : _e.length) ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: 400,
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmEmpty["default"], {
    style: {
      display: 'block'
    },
    type: "chart",
    text: ""
  })));
}
var _default = exports["default"] = Jczbqs;
//# sourceMappingURL=Monitor.js.map
