'use strict';

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

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

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

var _getClassName2 = require('babel-plugin-react-css-modules/dist/browser/getClassName');

var _getClassName3 = _interopRequireDefault(_getClassName2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _styleModuleImportMap = {
  './table.scss': {
    'table-wrapper': 'flive_table_table-wrapper',
    'table': 'flive_table_table',
    'table-row-column': 'flive_table_table-row-column',
    'table--header': 'flive_table_table--header',
    'table--footer': 'flive_table_table--footer',
    'table-row': 'flive_table_table-row',
    'white': 'flive_table_white',
    'grey': 'flive_table_grey',
    'table-row--selected': 'flive_table_table-row--selected',
    'table-row-column--not--selectable': 'flive_table_table-row-column--not--selectable',
    'table-row-column--checkbox': 'flive_table_table-row-column--checkbox',
    'table-row-column--selected': 'flive_table_table-row-column--selected',
    'table-row-column--selectable': 'flive_table_table-row-column--selectable',
    'table-row-column--sortable': 'flive_table_table-row-column--sortable',
    'table-row-column--order-asc': 'flive_table_table-row-column--order-asc',
    'table-row-column--order-desc': 'flive_table_table-row-column--order-desc',
    'table-row-column--sorted': 'flive_table_table-row-column--sorted',
    'table-body': 'flive_table_table-body',
    'wrapper-fixed': 'flive_table_wrapper-fixed',
    'wrapper-scroll': 'flive_table_wrapper-scroll',
    'table--scrolled': 'flive_table_table--scrolled',
    'filter-wrapper': 'flive_table_filter-wrapper',
    'filter': 'flive_table_filter'
  }
};

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 TableRowColumn = function (_PureComponent) {
  _inherits(TableRowColumn, _PureComponent);

  function TableRowColumn() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, TableRowColumn);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TableRowColumn.__proto__ || Object.getPrototypeOf(TableRowColumn)).call.apply(_ref, [this].concat(args))), _this), _this.onClick = function (event) {
      var _this$props = _this.props,
          onClick = _this$props.onClick,
          columnNumber = _this$props.columnNumber,
          order = _this$props.order,
          sort = _this$props.sort,
          sortedOrder = _this$props.sortedOrder;

      var restultOrder = order;
      if (sortedOrder) {
        restultOrder = sortedOrder === 'asc' ? 'desc' : 'asc';
      }
      if (onClick) {
        onClick(event, { columnNumber: columnNumber, order: restultOrder, sort: sort });
      }
      event.stopPropagation();
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(TableRowColumn, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          checkbox = _props.checkbox,
          selected = _props.selected,
          sort = _props.sort,
          sortedOrder = _props.sortedOrder,
          order = _props.order,
          selectable = _props.selectable,
          multiSelectable = _props.multiSelectable,
          className = _props.className,
          rest = _objectWithoutProperties(_props, ['checkbox', 'selected', 'sort', 'sortedOrder', 'order', 'selectable', 'multiSelectable', 'className']);

      delete rest.columnNumber;
      delete rest.onClick;
      return (
        // eslint-disable-next-line jsx-a11y/no-static-element-interactions
        _react2.default.createElement('td', _extends({
          onClick: this.onClick
        }, rest, {
          className: (className ? className + ' ' : '') + (0, _getClassName3.default)((0, _classnames2.default)('table-row-column', _defineProperty({
            'table-row-column--checkbox': checkbox,
            'table-row-column--selected': selected,
            'table-row-column--sortable': sort,
            'table-row-column--sorted': sortedOrder,
            'table-row-column--not--selectable': !selectable && !multiSelectable,
            'table-row-column--selectable': selectable
          }, 'table-row-column--order-' + (sortedOrder || order), sort && order)), _styleModuleImportMap)
        }))
      );
    }
  }]);

  return TableRowColumn;
}(_react.PureComponent);

TableRowColumn.propTypes = {
  className: _propTypes2.default.string,
  /**
   * Children passed to table row column.
   */
  children: _propTypes2.default.node,
  /**
   * @ignore in documentation
   * Number to identify the header row. This property
   * is automatically populated when used with TableBody.
   */
  columnNumber: _propTypes2.default.number,
  /**
   * Controls sortable.
   */
  sort: _propTypes2.default.array,
  sortedOrder: _propTypes2.default.string,
  order: _propTypes2.default.string,
  /**
   * Controls variant type checkbox.
   */
  checkbox: _propTypes2.default.bool,
  /**
   * Controls status selected.
   */
  selected: _propTypes2.default.bool,
  /**
   * @ignore in documentation
   * */
  onClick: _propTypes2.default.func,
  selectable: _propTypes2.default.bool,
  multiSelectable: _propTypes2.default.bool
};
TableRowColumn.defaultProps = {
  className: undefined,
  children: null,
  columnNumber: null,
  sort: null,
  sortedOrder: null,
  order: 'asc',
  checkbox: false,
  selected: false,
  onClick: null,
  selectable: false,
  multiSelectable: false
};
exports.default = TableRowColumn;
module.exports = exports['default'];