'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; }; /* eslint-disable no-shadow */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var boolean = function boolean() {
  var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

  var props = _ref.props;

  var Boolean = function Boolean(_ref2) {
    var value = _ref2.value;
    var onValue = _ref2.onValue;
    return _react2.default.createElement(
      'div',
      props,
      _react2.default.createElement(
        'button',
        {
          disabled: value,
          onClick: function onClick() {
            return onValue(true);
          }
        },
        '✓'
      ),
      _react2.default.createElement(
        'button',
        {
          disabled: !value,
          onClick: function onClick() {
            return onValue(false);
          }
        },
        '✗'
      )
    );
  };
  Boolean.propTypes = {
    value: _react2.default.PropTypes.any,
    onClick: _react2.default.PropTypes.func,
    onValue: _react2.default.PropTypes.func
  };

  return Boolean;
};

var dropdown = function dropdown(_ref3) {
  var options = _ref3.options;
  var _ref3$fields = _ref3.fields;
  var fields = _ref3$fields === undefined ? {
    name: 'name',
    value: 'value'
  } : _ref3$fields;
  var props = _ref3.props;

  var Dropdown = function Dropdown(_ref4) {
    var value = _ref4.value;
    var onValue = _ref4.onValue;

    var edit = function edit(_ref5) {
      var value = _ref5.target.value;
      return onValue(value);
    }; // eslint-disable-line max-len, no-shadow, react/prop-types

    return _react2.default.createElement(
      'select',
      _extends({ onBlur: edit, onChange: edit, value: value }, props),
      options.map(function (option, i) {
        return _react2.default.createElement(
          'option',
          { key: i, value: option[fields.value] },
          option[fields.name]
        );
      })
    );
  };
  Dropdown.propTypes = {
    value: _react2.default.PropTypes.string.isRequired,
    onValue: _react2.default.PropTypes.func.isRequired
  };

  return Dropdown;
};

var input = function input() {
  var _ref6 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

  var props = _ref6.props;

  var Input = function Input(_ref7) {
    var value = _ref7.value;
    var onValue = _ref7.onValue;

    var onKeyUp = function onKeyUp(_ref8) {
      var key = _ref8.key;
      var value = _ref8.target.value;
      return key === 'Enter' && onValue(value);
    };
    var onBlur = function onBlur(_ref9) {
      var target = _ref9.target;
      return onValue(target.value);
    }; // eslint-disable-line react/prop-types

    return _react2.default.createElement('input', _extends({ defaultValue: value, onKeyUp: onKeyUp, onBlur: onBlur }, props));
  };
  Input.propTypes = {
    value: _react2.default.PropTypes.string,
    onValue: _react2.default.PropTypes.func
  };

  return Input;
};

exports.default = {
  boolean: boolean,
  dropdown: dropdown,
  input: input
};