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

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

import React, { forwardRef } from 'react';

var Radio = forwardRef(function (_ref, ref) {
  var value = _ref.value,
      checked = _ref.checked,
      _ref$inputAttribute = _ref.inputAttribute,
      inputAttribute = _ref$inputAttribute === undefined ? {} : _ref$inputAttribute,
      caption = _ref.caption,
      _ref$captionAttribute = _ref.captionAttribute,
      captionAttribute = _ref$captionAttribute === undefined ? {} : _ref$captionAttribute,
      _onClick = _ref.onClick,
      others = _objectWithoutProperties(_ref, ['value', 'checked', 'inputAttribute', 'caption', 'captionAttribute', 'onClick']);

  return React.createElement(
    'div',
    _extends({ ref: ref }, others, { onClick: function onClick(e) {
        if (_onClick) _onClick(e, e.target.getAttribute('data-checked') === 'true');
      }, 'data-checked': checked, 'data-name': value, className: 'radio' + (others.className ? ' ' + others.className : '') }),
    React.createElement('span', _extends({}, inputAttribute, { className: 'radio-input' + (inputAttribute.className ? ' ' + inputAttribute.className : '') })),
    caption && React.createElement(
      'span',
      _extends({}, captionAttribute, { className: 'radio-caption' + (captionAttribute.className ? ' ' + captionAttribute.className : '') }),
      caption
    )
  );
});

export default Radio;