'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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var edit = function edit(_ref) {
  var _ref$getEditId = _ref.getEditId;
  var getEditId = _ref$getEditId === undefined ? function () {} : _ref$getEditId;
  var _ref$getEditProperty = _ref.getEditProperty;
  var getEditProperty = _ref$getEditProperty === undefined ? function () {} : _ref$getEditProperty;
  var _ref$onActivate = _ref.onActivate;
  var onActivate = _ref$onActivate === undefined ? function () {} : _ref$onActivate;
  var _ref$onValue = _ref.onValue;

  var _onValue = _ref$onValue === undefined ? function () {} : _ref$onValue;

  return function (editor) {
    var Edit = function Edit(value, extraParameters) {
      var idx = getEditId(extraParameters);
      var editedCell = getEditProperty();

      if (editedCell === idx) {
        return {
          children: _react2.default.createElement(editor, {
            value: value,
            onValue: function onValue(v) {
              return _onValue(_extends({ value: v }, extraParameters));
            }
          })
        };
      }

      return {
        onClick: function onClick() {
          return onActivate(idx);
        }
      };
    };
    Edit.propTypes = {
      value: _react2.default.PropTypes.any,
      extraParameters: _react2.default.PropTypes.shape({
        cellData: _react2.default.PropTypes.object.isRequired,
        property: _react2.default.PropTypes.string.isRequired
      })
    };

    return Edit;
  };
};

var sort = function sort(_ref2) {
  var _ref2$getSortingColum = _ref2.getSortingColumns;
  var getSortingColumns = _ref2$getSortingColum === undefined ? function () {
    return [];
  } : _ref2$getSortingColum;
  var _ref2$onSort = _ref2.onSort;
  var onSort = _ref2$onSort === undefined ? function () {} : _ref2$onSort;
  return function (property) {
    var Sort = function Sort() {
      var columns = getSortingColumns();
      var index = columns.map(function (c) {
        return c.property;
      }).indexOf(property);
      var headerClass = '';

      if (index >= 0) {
        headerClass = 'sort-' + columns[index].sort;
      }

      return {
        className: headerClass,
        onClick: function onClick() {
          return onSort(property);
        }
      };
    };
    Sort.propTypes = {
      property: _react2.default.PropTypes.string.isRequired
    };

    return Sort;
  };
};

exports.default = {
  edit: edit,
  sort: sort
};