"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _default = exports["default"] = [{
  name: 'items',
  title: '折叠面板项',
  setter: {
    componentName: 'ArraySetter',
    props: {
      itemSetter: {
        componentName: 'ObjectSetter',
        props: {
          config: {
            items: [{
              name: 'title',
              title: '名称',
              defaultValue: '折叠面板项',
              important: true,
              setter: 'StringSetter'
            }, {
              name: 'primaryKey',
              title: '项目编号',
              condition: function condition() {
                return false;
              },
              setter: 'StringSetter'
            }, {
              name: 'icon',
              title: '图标',
              initialValue: '',
              setter: 'IconSetter'
            }]
          }
        },
        initialValue: function initialValue() {
          return {
            primaryKey: String(Math.floor(Math.random() * 10000)),
            title: '折叠面板项',
            icon: ''
          };
        }
      }
    }
  },
  extraProps: {
    getValue: function getValue(target) {
      var map = target.node.children.map(function (child) {
        var primaryKey = child.getPropValue('primaryKey') ? String(child.getPropValue('primaryKey')) : child.id;
        return {
          primaryKey: primaryKey,
          title: child.getPropValue('title') || '折叠面板项',
          icon: ''
        };
      });
      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.primaryKey] = tabitem;
      });
      node.children.mergeChildren(function (child) {
        var primaryKey = String(child.getPropValue('primaryKey'));
        if (Object.hasOwnProperty.call(map, primaryKey)) {
          child.setPropValue('title', map[primaryKey].title);
          child.setPropValue('icon', map[primaryKey].icon);
          delete map[primaryKey];
          return false;
        }
        return true;
      }, function () {
        var items = [];
        for (var primaryKey in map) {
          if (Object.hasOwnProperty.call(map, primaryKey)) {
            items.push({
              componentName: 'AccordionSelector.Item',
              props: map[primaryKey]
            });
          }
        }
        return items;
      }, function (child1, child2) {
        var a = value.findIndex(function (item) {
          return String(item.primaryKey) === String(child1.getPropValue('primaryKey'));
        });
        var b = value.findIndex(function (item) {
          return String(item.primaryKey) === String(child2.getPropValue('primaryKey'));
        });
        return a - b;
      });
    }
  }
}];