import { t } from "../../src/locale";
import { uuid } from "../_utils/utils";
import snippets from "./snippets";
export default {
  snippets: snippets,
  componentName: 'Carousel',
  "group": t('carousel.key_LBl9pRGgdqbW'),
  title: t('carousel.key_ovk03Iq8yjzy'),
  category: t('carousel.key_akjF2lup12Fs'),
  props: [{
    name: 'afterChange',
    title: {
      label: t('carousel.key_icIHq4DRi8WD'),
      tip: t('carousel.key_hOtYbIqfvke4')
    },
    propType: 'func'
  }, {
    name: 'autoplay',
    title: {
      label: t('carousel.key_I98gUEDfVtJf'),
      tip: t('carousel.key_TerLa7vFPAJv')
    },
    propType: 'bool',
    defaultValue: false
  }, {
    name: 'beforeChange',
    title: {
      label: t('carousel.key_XLoD4qLZr4rX'),
      tip: t('carousel.key_mXJvjFxP2ZW1')
    },
    propType: 'func'
  }, {
    name: 'dotPosition',
    title: {
      label: t('carousel.key_A3mTgRPfduFi'),
      tip: t('carousel.key_47auybK4Io28')
    },
    propType: {
      type: 'oneOf',
      value: ['top', 'bottom', 'left', 'right']
    }
  }, {
    name: 'dots',
    title: {
      label: t('carousel.key_0QkaiOW6UkoB'),
      tip: t('carousel.key_oqvREpx3N8Hu')
    },
    propType: {
      type: 'oneOfType',
      value: ['bool', 'object']
    }
  }, {
    name: 'easing',
    title: {
      label: t('carousel.key_TRr0hZ4maZjy'),
      tip: t('carousel.key_XoLNh7eEgwQI')
    },
    propType: 'string'
  }, {
    name: 'effect',
    title: {
      label: t('carousel.key_Ls6MFAdhcZAP'),
      tip: t('carousel.key_UVe0CcKnFIcl')
    },
    propType: {
      type: 'oneOf',
      value: ['scrollx', 'fade']
    }
  }, {
    name: 'items',
    title: t('carousel.key_8tRsuywcBT4v'),
    setter: {
      componentName: 'ArraySetter',
      props: {
        itemSetter: {
          componentName: 'ObjectSetter',
          initialValue: function initialValue() {
            return {
              key: uuid()
            };
          }
        }
      }
    },
    extraProps: {
      getValue: function getValue(target, fieldValue) {
        // console.log('getValue', target.node.children.length);
        var map = target.node.children.map(function (child) {
          var key = child.getPropValue('key') ? String(child.getPropValue('key')) : child.id;
          return {
            key: key
          };
        });
        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 key = String(child.getPropValue('key'));
          if (Object.hasOwnProperty.call(map, key)) {
            delete map[key];
            return false;
          }
          return true;
        }, function () {
          var items = [];
          for (var key in map) {
            if (Object.hasOwnProperty.call(map, key)) {
              items.push({
                componentName: 'Card',
                props: map[key]
              });
            }
          }
          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;
        });
      }
    }
  }],
  configure: {
    supports: {
      style: true
    },
    component: {
      isContainer: true
    }
  }
};