'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib_es6 = require('../../../../../tslib@2.3.0/node_modules/tslib/tslib.es6.js');
var axisDefault = require('./axisDefault.js');
var layout = require('../util/layout.js');
var OrdinalMeta = require('../data/OrdinalMeta.js');
var axisCommonTypes = require('./axisCommonTypes.js');
var util = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.js');
var axisBreakHelper = require('../component/axis/axisBreakHelper.js');

/**
 * Generate sub axis model class
 * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
 */
function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
  util.each(axisCommonTypes.AXIS_TYPES, function (v, axisType) {
    var defaultOption = util.merge(util.merge({}, axisDefault.default[axisType], true), extraDefaultOption, true);
    var AxisModel = /** @class */function (_super) {
      tslib_es6.__extends(AxisModel, _super);
      function AxisModel() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.type = axisName + 'Axis.' + axisType;
        return _this;
      }
      AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
        var layoutMode = layout.fetchLayoutMode(this);
        var inputPositionParams = layoutMode ? layout.getLayoutParams(option) : {};
        var themeModel = ecModel.getTheme();
        util.merge(option, themeModel.get(axisType + 'Axis'));
        util.merge(option, this.getDefaultOption());
        option.type = getAxisType(option);
        if (layoutMode) {
          layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
        }
      };
      AxisModel.prototype.optionUpdated = function () {
        var thisOption = this.option;
        if (thisOption.type === 'category') {
          this.__ordinalMeta = OrdinalMeta.default.createByAxisModel(this);
        }
      };
      /**
       * Should not be called before all of 'getInitailData' finished.
       * Because categories are collected during initializing data.
       */
      AxisModel.prototype.getCategories = function (rawData) {
        var option = this.option;
        // FIXME
        // warning if called before all of 'getInitailData' finished.
        if (option.type === 'category') {
          if (rawData) {
            return option.data;
          }
          return this.__ordinalMeta.categories;
        }
      };
      AxisModel.prototype.getOrdinalMeta = function () {
        return this.__ordinalMeta;
      };
      AxisModel.prototype.updateAxisBreaks = function (payload) {
        var axisBreakHelper$1 = axisBreakHelper.getAxisBreakHelper();
        return axisBreakHelper$1 ? axisBreakHelper$1.updateModelAxisBreak(this, payload) : {
          breaks: []
        };
      };
      AxisModel.type = axisName + 'Axis.' + axisType;
      AxisModel.defaultOption = defaultOption;
      return AxisModel;
    }(BaseAxisModelClass);
    registers.registerComponentModel(AxisModel);
  });
  registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
}
function getAxisType(option) {
  // Default axis with data is category axis
  return option.type || (option.data ? 'category' : 'value');
}

exports.default = axisModelCreator;
