'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

function _default(_ref, editor) {
  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;

  var Edit = function Edit(_ref2) {
    var cellData = _ref2.cellData;
    var property = _ref2.property;
    var cellKey = _ref2.cellKey;

    var idx = cellKey + '-' + property;
    var editedCell = getEditProperty();

    if (editedCell === idx) {
      return {
        children: _react2.default.createElement(editor, {
          value: cellData[property],
          onValue: function onValue(v) {
            return _onValue(v, cellData, property);
          }
        })
      };
    }

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

  return Edit;
}
exports.default = _default;