var _excluded = ["type", "value", "checked", "disabled", "inputAttribute", "caption", "captionAttribute", "onClick"];

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { forwardRef } from 'react';
var Checkbox = forwardRef(function (_ref, ref) {
  var type = _ref.type,
      value = _ref.value,
      checked = _ref.checked,
      disabled = _ref.disabled,
      _ref$inputAttribute = _ref.inputAttribute,
      inputAttribute = _ref$inputAttribute === void 0 ? {} : _ref$inputAttribute,
      caption = _ref.caption,
      _ref$captionAttribute = _ref.captionAttribute,
      captionAttribute = _ref$captionAttribute === void 0 ? {} : _ref$captionAttribute,
      onClick = _ref.onClick,
      others = _objectWithoutPropertiesLoose(_ref, _excluded);

  function clickHandler(e, isChecked) {
    if (disabled) return;
    if (onClick) onClick(e, isChecked);
  }

  var typeClassPrefix = type === 'radio' ? 'radio' : 'checkbox';
  return /*#__PURE__*/React.createElement("div", _extends({
    ref: ref
  }, others, {
    onClick: function onClick(e) {
      clickHandler(e, e.target.getAttribute('data-checked') === 'true');
    },
    disabled: disabled,
    "data-checked": checked,
    "data-value": value,
    className: "" + typeClassPrefix + (others.className ? ' ' + others.className : '')
  }), /*#__PURE__*/React.createElement("span", _extends({}, inputAttribute, {
    className: typeClassPrefix + "-input" + (inputAttribute.className ? ' ' + inputAttribute.className : '')
  })), caption && /*#__PURE__*/React.createElement("span", _extends({}, captionAttribute, {
    className: typeClassPrefix + "-caption" + (captionAttribute.className ? ' ' + captionAttribute.className : '')
  }), caption));
});
export default Checkbox;