import { t } from "../../src/locale";
import { uuid } from "../_utils/utils";
import snippets from "./snippets";
export default {
  snippets: snippets,
  componentName: 'Collapse',
  "group": t('collapse.key_AAAkeOkadc5o'),
  title: t('collapse.key_QDW9pDzlaGdx'),
  category: t('collapse.key_WL2aoa0eOUEv'),
  props: [{
    name: 'bordered',
    title: {
      label: t('collapse.key_AwwoYAYPHO3W'),
      tip: t('collapse.key_Gdu94xjlbC6p')
    },
    propType: 'bool',
    defaultValue: true,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'accordion',
    title: {
      label: t('collapse.key_oA39LpAzMdYx'),
      tip: t('collapse.key_CEaE8It3Wd9o')
    },
    propType: 'bool',
    defaultValue: false,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'collapsible',
    title: t('collapse.key_uWZOxm2TDRrZ'),
    propType: {
      type: 'oneOf',
      value: ['-', 'header', 'disabled']
    }
  }, {
    name: 'expandIconPosition',
    title: {
      label: t('collapse.key_Ypn8DeTYmMro'),
      tip: t('collapse.key_g12b8daJRtuc')
    },
    propType: {
      type: 'oneOf',
      value: ['left', 'right']
    }
  }, {
    name: 'destroyInactivePanel',
    title: {
      label: t('collapse.key_cj5yr22v6uHw'),
      tip: t('collapse.key_SZ0JOH4vSiCV')
    },
    propType: 'bool',
    defaultValue: false,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'ghost',
    title: {
      label: t('collapse.key_5DVGpPOqTmpS'),
      tip: t('collapse.key_aHOavAAQQkBY')
    },
    propType: 'bool',
    defaultValue: false,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'collapses',
    title: t('collapse.key_iGFBpkaFSW0w'),
    setter: {
      componentName: 'ArraySetter',
      props: {
        itemSetter: {
          componentName: 'ObjectSetter',
          props: {
            config: {
              items: [{
                name: 'key',
                title: 'key',
                setter: 'StringSetter',
                initialValue: function initialValue(val) {
                  return val || uuid();
                }
              }, {
                name: 'header',
                title: t('collapse.key_297lFKfWho5s'),
                setter: 'StringSetter',
                initialValue: t('collapse.key_XxH5V1hnEEFA')
              }]
            }
          },
          initialValue: function initialValue() {
            return {
              key: uuid(),
              header: t('collapse.key_hdPA8Iou6lFl'),
              showArrow: true,
              collapsible: undefined,
              forceRender: false
            };
          }
        }
      }
    },
    extraProps: {
      getValue: function getValue(target, fieldValue) {
        var map = target.node.children.map(function (child) {
          var key = child.getPropValue('key') ? String(child.getPropValue('key')) : child.id;
          return {
            key: key,
            header: child.getPropValue('header'),
            showArrow: child.getPropValue('showArrow'),
            collapsible: child.getPropValue('collapsible'),
            forceRender: child.getPropValue('forceRender')
          };
        });
        return map;
      },
      setValue: function setValue(target, value) {
        var node = target.node;
        var map = {};

        // console.log('setValue',value);

        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)) {
            child.setPropValue('header', map[key].header);
            child.setPropValue('showArrow', map[key].showArrow);
            child.setPropValue('collapsible', map[key].collapsible);
            child.setPropValue('forceRender', map[key].forceRender);
            delete map[key];
            return false;
          }
          return true;
        }, function () {
          var items = [];
          for (var key in map) {
            if (Object.hasOwnProperty.call(map, key)) {
              items.push({
                componentName: 'Collapse.Panel',
                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;
        });
      }
    }
  }, {
    name: 'defaultActiveKey',
    title: {
      label: t('collapse.key_fCIiRk1UcfVt'),
      tip: t('collapse.key_kNBHxjajSl1M')
    },
    propType: {
      type: 'oneOfType',
      value: ['string', {
        type: 'arrayOf',
        value: 'string'
      }, 'number', {
        type: 'arrayOf',
        value: 'number'
      }]
    }
  }, {
    name: 'activeKey',
    title: {
      label: t('collapse.key_Ll7oF4gofORc'),
      tip: t('collapse.key_0D0oe8i1uqbj')
    },
    propType: {
      type: 'oneOfType',
      value: ['string', {
        type: 'arrayOf',
        value: 'string'
      }, 'number', {
        type: 'arrayOf',
        value: 'number'
      }]
    }
  }],
  configure: {
    supports: {
      style: true,
      events: false
    },
    component: {
      isContainer: true
    }
  }
};