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 * as echarts from 'echarts';
import ReactEcharts from 'echarts-for-react';
import dayjs from 'dayjs';
import { useEffect } from 'react';
import { VmEmpty, VmFilter } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function Jczbqs(props) {
  var _timeSumData$extraDat2, _timeSumData$extraDat3, _timeSumData$values;
  var _useSettings = useSettings(),
    chartFontColor = _useSettings.chartFontColor,
    isDark = _useSettings.isDark;
  var deviceId = props.deviceId,
    deviceName = props.deviceName,
    realtimeRes = props.realtimeRes,
    startDate = props.startDate,
    endDate = props.endDate;
  var _useSetState = useSetState({
      value: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var value = state.value;
  useEffect(function () {
    var _realtimeRes$;
    setState({
      value: realtimeRes === null || realtimeRes === void 0 || (_realtimeRes$ = realtimeRes[0]) === null || _realtimeRes$ === void 0 ? void 0 : _realtimeRes$.monitorItemCode
    });
  }, [realtimeRes]);
  var _BaseService$useJczbq = BaseService.useJczbqsfx(value, deviceId, dayjs(startDate).format('YYYY-MM-DD 00:00:00'), dayjs(endDate).format('YYYY-MM-DD 23:59:59')),
    timeSumData = _BaseService$useJczbq.timeSumData;
  var option = {
    color: ['#1890FF'],
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        var _timeSumData$extraDat;
        return params[0].name + '<br/>' + params[0].seriesName + ': ' + params[0].value + (timeSumData === null || timeSumData === void 0 || (_timeSumData$extraDat = timeSumData.extraData) === null || _timeSumData$extraDat === void 0 || (_timeSumData$extraDat = _timeSumData$extraDat[0]) === null || _timeSumData$extraDat === void 0 ? void 0 : _timeSumData$extraDat.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: isDark ? '#fff' : chartFontColor
      },
      data: (timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.names) || []
    },
    yAxis: {
      name: (timeSumData === null || timeSumData === void 0 || (_timeSumData$extraDat2 = timeSumData.extraData) === null || _timeSumData$extraDat2 === void 0 || (_timeSumData$extraDat2 = _timeSumData$extraDat2[0]) === null || _timeSumData$extraDat2 === void 0 ? void 0 : _timeSumData$extraDat2.unit) || '',
      type: 'value',
      axisTick: {
        show: false
      },
      min: 0,
      nameTextStyle: {
        //y轴上方单位的颜色
        color: isDark ? '#fff' : chartFontColor
      },
      axisLabel: {
        color: isDark ? '#fff' : chartFontColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    },
    series: [{
      name: timeSumData === null || timeSumData === void 0 || (_timeSumData$extraDat3 = timeSumData.extraData) === null || _timeSumData$extraDat3 === void 0 || (_timeSumData$extraDat3 = _timeSumData$extraDat3[0]) === null || _timeSumData$extraDat3 === void 0 ? void 0 : _timeSumData$extraDat3.monitorItemName,
      type: 'line',
      data: timeSumData !== null && timeSumData !== void 0 && timeSumData.values ? timeSumData.values[0] : [],
      smooth: true,
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
          offset: 0,
          color: isDark ? 'rgba(0,157,255,0.1)' : 'rgba(22, 119, 255, 0.10)'
        }, {
          offset: 0.5,
          color: isDark ? 'rgba(0,157,255,0.3)' : 'rgba(22, 119, 255, 0.30)'
        }, {
          offset: 1,
          color: isDark ? 'rgba(0,157,255,0.75)' : 'rgba(22, 119, 255, 0.75)'
        }])
      }
    }],
    dataZoom: [{
      // 这个dataZoom组件，默认控制x轴。
      type: 'slider',
      // 这个 dataZoom 组件是 slider 型 dataZoom 组件
      start: 0,
      // 左边在 10% 的位置。
      end: 100,
      // 右边在 60% 的位置。
      borderColor: isDark ? 'rgba(0, 157, 255, 0.5)' : 'rgba(22, 119, 255, 0.5)',
      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__*/_jsxs("div", {
    className: "df-condition-trend",
    children: [/*#__PURE__*/_jsxs("div", {
      className: "df-condition-trend-head",
      children: [/*#__PURE__*/_jsx("div", {
        children: deviceName || ''
      }), /*#__PURE__*/_jsx(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
      })]
    }), /*#__PURE__*/_jsx("div", {
      style: {
        height: 414,
        width: '100%'
      },
      children: timeSumData !== null && timeSumData !== void 0 && (_timeSumData$values = timeSumData.values) !== null && _timeSumData$values !== void 0 && _timeSumData$values.length ? /*#__PURE__*/_jsx(ReactEcharts, {
        option: option,
        notMerge: true,
        lazyUpdate: true,
        style: {
          height: '100%',
          width: '100%'
        }
      }) : /*#__PURE__*/_jsx(VmEmpty, {
        type: "NO_CHART"
      })
    })]
  });
}
export default Jczbqs;