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 { tagPropType, mapToCssModules } from './Shared/helper.js';
import { Link } from 'react-router-dom';

//component - CoreUI / CLink

var CLink = function CLink(props) {
  var className = props.className,
      cssModule = props.cssModule,
      innerRef = props.innerRef,
      active = props.active,
      disabled = props.disabled,
      href = props.href,
      to = props.to,
      attributes = _objectWithoutProperties(props, ['className', 'cssModule', 'innerRef', 'active', 'disabled', 'href', 'to']);

  var href2 = href;

  var onClick = function onClick(e) {
    if (props.disabled) {
      e.preventDefault();
      return;
    }
    if (href2 === '#') {
      e.preventDefault();
    }
    if (props.onClick) {
      props.onClick(e);
    }
  };

  // render

  var classes = mapToCssModules(classNames(className, active ? 'active' : null, disabled ? 'disabled' : null), cssModule);

  //<span {...attributes} className={classes} ref={innerRef} />

  to || href2 || (href2 = '#');

  return to ? React.createElement(Link, _extends({ to: to }, attributes, { className: classes, ref: innerRef })) : React.createElement('a', _extends({ href: href2 }, attributes, { className: classes, onClick: onClick, ref: innerRef }));
};

CLink.propTypes = process.env.NODE_ENV !== "production" ? {
  className: PropTypes.string,
  cssModule: PropTypes.object,
  //
  innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  active: PropTypes.bool,
  disabled: PropTypes.bool,
  href: PropTypes.string,
  to: PropTypes.string
} : {};

CLink.defaultProps = {};

export default CLink;