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

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

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

    var edit = function edit(_ref3) {
      var value = _ref3.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;
};