import { ref } from 'vue';
import { toMarks } from '../../utils/render.js';
import def from './default.js';
import config, { CATEGORY } from '../../config.js';
import assign from '../../utils/assign.js';
import 'dayjs';
import 'numeral';
import 'lodash-es/assign';
import '@dfsj/utils';
import { useHydrology } from '../useHydrology/index.js';
import { useECharts } from '../../hooks/useECharts.js';

function useRainfall(chartRef) {
  var _useECharts = useECharts(chartRef),
    setOptions = _useECharts.setOptions,
    echarts = _useECharts.echarts,
    getInstance = _useECharts.getInstance,
    container = _useECharts.container;
  var rainIndex = ref(0);
  var _useHydrology = useHydrology(null, {
      S: toSeries,
      M: toMarks$1,
      C: def
    }),
    hydrologyAssemble = _useHydrology.assemble;
  var assemble = function assemble(value, options) {
    var chart = getInstance();
    rainIndex.value = 0;
    return hydrologyAssemble(value, options, chart);
  };
  function toSeries(dimension, index, optioned) {
    var item = optioned.$series.find(function (e) {
      return e.$code & dimension.code;
    });
    if ((item === null || item === void 0 ? void 0 : item.$code) === CATEGORY.RAINFALL) {
      item.itemStyle.color = config.rainfallColor[rainIndex.value++];
    }
    return item;
  }
  function toMarks$1(value, optioned) {
    return toMarks(value, optioned, assign({}, config.mark, optioned.$mark));
  }
  return {
    setOptions: setOptions,
    echarts: echarts,
    getInstance: getInstance,
    container: container,
    assemble: assemble
  };
}

export { useRainfall };
