"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _js = require("../../globals/js");

var _excluded = ["children", "className", "image", "isExternal", "isLink", "metadata", "subTitle", "title", "kind", "url", "cardWidth", "cardHeight"];
var prefix = _js.settings.prefix;
/**
 * Cards are a convenient means of displaying content composed of different types of objects. It is a multi usage component which creates boxes that are usually teasing some kind of content. */

var Card = function Card(_ref) {
  var _classNames;

  var children = _ref.children,
      className = _ref.className,
      image = _ref.image,
      isExternal = _ref.isExternal,
      isLink = _ref.isLink,
      metadata = _ref.metadata,
      subTitle = _ref.subTitle,
      title = _ref.title,
      kind = _ref.kind,
      url = _ref.url,
      cardWidth = _ref.cardWidth,
      cardHeight = _ref.cardHeight,
      other = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var style = kind == 'overlay' ? {
    backgroundImage: "url(".concat(image, ")")
  } : {};
  var pagewidth = cardWidth ? cardWidth : '300px';
  var pageheight = cardHeight ? cardHeight : '260px';
  var wrapperClasses = (0, _classnames.default)(["".concat(prefix, "--card-box")], (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--photo-cardnew--").concat(kind), kind), (0, _defineProperty2.default)(_classNames, "".concat(prefix, "--photo-cardnew--link"), isLink), (0, _defineProperty2.default)(_classNames, "".concat(className), className), _classNames));

  var content = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, kind === 'overlay' ? /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(prefix, "--photo-cardnew__background"),
    style: style
  }) : null, image && kind === 'simple-card' ? /*#__PURE__*/_react.default.createElement("img", {
    src: image,
    alt: title,
    className: "".concat(prefix, "--header-photo")
  }) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(prefix, "--photo-cardnew__info")
  }, /*#__PURE__*/_react.default.createElement("div", null, kind === 'overlay' && /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(prefix, "--photo-cardnew__info__background"),
    style: style
  }), metadata && /*#__PURE__*/_react.default.createElement("p", {
    className: "".concat(prefix, "--photo-cardnew__info__metadata")
  }, metadata), title && /*#__PURE__*/_react.default.createElement("h3", {
    className: "".concat(prefix, "--photo-cardnew__info__title")
  }, title), subTitle && /*#__PURE__*/_react.default.createElement("p", {
    className: "".concat(prefix, "--photo-cardnew__info__subtitle")
  }, subTitle))), children);

  return isLink ? /*#__PURE__*/_react.default.createElement("div", {
    className: wrapperClasses,
    style: {
      width: pagewidth,
      minHeight: pageheight
    }
  }, /*#__PURE__*/_react.default.createElement("a", (0, _extends2.default)({
    href: url,
    target: isExternal ? '_blank' : '',
    style: {
      width: pagewidth,
      minHeight: pageheight
    }
  }, other), content)) : /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    className: wrapperClasses
  }, other, {
    style: {
      width: pagewidth,
      minHeight: pageheight
    }
  }), content);
};

Card.propTypes = {
  /**
   Additional className which will be added
  */
  className: _propTypes.default.string,

  /**
   An optimized photograph
  */
  image: _propTypes.default.string,

  /**
  isExternal if true, opens link in a different window
  */
  isExternal: _propTypes.default.bool,

  /**
  Render the Card as link
  */
  isLink: _propTypes.default.bool,

  /**
  A short sentence to explain the content of the node (max 180 characters) 
  */
  subTitle: _propTypes.default.node,

  /**
   A search-friendly title (ideally 50 characters, max 100) 
  */
  title: _propTypes.default.node,

  /**
  Additional metadatas
  */
  metadata: _propTypes.default.string,

  /**
  Kind of Card
  */
  kind: _propTypes.default.oneOf(['simple-card', 'overlay']).isRequired,

  /**
  The URL where the content uploaded is located.
  */
  url: _propTypes.default.string,

  /**
   * override default card width with preferred width
   */
  cardWidth: _propTypes.default.string,

  /**
   * override default card width with preferred width
   */
  cardHeight: _propTypes.default.string
};
Card.defaultProps = {
  isLink: true
};
var _default = Card;
exports.default = _default;