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 CLink from './CLink';

//component - CoreUI / CSidebarBrand

var CSidebarBrand = function CSidebarBrand(props) {
  var Tag = props.tag,
      children = props.children,
      className = props.className,
      custom = props.custom,
      innerRef = props.innerRef,
      img = props.img,
      imgFull = props.imgFull,
      imgMinimized = props.imgMinimized,
      wrappedInLink = props.wrappedInLink,
      linkClassName = props.linkClassName,
      linkProps = props.linkProps,
      attributes = _objectWithoutProperties(props, ['tag', 'children', 'className', 'custom', 'innerRef', 'img', 'imgFull', 'imgMinimized', 'wrappedInLink', 'linkClassName', 'linkProps']);

  var imgSrc = function imgSrc(brand) {
    return brand.src ? brand.src : '';
  };
  var imgWidth = function imgWidth(brand) {
    return brand.width ? brand.width : 'auto';
  };
  var imgHeight = function imgHeight(brand) {
    return brand.height ? brand.height : 'auto';
  };
  var imgAlt = function imgAlt(brand) {
    return brand.alt ? brand.alt : '';
  };
  var navbarBrandImg = function navbarBrandImg(props, classBrand, key) {
    var src = props.src,
        width = props.width,
        alt = props.alt,
        height = props.height,
        attributes = _objectWithoutProperties(props, ['src', 'width', 'alt', 'height']);

    return React.createElement('img', _extends({
      src: imgSrc(props),
      width: imgWidth(props),
      height: imgHeight(props),
      alt: imgAlt(props),
      className: classBrand
    }, attributes, {
      key: key.toString()
    }));
  };

  // render

  var classes = classNames(className, 'c-sidebar-brand');

  if (custom) {
    return React.createElement(
      Tag,
      _extends({ className: classes }, attributes, { ref: innerRef }),
      children
    );
  }

  var classesLink = classNames(linkClassName, 'c-sidebar-brand');

  var imgChildren = [];
  if (imgFull) {
    imgChildren.push(navbarBrandImg(imgFull || img, 'c-sidebar-brand-full', 1));
  }
  if (imgMinimized) {
    imgChildren.push(navbarBrandImg(imgMinimized || img, 'c-sidebar-brand-minimized', imgChildren.length + 1));
  }

  return React.createElement(
    Tag,
    _extends({}, attributes, { className: classes, ref: innerRef }),
    wrappedInLink ? React.createElement(
      CLink,
      _extends({ className: classesLink }, linkProps),
      imgChildren
    ) : imgChildren
  );
};

CSidebarBrand.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  children: PropTypes.node,
  className: PropTypes.string,
  custom: PropTypes.bool,
  //
  innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  img: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
  imgFull: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
  imgMinimized: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
  linkClassName: PropTypes.string,
  linkProps: PropTypes.object,
  wrappedInLink: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
} : {};

CSidebarBrand.defaultProps = {
  tag: 'div'
};

export default CSidebarBrand;