"use strict";

exports.__esModule = true;
exports.createDataSource = void 0;
var createDataSource = function createDataSource(list, keys, level, prefix) {
  if (keys === void 0) {
    keys = {
      selected: [],
      expanded: []
    };
  }
  if (level === void 0) {
    level = 0;
  }
  if (prefix === void 0) {
    prefix = '';
  }
  var array = [];
  var index = 0;
  list.forEach(function (item) {
    var key = (prefix || level) + "-" + index++;
    if (item.children && item.children.length > 0) {
      item.children = createDataSource(item.children, keys, level + 1, key);
    }
    if (typeof Array.isArray(item.value) && item.value.length) {
      var _label, _icon;
      item.value.forEach(function (i) {
        if (i.type === 'icon') {
          _icon = i.value;
        } else {
          _label = i.value;
        }
      });
      array.push({
        label: _label,
        icon: _icon,
        disabled: item.state === 'disabled',
        key: key,
        children: item.children
      });
    } else {
      array.push({
        label: item.value,
        disabled: item.state === 'disabled',
        key: key,
        children: item.children
      });
    }
    if (item.state === 'active') {
      if (item.children && item.children.length > 0) {
        keys.expanded.push(key);
      } else {
        keys.selected.push(key);
      }
    }
    return;
  });
  return array;
};
exports.createDataSource = createDataSource;