'use strict';

exports.__esModule = 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; };

require('./style.scss');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

/**
 * A simple toggle.
 */
var Toggle = function Toggle(props) {
  var children = props.children,
      className = props.className,
      label = props.label,
      type = props.type;

  var ToggleClasses = ['Toggle', 'Toggle_' + type, className].filter(function (e) {
    return e;
  }).join(' ');

  return _react2.default.createElement(
    'label',
    { className: ToggleClasses },
    _react2.default.createElement('input', _extends({}, _extends({}, props, { children: null, style: null }), {
      className: 'Toggle-input',
      type: props.type === 'toggle' ? 'checkbox' : props.type
    })),
    _react2.default.createElement(
      'div',
      { className: 'Toggle-display' },
      _react2.default.createElement('i', { className: 'fa fa-check' })
    ),
    (label || children) && _react2.default.createElement(
      'span',
      { className: 'Toggle-label', title: label },
      label || children
    )
  );
};

Toggle.propTypes = process.env.NODE_ENV !== "production" ? {
  className: _propTypes2.default.string,
  label: _propTypes2.default.string,
  type: _propTypes2.default.oneOf(['checkbox', 'radio', 'toggle']),
  value: _propTypes2.default.any
} : {};

Toggle.defaultProps = {
  type: 'checkbox'
};

exports.default = Toggle;
module.exports = exports['default'];