"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _base = _interopRequireDefault(require("@emotion/styled/base"));
var _react = _interopRequireDefault(require("react"));
var _reactRedux = require("react-redux");
var _reactRouterDom = require("react-router-dom");
var _decapCmsUiDefault = require("decap-cms-ui-default");
var _media = require("../../../actions/media");
var _collectionViews = require("../../../constants/collectionViews");
var _medias = require("../../../reducers/medias");
var _collections = require("../../../reducers/collections");
var _react2 = require("@emotion/react");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
const ListCard = /*#__PURE__*/(0, _base.default)("li", {
  target: "effeus48",
  label: "ListCard"
})(_decapCmsUiDefault.components.card, ";width:", _decapCmsUiDefault.lengths.topCardWidth, ";margin-left:12px;margin-bottom:10px;overflow:hidden;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const ListCardLink = /*#__PURE__*/(0, _base.default)(_reactRouterDom.Link, {
  target: "effeus47",
  label: "ListCardLink"
})("display:block;max-width:100%;padding:16px 20px;&:hover{background-color:", _decapCmsUiDefault.colors.foreground, ";}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const GridCard = /*#__PURE__*/(0, _base.default)("li", {
  target: "effeus46",
  label: "GridCard"
})(_decapCmsUiDefault.components.card, ";flex:0 0 335px;height:240px;overflow:hidden;margin-left:12px;margin-bottom:16px;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const GridCardLink = /*#__PURE__*/(0, _base.default)(_reactRouterDom.Link, {
  target: "effeus45",
  label: "GridCardLink"
})("display:block;height:100%;outline-offset:-2px;&,&:hover{background-color:", _decapCmsUiDefault.colors.foreground, ";color:", _decapCmsUiDefault.colors.text, ";}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const CollectionLabel = /*#__PURE__*/(0, _base.default)("h2", {
  target: "effeus44",
  label: "CollectionLabel"
})("font-size:12px;color:", _decapCmsUiDefault.colors.textLead, ";text-transform:uppercase;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const ListCardTitle = /*#__PURE__*/(0, _base.default)("h2", {
  target: "effeus43",
  label: "ListCardTitle"
})(process.env.NODE_ENV === "production" ? {
  name: "1ykowef",
  styles: "margin-bottom:0"
} : {
  name: "1ykowef",
  styles: "margin-bottom:0",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
const CardHeading = /*#__PURE__*/(0, _base.default)("h2", {
  target: "effeus42",
  label: "CardHeading"
})(process.env.NODE_ENV === "production" ? {
  name: "m483k0",
  styles: "margin:0 0 2px"
} : {
  name: "m483k0",
  styles: "margin:0 0 2px",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
const CardBody = /*#__PURE__*/(0, _base.default)("div", {
  target: "effeus41",
  label: "CardBody"
})("padding:16px 20px;height:90px;position:relative;margin-bottom:", props => props.hasImage && 0, ";&:after{content:'';position:absolute;display:block;z-index:", _decapCmsUiDefault.zIndex.zIndex1, ";bottom:0;left:-20%;height:140%;width:140%;box-shadow:inset 0 -15px 24px ", _decapCmsUiDefault.colorsRaw.white, ";}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
const CardImage = /*#__PURE__*/(0, _base.default)("div", {
  target: "effeus40",
  label: "CardImage"
})("background-image:url(", props => props.src, ");background-position:center center;background-size:cover;background-repeat:no-repeat;height:150px;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5836 characters] */"));
function EntryCard({
  path,
  summary,
  image,
  imageField,
  collectionLabel,
  viewStyle = _collectionViews.VIEW_STYLE_LIST,
  getAsset
}) {
  if (viewStyle === _collectionViews.VIEW_STYLE_LIST) {
    return (0, _react2.jsx)(ListCard, null, (0, _react2.jsx)(ListCardLink, {
      to: path
    }, collectionLabel ? (0, _react2.jsx)(CollectionLabel, null, collectionLabel) : null, (0, _react2.jsx)(ListCardTitle, null, summary)));
  }
  if (viewStyle === _collectionViews.VIEW_STYLE_GRID) {
    return (0, _react2.jsx)(GridCard, null, (0, _react2.jsx)(GridCardLink, {
      to: path
    }, (0, _react2.jsx)(CardBody, {
      hasImage: image
    }, collectionLabel ? (0, _react2.jsx)(CollectionLabel, null, collectionLabel) : null, (0, _react2.jsx)(CardHeading, null, summary)), image ? (0, _react2.jsx)(CardImage, {
      src: getAsset(image, imageField).toString()
    }) : null));
  }
}
function mapStateToProps(state, ownProps) {
  var _collection$get;
  const {
    entry,
    inferredFields,
    collection
  } = ownProps;
  const entryData = entry.get('data');
  const summary = (0, _collections.selectEntryCollectionTitle)(collection, entry);
  let image = entryData.get(inferredFields.imageField);
  if (image) {
    image = encodeURI(image);
  }
  const isLoadingAsset = (0, _medias.selectIsLoadingAsset)(state.medias);
  return {
    summary,
    path: `/collections/${collection.get('name')}/entries/${entry.get('slug')}`,
    image,
    imageFolder: (_collection$get = collection.get('fields')) === null || _collection$get === void 0 ? void 0 : _collection$get.find(f => f.get('name') === inferredFields.imageField && f.get('widget') === 'image'),
    isLoadingAsset
  };
}
function mapDispatchToProps(dispatch) {
  return {
    boundGetAsset: (collection, entry) => (0, _media.boundGetAsset)(dispatch, collection, entry)
  };
}
function mergeProps(stateProps, dispatchProps, ownProps) {
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, stateProps), dispatchProps), ownProps), {}, {
    getAsset: dispatchProps.boundGetAsset(ownProps.collection, ownProps.entry)
  });
}
const ConnectedEntryCard = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps, mergeProps)(EntryCard);
var _default = exports.default = ConnectedEntryCard;