"use strict";

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

exports.__esModule = true;
exports.BlogListing = void 0;

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

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _lib = require("@sentecacommerce-theme/lib");

var _Common = require("../../../Common");

var _Components = require("./Components");

var _templateObject, _templateObject2, _templateObject3, _templateObject4;

var BlogListing = function BlogListing() {
  var _useConfigState = (0, _lib.useConfigState)(),
      blogConfig = _useConfigState.blogConfig;

  var labels = (0, _lib.useLocalLabels)();

  var _useCmsContentList = (0, _lib.useCmsContentList)({
    type: blogConfig.key,
    limit: blogConfig.limit || 6,
    sort: 'createdAt;desc'
  }),
      data = _useCmsContentList.data;

  if (!data) {
    return /*#__PURE__*/_react["default"].createElement(LoaderContainer, null, /*#__PURE__*/_react["default"].createElement(_Common.Loader, null));
  }

  var results = data.results,
      rest = (0, _objectWithoutPropertiesLoose2["default"])(data, ["results"]);
  return !!results.length ? /*#__PURE__*/_react["default"].createElement(Container, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.title), results == null ? void 0 : results.map(function (content) {
    return /*#__PURE__*/_react["default"].createElement(_Components.BlogItem, {
      data: content,
      key: content._id,
      slug: content.key
    });
  }), /*#__PURE__*/_react["default"].createElement(_Components.Pagination, rest)) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.title), /*#__PURE__*/_react["default"].createElement(NoPostsContainer, null, /*#__PURE__*/_react["default"].createElement("p", null, labels.noPosts)));
};

exports.BlogListing = BlogListing;

var LoaderContainer = _styledComponents["default"].div.attrs({
  className: 'd-flex align-items-center justify-content-center'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-height: calc(100vh - (20rem + 40rem));\n  position: relative;\n"])));

var Container = _styledComponents["default"].div.attrs({
  className: 'd-flex flex-column'
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var Title = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'h1',
  variant: 2,
  className: 'mt-2 mt-3'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-weight: bold;\n"])));

var NoPostsContainer = _styledComponents["default"].div.attrs({
  className: 'd-flex align-items-center justify-content-center'
})(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-height: calc(100vh - (20rem + 40rem));\n"])));
//# sourceMappingURL=index.js.map