import createSeriesDataSimply from "./createSeriesDataSimply.mjs";
import { each, isArray, extend, curry } from "../../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.mjs";
import { getDimensionTypeByAxis } from "../../data/helper/dimensionHelper.mjs";
import { makeSeriesEncodeForAxisCoordSys } from "../../data/helper/sourceHelper.mjs";
var WhiskerBoxCommonMixin = (
  /** @class */
  function() {
    function WhiskerBoxCommonMixin2() {
    }
    WhiskerBoxCommonMixin2.prototype.getInitialData = function(option, ecModel) {
      var ordinalMeta;
      var xAxisModel = ecModel.getComponent("xAxis", this.get("xAxisIndex"));
      var yAxisModel = ecModel.getComponent("yAxis", this.get("yAxisIndex"));
      var xAxisType = xAxisModel.get("type");
      var yAxisType = yAxisModel.get("type");
      var addOrdinal;
      if (xAxisType === "category") {
        option.layout = "horizontal";
        ordinalMeta = xAxisModel.getOrdinalMeta();
        addOrdinal = true;
      } else if (yAxisType === "category") {
        option.layout = "vertical";
        ordinalMeta = yAxisModel.getOrdinalMeta();
        addOrdinal = true;
      } else {
        option.layout = option.layout || "horizontal";
      }
      var coordDims = ["x", "y"];
      var baseAxisDimIndex = option.layout === "horizontal" ? 0 : 1;
      var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
      var otherAxisDim = coordDims[1 - baseAxisDimIndex];
      var axisModels = [xAxisModel, yAxisModel];
      var baseAxisType = axisModels[baseAxisDimIndex].get("type");
      var otherAxisType = axisModels[1 - baseAxisDimIndex].get("type");
      var data = option.data;
      if (data && addOrdinal) {
        var newOptionData_1 = [];
        each(data, function(item, index) {
          var newItem;
          if (isArray(item)) {
            newItem = item.slice();
            item.unshift(index);
          } else if (isArray(item.value)) {
            newItem = extend({}, item);
            newItem.value = newItem.value.slice();
            item.value.unshift(index);
          } else {
            newItem = item;
          }
          newOptionData_1.push(newItem);
        });
        option.data = newOptionData_1;
      }
      var defaultValueDimensions = this.defaultValueDimensions;
      var coordDimensions = [{
        name: baseAxisDim,
        type: getDimensionTypeByAxis(baseAxisType),
        ordinalMeta,
        otherDims: {
          tooltip: false,
          itemName: 0
        },
        dimsDef: ["base"]
      }, {
        name: otherAxisDim,
        type: getDimensionTypeByAxis(otherAxisType),
        dimsDef: defaultValueDimensions.slice()
      }];
      return createSeriesDataSimply(this, {
        coordDimensions,
        dimensionsCount: defaultValueDimensions.length + 1,
        encodeDefaulter: curry(makeSeriesEncodeForAxisCoordSys, coordDimensions, this)
      });
    };
    WhiskerBoxCommonMixin2.prototype.getBaseAxis = function() {
      var dim = this._baseAxisDim;
      return this.ecModel.getComponent(dim + "Axis", this.get(dim + "AxisIndex")).axis;
    };
    return WhiskerBoxCommonMixin2;
  }()
);
export {
  WhiskerBoxCommonMixin
};
