'use strict';

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

var color = require('../../../../../../zrender@6.0.0/node_modules/zrender/lib/tool/color.js');
var util = require('../../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.js');
var tokens = require('../../visual/tokens.js');

function sunburstVisual(ecModel) {
  var paletteScope = {};
  // Default color strategy
  function pickColor(node, seriesModel, treeHeight) {
    if (node.depth === 0) {
      // Don't use palette color for the root node, because it's displayed only when drilling down.
      return tokens.default.color.neutral50;
    }
    // Choose color from palette based on the first level.
    var current = node;
    while (current && current.depth > 1) {
      current = current.parentNode;
    }
    var color$1 = seriesModel.getColorFromPalette(current.name || current.dataIndex + '', paletteScope);
    if (node.depth > 1 && util.isString(color$1)) {
      // Lighter on the deeper level.
      color$1 = color.lift(color$1, (node.depth - 1) / (treeHeight - 1) * 0.5);
    }
    return color$1;
  }
  ecModel.eachSeriesByType('sunburst', function (seriesModel) {
    var data = seriesModel.getData();
    var tree = data.tree;
    tree.eachNode(function (node) {
      var model = node.getModel();
      var style = model.getModel('itemStyle').getItemStyle();
      if (!style.fill) {
        style.fill = pickColor(node, seriesModel, tree.root.height);
      }
      var existsStyle = data.ensureUniqueItemVisual(node.dataIndex, 'style');
      util.extend(existsStyle, style);
    });
  });
}

exports.default = sunburstVisual;
