import _defineProperty from '@babel/runtime/helpers/defineProperty';
import groupBy from 'lodash-es/groupBy';
import { to } from '../../utils/tools.js';
import assign from '../../utils/assign.js';
import config, { CATEGORY, axis, options } from '../../config.js';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function tooltipByMulti(items) {
  var buf = ["<article class='tooltip'>"];
  var grouped = groupBy(items, 'axisIndex');
  Object.keys(grouped).forEach(function (id) {
    buf.push('<fieldset>');
    buf.push("<legend>".concat(grouped[id][0].axisValueLabel, "</legend>"));
    grouped[id].forEach(function (e) {
      buf.push("<li>".concat(e.marker, "<i>").concat(e.seriesName, "</i><i>").concat(to(e.value[e.encode.y[0]]), "</i></li>"));
    });
    buf.push('</fieldset>');
  });
  buf.push('</article>');
  return buf.join('');
}
var def = assign({}, options, {
  $indices: [],
  $series: [{
    $code: CATEGORY.RAINFALL,
    z: 5,
    type: 'bar',
    barCategoryGap: '0',
    barWidth: '100%',
    barGap: '-100%',
    large: true,
    itemStyle: {
      color: null
    },
    markPoint: {
      data: [{
        type: 'max',
        symbolSize: 2,
        label: {
          offset: [0, 12],
          color: 'inherit',
          fontWeight: 'bold',
          fontSize: 14,
          formatter: function formatter(e) {
            return to(e.value);
          }
        }
      }]
    }
  }, {
    $code: ~CATEGORY.RAINFALL,
    z: 5,
    type: 'line',
    smooth: true,
    large: true,
    emphasis: {
      itemStyle: {
        opacity: 0.8
      }
    },
    itemStyle: {
      opacity: 0
    },
    markPoint: {
      data: [{
        type: 'max',
        symbolSize: 2,
        label: {
          offset: [0, -7],
          color: 'inherit',
          fontWeight: 'bold',
          fontSize: 14,
          formatter: function formatter(e) {
            return to(e.value);
          }
        }
      }]
    }
  }],
  color: config.color,
  tooltip: {
    formatter: tooltipByMulti,
    trigger: 'axis',
    axisPointer: {
      type: 'cross'
    }
  },
  axisPointer: {
    link: {
      xAxisIndex: 'all'
    }
  },
  grid: [{
    top: 50,
    left: 80,
    right: 80,
    bottom: '66%'
  }, {
    left: 80,
    right: 80,
    bottom: 50,
    top: '36%'
  }],
  legend: {
    show: true,
    top: 10
  },
  dataZoom: [{
    show: true,
    type: 'slider',
    brushSelect: false,
    handleIcon: config.icon.zoom,
    handleSize: '60%',
    xAxisIndex: [0, 1],
    realtime: true,
    throttle: 30,
    bottom: 10,
    height: 20
  }, {
    type: 'inside',
    realtime: true,
    xAxisIndex: [0, 1]
  }],
  xAxis: [_objectSpread(_objectSpread({}, axis), {}, {
    show: false,
    type: 'category',
    gridIndex: 0,
    boundaryGap: false,
    axisLine: {
      onZero: true
    },
    position: 'top'
  }), _objectSpread(_objectSpread({}, axis), {}, {
    type: 'category',
    gridIndex: 1,
    boundaryGap: false,
    axisLine: {
      onZero: false
    },
    nameGap: 50
  })],
  yAxis: [_objectSpread(_objectSpread({}, axis), {}, {
    $layout: CATEGORY.RAINFALL,
    type: 'value',
    nameLocation: 'middle',
    gridIndex: 0,
    nameGap: 50,
    inverse: true,
    min: 0,
    max: function max(v) {
      return to(v.max + (v.max - v.min) * 0.1);
    }
  }), _objectSpread(_objectSpread({}, axis), {}, {
    $layout: CATEGORY.SWC,
    type: 'value',
    nameLocation: 'middle',
    gridIndex: 0,
    nameGap: 50,
    min: 0,
    max: 100
  }), _objectSpread(_objectSpread({}, axis), {}, {
    $layout: CATEGORY.STAGE,
    type: 'value',
    nameLocation: 'middle',
    gridIndex: 1,
    nameGap: 50,
    min: function min(v) {
      return to(v.min - (v.max - v.min) * 0.1);
    },
    max: function max(v) {
      return to(v.max + (v.max - v.min) * 0.1);
    }
  }), _objectSpread(_objectSpread({}, axis), {}, {
    $layout: CATEGORY.FLOW,
    type: 'value',
    nameLocation: 'middle',
    gridIndex: 1,
    nameGap: 50,
    min: function min(v) {
      return to(Math.max(v.min - (v.max - v.min) * 0.1, 0));
    },
    max: function max(v) {
      return to(Math.min(v.max + (v.max - v.min) * 0.1, Infinity));
    }
  })]
});

export { def as default };
