"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var updateChildren = function updateChildren(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('icon', map[primaryKey].icon);
      child.setPropValue('title', map[primaryKey].title);
      child.setPropValue('content', map[primaryKey].content);
      child.setPropValue('state', map[primaryKey].state);
      child.setPropValue('time', map[primaryKey].time);
      child.setPropValue('timeLeft', map[primaryKey].timeLeft);
      child.setPropValue('animation', map[primaryKey].animation);
      delete map[primaryKey];
      return false;
    }
    return true;
  }, function () {
    var items = [];
    for (var primaryKey in map) {
      if (Object.hasOwnProperty.call(map, primaryKey)) {
        items.push({
          componentName: 'Timeline.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;
  });
};
module.exports = {
  group: '原子组件',
  componentName: 'Timeline',
  title: '时间轴',
  docUrl: '',
  screenshot: '',
  npm: {
    "package": '@alilc/lowcode-materials',
    version: '{{version}}',
    exportName: 'Timeline',
    main: '',
    destructuring: true,
    subName: ''
  },
  props: [{
    name: 'fold',
    propType: {
      type: 'arrayOf',
      value: {
        type: 'exact',
        value: [{
          name: 'foldArea',
          propType: {
            type: 'arrayOf',
            value: 'number'
          }
        }, {
          name: 'foldShow',
          propType: 'bool'
        }]
      }
    },
    description: '自定义折叠选项 示例`[{foldArea: [startIndex, endIndex], foldShow: boolean}]`',
    defaultValue: []
  }, {
    name: 'style',
    propType: 'object'
  }],
  configure: {
    component: {
      isContainer: true,
      nestingRule: {
        childWhitelist: ['Timeline.Item']
      }
    },
    props: [{
      name: '!timeAlign',
      title: '时间位置',
      defaultValue: 'bottom',
      setter: {
        componentName: 'RadioGroupSetter',
        props: {
          options: [{
            label: '左侧',
            value: 'left'
          }, {
            label: '底部',
            value: 'bottom'
          }]
        }
      },
      setValue: function setValue(target, value) {
        var _target$parent, _target$parent$getPro;
        console.log('setvalue');
        var items = target === null || target === void 0 ? void 0 : (_target$parent = target.parent) === null || _target$parent === void 0 ? void 0 : (_target$parent$getPro = _target$parent.getPropValue) === null || _target$parent$getPro === void 0 ? void 0 : _target$parent$getPro.call(_target$parent, '!items');
        if (items && items.length) {
          var _target$parent2, _target$parent2$setPr;
          var _items;
          if (value === 'left') {
            _items = items.map(function (item) {
              return (0, _extends2["default"])({}, item, {
                time: undefined,
                timeLeft: item.time
              });
            });
          } else {
            _items = items.map(function (item) {
              return (0, _extends2["default"])({}, item, {
                timeLeft: undefined,
                time: item.timeLeft
              });
            });
          }
          target === null || target === void 0 ? void 0 : (_target$parent2 = target.parent) === null || _target$parent2 === void 0 ? void 0 : (_target$parent2$setPr = _target$parent2.setPropValue) === null || _target$parent2$setPr === void 0 ? void 0 : _target$parent2$setPr.call(_target$parent2, '!items', _items);
          updateChildren(target, _items);
        }
      }
    }, {
      name: '!items',
      title: '时间轴数据',
      setter: function setter(target) {
        return {
          componentName: 'ArraySetter',
          props: {
            itemSetter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [{
                    name: 'title',
                    setter: 'StringSetter',
                    important: true,
                    title: '标题'
                  }, {
                    name: 'icon',
                    title: '图标',
                    setter: 'IconSetter',
                    description: '图标'
                  }, {
                    name: 'state',
                    setter: {
                      componentName: 'RadioGroupSetter',
                      props: {
                        options: ['done', 'process', 'error', 'success']
                      }
                    },
                    title: '节点状态',
                    defaultValue: 'done'
                  }, {
                    name: 'time',
                    setter: {
                      componentName: 'DateSetter',
                      props: {
                        format: 'YYYY-MM-DD'
                      }
                    },
                    title: '底部时间',
                    condition: function condition() {
                      var _target$parent3, _target$parent3$getPr;
                      var timeAlign = (target === null || target === void 0 ? void 0 : (_target$parent3 = target.parent) === null || _target$parent3 === void 0 ? void 0 : (_target$parent3$getPr = _target$parent3.getPropValue) === null || _target$parent3$getPr === void 0 ? void 0 : _target$parent3$getPr.call(_target$parent3, '!timeAlign')) || 'left';
                      return timeAlign === 'bottom';
                    }
                  }, {
                    name: 'timeLeft',
                    setter: {
                      componentName: 'DateSetter',
                      props: {
                        format: 'YYYY-MM-DD'
                      }
                    },
                    title: '左侧时间',
                    condition: function condition() {
                      var _target$parent4, _target$parent4$getPr;
                      var timeAlign = (target === null || target === void 0 ? void 0 : (_target$parent4 = target.parent) === null || _target$parent4 === void 0 ? void 0 : (_target$parent4$getPr = _target$parent4.getPropValue) === null || _target$parent4$getPr === void 0 ? void 0 : _target$parent4$getPr.call(_target$parent4, '!timeAlign')) || 'left';
                      return timeAlign === 'left';
                    }
                  }, {
                    name: 'content',
                    setter: 'TextAreaSetter',
                    title: '右侧内容'
                  }, {
                    name: 'animation',
                    setter: 'BoolSetter',
                    title: '启用动画',
                    defaultValue: true
                  }]
                }
              },
              initialValue: function initialValue() {
                return {
                  primaryKey: String(Math.floor(Math.random() * 10000)),
                  title: 'TimelineItem'
                };
              }
            }
          }
        };
      },
      extraProps: {
        getValue: function getValue(target, fieldValue) {
          // const node = target.node;
          // const children = node.getChildren();
          var map = target.node.children.map(function (child) {
            var primaryKey = child.getPropValue('primaryKey') ? String(child.getPropValue('primaryKey')) : child.id;
            return {
              primaryKey: primaryKey,
              icon: child.getPropValue('icon'),
              title: child.getPropValue('title'),
              state: child.getPropValue('state'),
              time: child.getPropValue('time'),
              timeLeft: child.getPropValue('timeLeft'),
              content: child.getPropValue('content'),
              animation: child.getPropValue('animation')
            };
          });
          return map;
        },
        setValue: updateChildren
      }
    }]
  },
  icon: '',
  category: '信息展示',
  snippets: require("./snippets")
};