"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _ = _interopRequireDefault(require(".."));

var _2 = require("../..");

var _excluded = ["children"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

var TreeNode = _2.Tree.Node;
var treeDataSource = [{
  label: 'Form',
  key: '2',
  value: '2',
  children: [{
    label: 'Input',
    key: '4',
    value: '4'
  }, {
    label: 'Field',
    key: '7',
    value: '7'
  }, {
    label: 'Select',
    key: '5',
    value: '5'
  }]
}, {
  label: 'Display',
  key: '3',
  value: '3',
  children: [{
    label: 'Table',
    key: '6',
    value: '6'
  }]
}, {
  label: 'Data',
  key: '8',
  value: '8'
}];
var transferDataSource = [];

function flatten() {
  var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  list.forEach(function (item) {
    transferDataSource.push(item);
    flatten(item.children);
  });
}

flatten(treeDataSource);

var Demo = /*#__PURE__*/function (_React$Component) {
  _inherits(Demo, _React$Component);

  var _super = _createSuper(Demo);

  function Demo(props) {
    var _this;

    _classCallCheck(this, Demo);

    _this = _super.call(this, props);
    _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
    _this.state = {
      selected: []
    };
    return _this;
  }

  _createClass(Demo, [{
    key: "handleChange",
    value: function handleChange(value) {
      this.setState({
        selected: value
      });
    }
  }, {
    key: "getTreeDataSource",
    value: function getTreeDataSource() {
      var _this2 = this;

      var dataSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var value = arguments.length > 1 ? arguments[1] : undefined;
      return dataSource.map(function (_ref) {
        var children = _ref.children,
            props = _objectWithoutProperties(_ref, _excluded);

        return /*#__PURE__*/_react["default"].createElement(TreeNode, _extends({}, props, {
          disabled: props.disabled || value.includes(props.value),
          key: props.value
        }), _this2.getTreeDataSource(children, value));
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;

      var selected = this.state.selected;
      return /*#__PURE__*/_react["default"].createElement(_["default"], {
        dataSource: transferDataSource,
        listStyle: {
          width: '200px',
          height: '192px'
        },
        onChange: this.handleChange,
        titles: [/*#__PURE__*/_react["default"].createElement(_2.Button, {
          key: "left",
          type: "primary"
        }, "Source"), 'Target']
      }, function (_ref2) {
        var position = _ref2.position,
            onChange = _ref2.onChange,
            value = _ref2.value;

        if (position === 'left') {
          return /*#__PURE__*/_react["default"].createElement(_2.Tree, {
            checkable: true,
            editable: true,
            style: {
              padding: '10px'
            },
            checkedKeys: value,
            onCheck: function onCheck(keys, extra) {
              var newValues = extra.checkedNodes.map(function (item) {
                return item.props.value;
              });
              onChange(position, newValues);
            }
          }, _this3.getTreeDataSource(treeDataSource, selected));
        }
      });
    }
  }]);

  return Demo;
}(_react["default"].Component);

_reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(Demo, null), document.createElement('transfer-demo-7'));