/**
 * 
 *     @dfsj/echarts： 专业的水文曲线组件或构造函数以及通用的echart二次封装图表
 *     版本: v3.7.0
 *     作者：yangbo <1747837358@qq.com>
 *     日期：2025-05-27 15:53:33
 *     
 *     
 */

import assign from '../../utils/assign.js';
import def from './default.js';
import config from '../../config.js';
import { useECharts } from '../../hooks/useECharts.js';
import { useTable } from '../../view/useTable.js';
import { useStatistic } from '../../view/useStatistic.js';

function useDrainageCurves(chartRef) {
  var _useECharts = useECharts(chartRef),
    setOptions = _useECharts.setOptions,
    echarts = _useECharts.echarts,
    getInstance = _useECharts.getInstance,
    container = _useECharts.container;
  var _useTable = useTable(),
    openTable = _useTable.open,
    closeTable = _useTable.close,
    props = _useTable.props,
    toggleTable = _useTable.toggleTable;
  props.container = container;
  var _useStatistic = useStatistic(),
    toggleStatistic = _useStatistic.toggleStatistic;
  var assemble = function assemble(value, options) {
    var optioned = assign({}, def, options);
    var chart = getInstance();
    if (value != null) {
      props.value = value;
      props.chart = chart;
      var src = value.source;
      var last = value.source.length - 1;
      optioned.dataset.source = value.source;
      optioned.series = value.dimensions.filter(function (e, i) {
        return i > 0;
      }).map(function (e, i) {
        var markPoint = {
          data: [{
            coord: [src[last][i + 1], src[last][0]],
            name: e
          }]
        };
        return assign({
          name: e,
          encode: {
            x: i + 1
          },
          markPoint: markPoint
        }, optioned.$series);
      });
      optioned.toolbox.feature.myTabulation = {
        onclick: function onclick() {
          props.visible = !props.visible;
          console.log('打开', props);
          props.visible ? openTable() : closeTable();
        },
        icon: config.icon.tabulation,
        title: '表格'
      };
    }
    return optioned;
  };
  var transform = function transform(data) {
    return {};
  };
  var createOptions = function createOptions(data) {
    return {};
  };
  return {
    setOptions: setOptions,
    echarts: echarts,
    getInstance: getInstance,
    container: container,
    assemble: assemble,
    transform: transform,
    createOptions: createOptions,
    toggleTable: toggleTable,
    toggleStatistic: toggleStatistic
  };
}

export { useDrainageCurves };
