"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const tslib_es6 = require("../../node_modules/tslib/tslib.es6.js");
const util = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.js");
const Model = require("./Model.js");
const component = require("../util/component.js");
const clazz = require("../util/clazz.js");
const model = require("../util/model.js");
const layout = require("../util/layout.js");
var inner = model.makeInner();
var ComponentModel = (
  /** @class */
  function(_super) {
    tslib_es6.__extends(ComponentModel2, _super);
    function ComponentModel2(option, parentModel, ecModel) {
      var _this = _super.call(this, option, parentModel, ecModel) || this;
      _this.uid = component.getUID("ec_cpt_model");
      return _this;
    }
    ComponentModel2.prototype.init = function(option, parentModel, ecModel) {
      this.mergeDefaultAndTheme(option, ecModel);
    };
    ComponentModel2.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(this.mainType));
      util.merge(option, this.getDefaultOption());
      if (layoutMode) {
        layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
      }
    };
    ComponentModel2.prototype.mergeOption = function(option, ecModel) {
      util.merge(this.option, option, true);
      var layoutMode = layout.fetchLayoutMode(this);
      if (layoutMode) {
        layout.mergeLayoutParam(this.option, option, layoutMode);
      }
    };
    ComponentModel2.prototype.optionUpdated = function(newCptOption, isInit) {
    };
    ComponentModel2.prototype.getDefaultOption = function() {
      var ctor = this.constructor;
      if (!clazz.isExtendedClass(ctor)) {
        return ctor.defaultOption;
      }
      var fields = inner(this);
      if (!fields.defaultOption) {
        var optList = [];
        var clz = ctor;
        while (clz) {
          var opt = clz.prototype.defaultOption;
          opt && optList.push(opt);
          clz = clz.superClass;
        }
        var defaultOption = {};
        for (var i = optList.length - 1; i >= 0; i--) {
          defaultOption = util.merge(defaultOption, optList[i], true);
        }
        fields.defaultOption = defaultOption;
      }
      return fields.defaultOption;
    };
    ComponentModel2.prototype.getReferringComponents = function(mainType, opt) {
      var indexKey = mainType + "Index";
      var idKey = mainType + "Id";
      return model.queryReferringComponents(this.ecModel, mainType, {
        index: this.get(indexKey, true),
        id: this.get(idKey, true)
      }, opt);
    };
    ComponentModel2.prototype.getBoxLayoutParams = function() {
      var boxLayoutModel = this;
      return {
        left: boxLayoutModel.get("left"),
        top: boxLayoutModel.get("top"),
        right: boxLayoutModel.get("right"),
        bottom: boxLayoutModel.get("bottom"),
        width: boxLayoutModel.get("width"),
        height: boxLayoutModel.get("height")
      };
    };
    ComponentModel2.prototype.getZLevelKey = function() {
      return "";
    };
    ComponentModel2.prototype.setZLevel = function(zlevel) {
      this.option.zlevel = zlevel;
    };
    ComponentModel2.protoInitialize = function() {
      var proto = ComponentModel2.prototype;
      proto.type = "component";
      proto.id = "";
      proto.name = "";
      proto.mainType = "";
      proto.subType = "";
      proto.componentIndex = 0;
    }();
    return ComponentModel2;
  }(Model.default)
);
clazz.mountExtend(ComponentModel, Model.default);
clazz.enableClassManagement(ComponentModel);
component.enableSubTypeDefaulter(ComponentModel);
component.enableTopologicalTravel(ComponentModel, getDependencies);
function getDependencies(componentType) {
  var deps = [];
  util.each(ComponentModel.getClassesByMainType(componentType), function(clz) {
    deps = deps.concat(clz.dependencies || clz.prototype.dependencies || []);
  });
  deps = util.map(deps, function(type) {
    return clazz.parseClassType(type).main;
  });
  if (componentType !== "dataset" && util.indexOf(deps, "dataset") <= 0) {
    deps.unshift("dataset");
  }
  return deps;
}
const ComponentModel$1 = ComponentModel;
exports.default = ComponentModel$1;
