function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
import ReactEcharts from 'echarts-for-react';
import groupBy from 'lodash/groupBy';
import useSettings from "../../../_hooks/useSettings";
import { jsx as _jsx } from "react/jsx-runtime";
var xAxis = _toConsumableArray(new Array(24)).map(function (_, index) {
  return add0(index);
});
function add0(num) {
  return num >= 10 ? num.toString() : "0".concat(num);
}
function transferData(data) {
  var chartData = [];
  var dataGroupByDate = groupBy(data, 'date');
  var count = 0;
  // eslint-disable-next-line guard-for-in
  for (var key in dataGroupByDate) {
    dataGroupByDate[key].forEach(function (item, index) {
      chartData.push([index, count, item.value]);
    });
    count++;
  }
  return {
    yAxis: Object.keys(dataGroupByDate).map(function (item) {
      return item.substring(5);
    }),
    chartData: chartData
  };
}
var getGaugeOption = function getGaugeOption(_ref, isDark) {
  var _ref$data = _ref.data,
    data = _ref$data === void 0 ? [] : _ref$data;
  var _transferData = transferData(data),
    yAxis = _transferData.yAxis,
    chartData = _transferData.chartData;
  var max = Math.max.apply(Math, _toConsumableArray(chartData.map(function (item) {
    return item[2];
  })));
  if (!(chartData !== null && chartData !== void 0 && chartData.length)) return {};
  return {
    tooltip: {
      position: 'top',
      formatter: function formatter(params) {
        var value = params.value,
          marker = params.marker;
        var date = yAxis[value[1]];
        var hour = "".concat(add0(value[0]), ":00-").concat(add0(value[0] + 1), ":00");
        return "<div>".concat(date, " ").concat(hour, "</div><div>").concat(marker, " \u6295\u653E\u6B21\u6570\uFF1A").concat(value[2], "\u6B21</div>");
      }
    },
    grid: {
      top: 50,
      bottom: 0,
      right: 0,
      left: 0,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: xAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        interval: 0,
        color: isDark ? '#fff' : '#000'
      },
      axisTick: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: yAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        color: isDark ? '#fff' : '#000',
        interval: 0
      },
      axisTick: {
        show: false
      }
    },
    visualMap: {
      // type: 'piecewise',
      min: 0,
      max: max,
      calculable: true,
      orient: 'horizontal',
      left: 'center',
      top: 0,
      inRange: {
        color: ['rgba(34,154,239,0.5)', '#1CC10D', '#009DFF', '#FF9500', '#F5222D']
      },
      textStyle: {
        color: '#fff'
      }
    },
    series: [{
      name: '24h分布',
      type: 'heatmap',
      data: chartData,
      label: {
        show: true
      },
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }]
  };
};
var Distribute = function Distribute(props) {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  return /*#__PURE__*/_jsx(ReactEcharts, {
    option: getGaugeOption(props, isDark),
    style: {
      height: '100%'
    }
  });
};
export default Distribute;