export default [{
  name: 'dataList',
  title: '折叠面板项',
  setter: {
    componentName: 'ArraySetter',
    props: {
      itemSetter: {
        componentName: 'ObjectSetter',
        props: {
          config: {
            items: [{
              name: 'title',
              title: '标题',
              defaultValue: '标题名',
              setter: 'StringSetter'
            }, {
              name: 'icon',
              title: '图标',
              defaultValue: '',
              setter: 'StringSetter'
            }, {
              name: 'key',
              title: '项目编号',
              condition: function condition() {
                return false;
              },
              setter: 'StringSetter'
            }, {
              name: 'isContent',
              title: '是否有内容',
              setter: 'BoolSetter',
              initValue: true
            }]
          }
        },
        initialValue: function initialValue() {
          return {
            key: String(Math.floor(Math.random() * 10000)),
            title: '标题名',
            icon: '',
            isContent: true
          };
        }
      }
    }
  },
  extraProps: {
    getValue: function getValue(target) {
      var map = target.node.children.map(function (child) {
        var primaryKey = child.getPropValue('key') ? String(child.getPropValue('key')) : child.id;
        return {
          key: primaryKey,
          title: child.getPropValue('title') || '标题名',
          icon: child.getPropValue('icon') || '',
          isContent: child.getPropValue('isContent')
        };
      });
      return map;
    },
    setValue: function setValue(target, value) {
      var node = target.node;
      var map = {};
      if (!Array.isArray(value)) {
        value = [];
      }
      value.forEach(function (item) {
        var tabitem = Object.assign({}, item);
        map[item.key] = tabitem;
      });
      node.children.mergeChildren(function (child) {
        var primaryKey = String(child.getPropValue('key'));
        if (Object.hasOwnProperty.call(map, primaryKey)) {
          child.setPropValue('title', map[primaryKey].title);
          child.setPropValue('icon', map[primaryKey].icon);
          child.setPropValue('isContent', map[primaryKey].isContent);
          delete map[primaryKey];
          return false;
        }
        return true;
      }, function () {
        var items = [];
        for (var primaryKey in map) {
          if (Object.hasOwnProperty.call(map, primaryKey)) {
            items.push({
              componentName: 'CollapseSelectorItem',
              props: map[primaryKey]
            });
          }
        }
        return items;
      }, function (child1, child2) {
        var a = value.findIndex(function (item) {
          return String(item.key) === String(child1.getPropValue('key'));
        });
        var b = value.findIndex(function (item) {
          return String(item.key) === String(child2.getPropValue('key'));
        });
        return a - b;
      });
    }
  }
}];