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 from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules } from './Shared/helper.js';

//component - CoreUI / CCustomInput

var CCustomInput = function CCustomInput(props) {
  var children = props.children,
      className = props.className,
      cssModule = props.cssModule,
      innerRef = props.innerRef,
      label = props.label,
      inline = props.inline,
      valid = props.valid,
      invalid = props.invalid,
      bsSize = props.bsSize,
      wrapperProps = props.wrapperProps,
      attributes = _objectWithoutProperties(props, ['children', 'className', 'cssModule', 'innerRef', 'label', 'inline', 'valid', 'invalid', 'bsSize', 'wrapperProps']);

  //render

  var type = attributes.type;

  var customClass = mapToCssModules(classNames(className, 'custom-' + type, bsSize ? 'custom-' + type + '-' + bsSize : false), cssModule);

  var validationClassNames = mapToCssModules(classNames(invalid && 'is-invalid', valid && 'is-valid'), cssModule);

  if (type === 'select') {
    return React.createElement(
      'select',
      _extends({}, attributes, { className: classNames(validationClassNames, customClass), ref: innerRef }),
      children
    );
  }

  if (type === 'file') {
    return React.createElement(
      'div',
      _extends({ className: customClass }, wrapperProps, { ref: innerRef }),
      React.createElement('input', _extends({}, attributes, { className: classNames(validationClassNames, mapToCssModules('custom-file-input', cssModule)) })),
      React.createElement(
        'label',
        { className: mapToCssModules('custom-file-label', cssModule), htmlFor: attributes.id },
        label || 'Choose file'
      )
    );
  }

  if (type !== 'checkbox' && type !== 'radio' && type !== 'switch') {
    return React.createElement('input', _extends({}, attributes, { className: classNames(validationClassNames, customClass), ref: innerRef }));
  }

  var wrapperClasses = classNames(customClass, mapToCssModules(classNames('custom-control', { 'custom-control-inline': inline }), cssModule));

  return React.createElement(
    'div',
    _extends({}, wrapperProps, { className: wrapperClasses }),
    React.createElement('input', _extends({}, attributes, {
      type: type === 'switch' ? 'checkbox' : type,
      className: classNames(validationClassNames, mapToCssModules('custom-control-input', cssModule)),
      ref: innerRef
    })),
    React.createElement(
      'label',
      { className: mapToCssModules('custom-control-label', cssModule), htmlFor: attributes.id },
      label
    ),
    children
  );
};

CCustomInput.propTypes = process.env.NODE_ENV !== "production" ? {
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.array, PropTypes.func]),
  className: PropTypes.string,
  cssModule: PropTypes.object,
  //
  innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
  type: PropTypes.string.isRequired,
  label: PropTypes.node,
  inline: PropTypes.bool,
  valid: PropTypes.bool,
  invalid: PropTypes.bool,
  bsSize: PropTypes.string,
  wrapperProps: PropTypes.object
} : {};

export default CCustomInput;