'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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _CLink = require('./CLink');

var _CLink2 = _interopRequireDefault(_CLink);

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

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; }

//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 _react2.default.createElement('img', _extends({
      src: imgSrc(props),
      width: imgWidth(props),
      height: imgHeight(props),
      alt: imgAlt(props),
      className: classBrand
    }, attributes, {
      key: key.toString()
    }));
  };

  // render

  var classes = (0, _classnames2.default)(className, 'c-sidebar-brand');

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

  var classesLink = (0, _classnames2.default)(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 _react2.default.createElement(
    Tag,
    _extends({}, attributes, { className: classes, ref: innerRef }),
    wrappedInLink ? _react2.default.createElement(
      _CLink2.default,
      _extends({ className: classesLink }, linkProps),
      imgChildren
    ) : imgChildren
  );
};

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

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

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