(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(['exports', 'react', 'classnames', './px-table-view.scss', './TableRow'], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require('react'), require('classnames'), require('./px-table-view.scss'), require('./TableRow'));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.react, global.classnames, global.pxTableView, global.TableRow);
    global.index = mod.exports;
  }
})(this, function (exports, _react, _classnames, _pxTableView, _TableRow) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });

  var _react2 = _interopRequireDefault(_react);

  var _classnames2 = _interopRequireDefault(_classnames);

  var _pxTableView2 = _interopRequireDefault(_pxTableView);

  var _TableRow2 = _interopRequireDefault(_TableRow);

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

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

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

  var _createClass = 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);
      }
    }

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

  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 TableView = function (_React$Component) {
    _inherits(TableView, _React$Component);

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

      var _this = _possibleConstructorReturn(this, (TableView.__proto__ || Object.getPrototypeOf(TableView)).call(this, props));

      _this.displayName = 'TableView';
      _this.renderRow = _this.renderRow.bind(_this);
      return _this;
    }

    _createClass(TableView, [{
      key: '_handleSelect',
      value: function _handleSelect(e) {
        if (this.props.onSelect) {
          this.props.onSelect(e);
        }
      }
    }, {
      key: 'renderRow',
      value: function renderRow(_ref) {
        var key = _ref.key,
            index = _ref.index,
            isScrolling = _ref.isScrolling,
            isVisible = _ref.isVisible,
            style = _ref.style;

        var content = this.props.items[index];
        return _react2.default.createElement(_TableRow2.default, _extends({
          tappable: this.props.tappable,
          key: key,
          index: index
        }, content, {
          onClick: this._handleSelect }));
      }
    }, {
      key: 'render',
      value: function render() {
        var _this2 = this;

        var _props = this.props,
            _props$style = _props.style,
            style = _props$style === undefined ? {
          outline: 'none'
        } : _props$style,
            _props$items = _props.items,
            items = _props$items === undefined ? [] : _props$items,
            selectedItem = _props.selectedItem,
            selected = _props.selected,
            tappable = _props.tappable,
            size = _props.size,
            _props$height = _props.height,
            height = _props$height === undefined ? 300 : _props$height,
            _props$width = _props.width,
            width = _props$width === undefined ? 320 : _props$width,
            _props$rowHeight = _props.rowHeight,
            rowHeight = _props$rowHeight === undefined ? 44 : _props$rowHeight,
            children = _props.children;


        var baseClassnames = (0, _classnames2.default)('px-table-view', { 'px-table-view--flush': size === 'flush' }, { 'px-table-view--tiny': size === 'tiny' }, { 'px-table-view--small': size === 'small' }, { 'px-table-view--regular': size === 'regular' }, { 'px-table-view--large': size === 'large' }, { 'px-table-view--huge': size === 'huge' });
        var tableViewClassnames = (0, _classnames2.default)('table-view', { 'table-view--flush': size === 'flush' }, { 'table-view--tiny': size === 'tiny' }, { 'table-view--small': size === 'small' }, { 'table-view--regular': size === 'regular' }, { 'table-view--large': size === 'large' }, { 'table-view--huge': size === 'huge' });

        return _react2.default.createElement(
          'div',
          { className: baseClassnames },
          children,
          items && items.map(function (item, index) {
            return _react2.default.createElement(_TableRow2.default, _extends({
              tappable: _this2.props.tappable,
              key: index,
              index: index
            }, item, {
              onClick: _this2._handleSelect }));
          })
        );
      }
    }]);

    return TableView;
  }(_react2.default.Component);

  TableView.defaultProps = {
    items: []
  };

  exports.default = TableView;
});