"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

var _router = require("next/router");

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

var _templateObject, _templateObject2, _templateObject3;

var BlogPost = function BlogPost() {
  var _data$content, _data$content2;

  var _useConfigState = (0, _lib.useConfigState)(),
      date = _useConfigState.date;

  var router = (0, _router.useRouter)();

  var _useCmsContent = (0, _lib.useCmsContent)({
    key: router.query.slug
  }),
      data = _useCmsContent.data,
      isError = _useCmsContent.isError;

  (0, _react.useEffect)(function () {
    if (!data && isError) {
      router.push('/404');
    }
  }, [data, isError, router]);
  return /*#__PURE__*/_react["default"].createElement(BlogPostContent, null, /*#__PURE__*/_react["default"].createElement(CreationDate, null, new Date(data == null ? void 0 : data.content.datePublished).toLocaleDateString(date.locale)), /*#__PURE__*/_react["default"].createElement(Title, null, data == null ? void 0 : (_data$content = data.content) == null ? void 0 : _data$content.name), /*#__PURE__*/_react["default"].createElement(_Common.Copy, {
    html: data == null ? void 0 : (_data$content2 = data.content) == null ? void 0 : _data$content2.content
  }));
};

exports.BlogPost = BlogPost;

var BlogPostContent = _styledComponents["default"].div.attrs({
  className: 'mb-5'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var CreationDate = (0, _styledComponents["default"])(_Common.Typography).attrs({
  variant: '7',
  className: ''
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])([""])));
var Title = (0, _styledComponents["default"])(_Common.Typography).attrs({
  variant: '2',
  as: 'h1',
  className: 'mt-2 mb-3'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-weight: bold;\n"])));
//# sourceMappingURL=index.js.map