'use strict';

var tslib_es6 = require('../../../../../../tslib@2.3.0/node_modules/tslib/tslib.es6.js');
var Component = require('../../model/Component.js');
var log = require('../../util/log.js');
var tokens = require('../../visual/tokens.js');
var thumbnailBridge = require('../helper/thumbnailBridge.js');
var ThumbnailBridgeImpl = require('./ThumbnailBridgeImpl.js');

var ThumbnailModel = /** @class */function (_super) {
  tslib_es6.__extends(ThumbnailModel, _super);
  function ThumbnailModel() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.type = ThumbnailModel.type;
    _this.preventAutoZ = true;
    return _this;
  }
  ThumbnailModel.prototype.optionUpdated = function (newCptOption, isInit) {
    this._updateBridge();
  };
  ThumbnailModel.prototype._updateBridge = function () {
    var bridge = this._birdge = this._birdge || new ThumbnailBridgeImpl.ThumbnailBridgeImpl(this);
    // Clear all, in case of option changed.
    this._target = null;
    this.ecModel.eachSeries(function (series) {
      thumbnailBridge.injectThumbnailBridge(series, null);
    });
    if (this.shouldShow()) {
      var target = this.getTarget();
      // If a component is targeted by more than one thumbnails, simply only the last one works.
      thumbnailBridge.injectThumbnailBridge(target.baseMapProvider, bridge);
    }
  };
  ThumbnailModel.prototype.shouldShow = function () {
    return this.getShallow('show', true);
  };
  ThumbnailModel.prototype.getBridge = function () {
    return this._birdge;
  };
  ThumbnailModel.prototype.getTarget = function () {
    if (this._target) {
      return this._target;
    }
    // Find by `seriesId`/`seriesIndex`.
    var series = this.getReferringComponents('series', {
      useDefault: false,
      enableAll: false,
      enableNone: false
    }).models[0];
    if (series) {
      if (series.subType !== 'graph') {
        series = null;
        if (process.env.NODE_ENV !== 'production') {
          log.error("series." + series.subType + " is not supported in thumbnail.", true);
        }
      }
    } else {
      // If no xxxId and xxxIndex specified, find the first series.graph. If other components,
      // such as geo, is supported in future, the default stretagy may be extended.
      series = this.ecModel.queryComponents({
        mainType: 'series',
        subType: 'graph'
      })[0];
    }
    this._target = {
      baseMapProvider: series
    };
    return this._target;
  };
  ThumbnailModel.type = 'thumbnail';
  ThumbnailModel.layoutMode = 'box';
  // All the supported components should be added here.
  ThumbnailModel.dependencies = ['series', 'geo'];
  ThumbnailModel.defaultOption = {
    show: true,
    right: 1,
    bottom: 1,
    height: '25%',
    width: '25%',
    itemStyle: {
      // Use echarts option.backgorundColor by default.
      borderColor: tokens.default.color.border,
      borderWidth: 2
    },
    windowStyle: {
      borderWidth: 1,
      color: tokens.default.color.neutral30,
      borderColor: tokens.default.color.neutral40,
      opacity: 0.3
    },
    z: 10
  };
  return ThumbnailModel;
}(Component.default);

exports.ThumbnailModel = ThumbnailModel;
