'use strict';

exports.__esModule = true;
exports.default = undefined;

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _instance = require('./instance');

var _instance2 = _interopRequireDefault(_instance);

var _Button = require('./../Button');

var _Button2 = _interopRequireDefault(_Button);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

var ListPull = (_temp = _class = function (_Component) {
  _inherits(ListPull, _Component);

  function ListPull(props) {
    _classCallCheck(this, ListPull);

    return _possibleConstructorReturn(this, _Component.call(this, props));
  }

  ListPull.prototype.componentDidMount = function componentDidMount() {
    var _this2 = this;

    var instance = new _instance2.default(this.$el, {
      onClick: function onClick(e) {
        var index = e.target.getAttribute('data-index');
        var item = _this2.props.list[index];
        var btn = null;
        var i = e.target.getAttribute('data-i');
        var direction = e.target.getAttribute('data-direction');
        if (i && direction) {
          if (direction === 'left') {
            btn = item.lButtons[i];
          } else {
            btn = item.rButtons[i];
          }
        }
        if (_this2.props.onClick) _this2.props.onClick(item, index, btn);
      },
      onShowedLeft: this.props.onShowedLeft,
      onShowedRight: this.props.onShowedRight
    });
    this.instance = instance;
  };

  ListPull.prototype.render = function render() {
    var _this3 = this;

    var _props = this.props,
        list = _props.list,
        onShowedLeft = _props.onShowedLeft,
        onShowedRight = _props.onShowedRight,
        others = _objectWithoutProperties(_props, ['list', 'onShowedLeft', 'onShowedRight']);

    return _react2.default.createElement(
      'ul',
      { ref: function ref(el) {
          _this3.$el = el;
        }, className: 'list-pull' + (others.className ? ' ' + others.className : '') },
      list.map(function (item, index) {
        return _react2.default.createElement(
          'li',
          { key: 'button' + index, 'data-index': '' + index, className: 'border-b list-pull-li' },
          item.lButtons && item.lButtons.length && _react2.default.createElement(
            'div',
            { className: 'list-pull-left' },
            item.lButtons.map(function (button, i) {
              return _react2.default.createElement(
                _Button2.default,
                { key: 'button' + i, 'data-index': '' + index, 'data-i': '' + i, 'data-direction': 'left', className: 'list-pull-button' + (button.className ? ' ' + button.className : ''), style: button.style },
                button.value
              );
            })
          ),
          _react2.default.createElement(
            'div',
            { className: 'list-pull-handler', 'data-index': '' + index },
            item.container
          ),
          item.rButtons && item.rButtons.length && _react2.default.createElement(
            'div',
            { className: 'list-pull-right' },
            item.rButtons.map(function (button, i) {
              return _react2.default.createElement(
                _Button2.default,
                { key: 'button' + i, 'data-index': '' + index, 'data-i': '' + i, 'data-direction': 'right', className: 'list-pull-button' + (button.className ? ' ' + button.className : ''), style: button.style },
                button.value
              );
            })
          )
        );
      })
    );
  };

  return ListPull;
}(_react.Component), _class.defaultProps = {}, _temp);
exports.default = ListPull;
ListPull.propTypes = process.env.NODE_ENV !== "production" ? {
  list: _propTypes2.default.array, // [{container: node, lButtons: [{value: '按钮文字', className: 'warn', style: object}], rButtons: 同lButtons}]
  onClick: _propTypes2.default.func,
  onShowedLeft: _propTypes2.default.func,
  onShowedRight: _propTypes2.default.func
} : {};
module.exports = exports['default'];