'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Tags = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Category = require('./Category');

var _Category2 = _interopRequireDefault(_Category);

var _More = require('../components/More');

var _More2 = _interopRequireDefault(_More);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _reactRouter = require('react-router');

var _dateTransformer = require('../lib/date-transformer');

var _index = require('../utils/index');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*eslint no-unused-vars: 1*/

if (process.env.BROWSER) {}

var CategoryName = function (_Component) {
  _inherits(CategoryName, _Component);

  function CategoryName(props, context) {
    _classCallCheck(this, CategoryName);

    return _possibleConstructorReturn(this, (CategoryName.__proto__ || Object.getPrototypeOf(CategoryName)).call(this, props, context));
  }

  _createClass(CategoryName, [{
    key: 'render',
    value: function render() {
      var cat_display = this.props.cat_display;

      return _react2.default.createElement(
        'div',
        { className: 'category-name' },
        _react2.default.createElement(
          _Category2.default,
          null,
          cat_display
        )
      );
    }
  }]);

  return CategoryName;
}(_react.Component);

var Tags = function (_Component2) {
  _inherits(Tags, _Component2);

  function Tags(props, context) {
    _classCallCheck(this, Tags);

    return _possibleConstructorReturn(this, (Tags.__proto__ || Object.getPrototypeOf(Tags)).call(this, props, context));
  }

  _createClass(Tags, [{
    key: 'render',
    value: function render() {
      var _props = this.props;
      var articles = _props.articles;
      var hasMore = _props.hasMore;
      var loadMore = _props.loadMore;

      var bgStyle = {};
      var photoClass = void 0;

      if (this.props.bgStyle === 'dark') {
        photoClass = 'tag-photography';
      }
      if (articles && articles.length > 0) {
        return _react2.default.createElement(
          'section',
          null,
          _react2.default.createElement(
            'div',
            { className: 'container' },
            _react2.default.createElement(
              'ul',
              { className: (0, _classnames2.default)('tag-listing', photoClass) },
              _lodash2.default.map(articles, function (a) {
                var image = (0, _index.imageComposer)(a).mobileImage;
                var d_str = (0, _dateTransformer.date2yyyymmdd)(a.publishedDate, '.');
                var url = '/a/' + a.slug;
                var excerpt = _lodash2.default.get(a, 'ogDescription', '');
                if (image) {
                  return _react2.default.createElement(
                    'li',
                    { className: 'tag-item', key: a.id, style: bgStyle },
                    _react2.default.createElement(
                      _reactRouter.Link,
                      { to: url },
                      _react2.default.createElement(
                        'div',
                        { className: 'itemimage-wrap' },
                        _react2.default.createElement('img', { className: 'category-itemimage', src: image })
                      ),
                      _react2.default.createElement(
                        'div',
                        { className: 'tag-itemdesc', style: bgStyle },
                        _react2.default.createElement(
                          'div',
                          { className: 'tag-itemtitle' },
                          _react2.default.createElement(
                            'h3',
                            null,
                            a.title
                          )
                        ),
                        _react2.default.createElement(
                          'div',
                          { className: 'tag-itemexcerpt' },
                          excerpt
                        ),
                        _react2.default.createElement(
                          'div',
                          { className: 'tag-itempublished' },
                          d_str
                        )
                      )
                    )
                  );
                }
              })
            )
          ),
          hasMore ? _react2.default.createElement(_More2.default, { loadMore: loadMore }) : null
        );
      } else {
        return _react2.default.createElement(
          'div',
          null,
          ' '
        );
      }
    }
  }]);

  return Tags;
}(_react.Component);

exports.default = Tags;
exports.Tags = Tags;