'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ChoicesFull = 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 _index = require('../utils/index');

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _dateformat = require('dateformat');

var _dateformat2 = _interopRequireDefault(_dateformat);

var _entities = require('entities');

var _entities2 = _interopRequireDefault(_entities);

var _reactGa = require('react-ga');

var _reactGa2 = _interopRequireDefault(_reactGa);

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

var _sanitizeHtml2 = _interopRequireDefault(_sanitizeHtml);

var _truncate = require('truncate');

var _truncate2 = _interopRequireDefault(_truncate);

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 ChoicesFull = function (_Component) {
  _inherits(ChoicesFull, _Component);

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

    var _this = _possibleConstructorReturn(this, (ChoicesFull.__proto__ || Object.getPrototypeOf(ChoicesFull)).call(this, props, context));

    _this._handleClick = _this._handleClick.bind(_this);
    return _this;
  }

  _createClass(ChoicesFull, [{
    key: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: this.props.pathName,
        action: 'click',
        label: 'choicesFull'
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var articles = this.props.articles;


      return articles ? _react2.default.createElement(
        'section',
        { id: 'editorPicks', className: 'choice-section' },
        _react2.default.createElement(
          'div',
          { className: 'section-title' },
          _react2.default.createElement(
            'h2',
            null,
            _react2.default.createElement('div', { className: 'colorBlock' }),
            '編輯精選 Editor\\\'s Picks'
          )
        ),
        _react2.default.createElement(
          'div',
          { className: 'choice-post-block' },
          _lodash2.default.map(_lodash2.default.take(articles, 3), function (a) {
            var brief = (0, _sanitizeHtml2.default)(_lodash2.default.get(a, ['brief', 'html'], ''), { allowedTags: [] });
            var briefContent = brief.length > 0 ? brief : content;
            var content = (0, _sanitizeHtml2.default)(_lodash2.default.get(a, ['content', 'html'], ''), { allowedTags: [] });
            var image = (0, _index.imageComposer)(a).mobileImage;
            var linkStyle = _lodash2.default.get(a, 'style', '') == 'projects' ? '/projects/' : '/story/';
            var writers = '文｜' + _lodash2.default.pluck(a.writers, 'name').join('、') + '｜';

            return _react2.default.createElement(
              'div',
              { className: 'post-container', key: 'choiceFull' + a.id },
              _react2.default.createElement(
                'a',
                { href: linkStyle + a.slug + '/', onClick: _this2._handleClick },
                _react2.default.createElement('div', { className: 'editor-img', style: { background: 'url(' + image + ') no-repeat center center', backgroundSize: 'cover' } })
              ),
              _react2.default.createElement(
                'div',
                { className: 'choice-post' },
                _react2.default.createElement(
                  'a',
                  { href: linkStyle + a.slug + '/', onClick: _this2._handleClick },
                  _react2.default.createElement(
                    'h2',
                    null,
                    a.title
                  )
                ),
                _react2.default.createElement(
                  'div',
                  { className: 'choice-brief' },
                  (0, _truncate2.default)(_entities2.default.decodeHTML(briefContent), 70)
                ),
                _react2.default.createElement(
                  'div',
                  { className: 'choice meta' },
                  _react2.default.createElement(
                    'div',
                    { className: 'choice-author' },
                    _lodash2.default.get(a, ['writers', 'length'], 0) > 0 ? writers + ' ' : null
                  ),
                  _react2.default.createElement(
                    'div',
                    { className: 'choice-date' },
                    (0, _dateformat2.default)(a.publishedDate, 'yyyy.mm.dd')
                  )
                )
              )
            );
          })
        )
      ) : null;
    }
  }]);

  return ChoicesFull;
}(_react.Component);

exports.default = ChoicesFull;
exports.ChoicesFull = ChoicesFull;