'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 _helper = require('./Shared/helper.js');

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 / CImg

var CImg = function CImg(props) {
  var className = props.className,
      cssModule = props.cssModule,
      innerRef = props.innerRef,
      fluid = props.fluid,
      block = props.block,
      thumbnail = props.thumbnail,
      shape = props.shape,
      align = props.align,
      alt = props.alt,
      src = props.src,
      width = props.width,
      height = props.height,
      placeholderColor = props.placeholderColor,
      active = props.active,
      fluidGrow = props.fluidGrow,
      attributes = _objectWithoutProperties(props, ['className', 'cssModule', 'innerRef', 'fluid', 'block', 'thumbnail', 'shape', 'align', 'alt', 'src', 'width', 'height', 'placeholderColor', 'active', 'fluidGrow']);

  // vars

  var isActive = function () {
    //active prop is present in CImgLazy component, here always undefined
    return active !== false;
  }();

  var alignClass = function () {
    if (align === 'center') {
      return 'mx-auto';
    } else if (align === 'right') {
      return 'float-right';
    } else if (align === 'left') {
      return 'float-left';
    }
    return null;
  }();

  // render

  var classes = (0, _helper.mapToCssModules)((0, _classnames2.default)(className, alignClass, thumbnail ? 'img-thumbnail' : null, fluid || fluidGrow ? 'img-fluid' : null, fluidGrow ? 'w-100' : null, block ? 'd-block' : null, shape ? shape : null), cssModule);

  return src && isActive ? _react2.default.createElement('img', _extends({}, attributes, {
    className: classes,
    src: src,
    alt: alt,
    width: width,
    height: height,
    ref: innerRef })) : _react2.default.createElement('svg', _extends({}, attributes, {
    className: classes,
    width: width,
    height: height,
    style: { 'backgroundColor': isActive ? placeholderColor : 'transparent' },
    ref: innerRef
  }));
};

CImg.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: _helper.tagPropType,
  className: _propTypes2.default.string,
  cssModule: _propTypes2.default.object,
  //
  innerRef: _propTypes2.default.oneOfType([_propTypes2.default.object, _propTypes2.default.func, _propTypes2.default.string]),
  src: _propTypes2.default.string,
  alt: _propTypes2.default.string,
  width: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
  height: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
  block: _propTypes2.default.bool,
  fluid: _propTypes2.default.bool,
  fluidGrow: _propTypes2.default.bool,
  shape: _propTypes2.default.string, //oneOf(['', 'rounded']),
  thumbnail: _propTypes2.default.bool,
  align: _propTypes2.default.oneOf(['', 'left', 'right', 'center']),
  placeholderColor: _propTypes2.default.string
} : {};

CImg.defaultProps = {
  placeholderColor: 'transparent'
};

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