"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var React = _interopRequireWildcard(require("react"));
var _uiHelpers = require("@megafon/ui-helpers");
var _setRelAttribute = require("../../../helpers/setRelAttribute");
var _useResolutions2 = _interopRequireDefault(require("../../../hooks/useResolutions"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var cn = (0, _uiHelpers.cnCreate)('mfui-blog-box-tile');
var BlogBoxTile = function BlogBoxTile(_ref) {
  var date = _ref.date,
    title = _ref.title,
    href = _ref.href,
    target = _ref.target,
    rel = _ref.rel,
    _ref$image = _ref.image,
    srcMobile = _ref$image.srcMobile,
    srcDesktop = _ref$image.srcDesktop,
    srcThumbnail = _ref$image.srcThumbnail,
    _ref$image$alt = _ref$image.alt,
    alt = _ref$image$alt === void 0 ? 'image' : _ref$image$alt,
    view = _ref.view,
    classes = _ref.classes;
  var _useResolutions = (0, _useResolutions2["default"])(),
    isMobile = _useResolutions.isMobile;
  var isViewThumbnail = view === 'thumbnail';
  var currentRel = (0, _setRelAttribute.setRelAttribute)(rel, target);
  var renderImage = function renderImage() {
    if (isViewThumbnail) {
      return isMobile ? null : /*#__PURE__*/React.createElement("picture", {
        className: cn('picture')
      }, /*#__PURE__*/React.createElement("img", {
        className: cn('image'),
        src: srcThumbnail,
        alt: alt
      }));
    }
    return /*#__PURE__*/React.createElement("picture", {
      className: cn('picture')
    }, /*#__PURE__*/React.createElement("source", {
      media: "(min-width: ".concat(_uiHelpers.breakpoints.DESKTOP_SMALL_START, "px)"),
      srcSet: srcDesktop
    }), /*#__PURE__*/React.createElement("img", {
      className: cn('image'),
      src: srcMobile,
      alt: alt
    }));
  };
  return /*#__PURE__*/React.createElement("a", {
    className: cn({
      view: view
    }),
    href: href,
    target: target,
    rel: currentRel
  }, renderImage(), /*#__PURE__*/React.createElement("div", {
    className: cn('content')
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('date')
  }, date), /*#__PURE__*/React.createElement("div", {
    className: cn('title', [classes === null || classes === void 0 ? void 0 : classes.title])
  }, title)));
};
var _default = exports["default"] = BlogBoxTile;