'use strict';

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

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

var _reactGa2 = _interopRequireDefault(_reactGa);

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

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

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

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

  _createClass(TopChoice, [{
    key: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: 'home',
        action: 'click',
        label: 'topChoice'
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props;
      var article = _props.article;
      var categories = _props.categories;

      var a = article;
      var linkStyle = _lodash2.default.get(a, 'style', '') == 'projects' ? '/projects/' : '/story/';
      var image = (0, _index.imageComposer)(a).mobileImage;
      return a ? _react2.default.createElement(
        'div',
        { className: 'container tablet-hide computer-hide' },
        _react2.default.createElement(
          'div',
          { className: 'choice-main' },
          _react2.default.createElement(
            'div',
            { className: 'choice-block', key: 'choice' + a.id },
            _react2.default.createElement(
              'a',
              { href: linkStyle + a.slug + '/', onClick: this._handleClick },
              _react2.default.createElement('div', { className: 'choice-img ', style: { background: 'url(' + image + ') no-repeat center center', backgroundSize: 'cover' } })
            ),
            _react2.default.createElement(
              'div',
              { className: 'choice-title' },
              '編輯精選'
            ),
            _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 + '/', onClick: this._handleClick },
                _react2.default.createElement(
                  'h2',
                  null,
                  a.title
                )
              )
            )
          )
        )
      ) : null;
    }
  }]);

  return TopChoice;
}(_react.Component);

exports.default = TopChoice;
exports.TopChoice = TopChoice;