var _class, _temp;

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; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Instance from './instance';
import Button from './../Button';

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 Instance(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 React.createElement(
      'ul',
      { ref: function ref(el) {
          _this3.$el = el;
        }, className: 'list-pull' + (others.className ? ' ' + others.className : '') },
      list.map(function (item, index) {
        return React.createElement(
          'li',
          { key: 'button' + index, 'data-index': '' + index, className: 'border-b list-pull-li' },
          item.lButtons && item.lButtons.length && React.createElement(
            'div',
            { className: 'list-pull-left' },
            item.lButtons.map(function (button, i) {
              return React.createElement(
                Button,
                { 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
              );
            })
          ),
          React.createElement(
            'div',
            { className: 'list-pull-handler', 'data-index': '' + index },
            item.container
          ),
          item.rButtons && item.rButtons.length && React.createElement(
            'div',
            { className: 'list-pull-right' },
            item.rButtons.map(function (button, i) {
              return React.createElement(
                Button,
                { 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;
}(Component), _class.defaultProps = {}, _temp);
export { ListPull as default };
ListPull.propTypes = process.env.NODE_ENV !== "production" ? {
  list: PropTypes.array, // [{container: node, lButtons: [{value: '按钮文字', className: 'warn', style: object}], rButtons: 同lButtons}]
  onClick: PropTypes.func,
  onShowedLeft: PropTypes.func,
  onShowedRight: PropTypes.func
} : {};