'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Featured = 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 _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _sanitizeHtml = require('sanitize-html');

var _sanitizeHtml2 = _interopRequireDefault(_sanitizeHtml);

var _truncate = require('truncate');

var _truncate2 = _interopRequireDefault(_truncate);

var _entities = require('entities');

var _entities2 = _interopRequireDefault(_entities);

var _dateformat = require('dateformat');

var _dateformat2 = _interopRequireDefault(_dateformat);

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; }

if (process.env.BROWSER) {}

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

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

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

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


      return articles ? _react2.default.createElement(
        'div',
        { className: 'container mobile-hide', style: { marginTop: '50px' } },
        _react2.default.createElement(
          'div',
          { className: 'ui text container', style: { marginBottom: '35px', paddingLeft: '1em !important', marginLeft: '0 !important' } },
          _react2.default.createElement(
            'div',
            { className: 'article-main', style: { textAlign: 'center' } },
            _react2.default.createElement(
              'h2',
              { className: 'hot-topic' },
              _react2.default.createElement('div', { className: 'colorBlock choice' }),
              '編輯精選',
              _react2.default.createElement('div', { className: 'blue-line', style: { marginLeft: '16px', display: 'inline-block' } })
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { className: 'choice-main' },
          _lodash2.default.map(_lodash2.default.take(articles, 3), function (a) {
            var image = (0, _index.imageComposer)(a).mobileImage;
            var linkStyle = _lodash2.default.get(a, 'style', '') == 'projects' ? '/projects/' : '/story/';
            var brief = (0, _sanitizeHtml2.default)(_lodash2.default.get(a, ['brief', 'html'], ''), { allowedTags: [] });
            var content = (0, _sanitizeHtml2.default)(_lodash2.default.get(a, ['content', 'html'], ''), { allowedTags: [] });
            var briefContent = brief.length > 0 ? brief : content;

            return _react2.default.createElement(
              'div',
              { className: 'choice-block', key: 'choice' + a.id },
              _react2.default.createElement(
                'a',
                { href: linkStyle + a.slug + '/' },
                _react2.default.createElement('div', { className: 'choice-img ', style: { background: 'url(' + image + ') no-repeat center center', backgroundSize: 'cover' } })
              ),
              _react2.default.createElement(
                'div',
                { className: 'choice-cat ' },
                _lodash2.default.get(categories, [_lodash2.default.first(a.categories), 'title'])
              ),
              _react2.default.createElement(
                'div',
                { className: 'choice-content ' },
                _react2.default.createElement(
                  'a',
                  { href: linkStyle + a.slug + '/' },
                  _react2.default.createElement(
                    'h2',
                    null,
                    a.title
                  )
                ),
                _react2.default.createElement('div', { className: 'line' }),
                _react2.default.createElement(
                  'div',
                  { className: 'brief' },
                  (0, _truncate2.default)(_entities2.default.decodeHTML(briefContent), 200)
                )
              ),
              _react2.default.createElement(
                'div',
                { className: 'choice-meta ' },
                _react2.default.createElement(
                  'div',
                  { className: 'date' },
                  (0, _dateformat2.default)(a.publishedDate, 'yyyy.mm.dd')
                )
              )
            );
          })
        )
      ) : null;
    }
  }]);

  return Featured;
}(_react.Component);

exports.default = Featured;
exports.Featured = Featured;