'use strict';

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

var _lodash2 = _interopRequireDefault(_lodash);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

var _reactGa2 = _interopRequireDefault(_reactGa);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDfp = require('react-dfp');

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

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

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

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

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

  _createClass(LatestChoices, [{
    key: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: 'home',
        action: 'click',
        label: 'latestChoices'
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var _props = this.props;
      var articles = _props.articles;
      var categories = _props.categories;
      var choices = _props.choices;


      var styles = ['ui', 'centered', { 'three column': false }, 'grid'];

      return _react2.default.createElement(
        'div',
        { className: 'container LatestChoices' },
        _react2.default.createElement(
          'div',
          { className: (0, _classnames2.default)(styles) },
          _lodash2.default.map(_lodash2.default.take(choices, 2), function (c) {
            var a = _lodash2.default.get(articles, c, {});
            var linkStyle = _lodash2.default.get(a, 'style', '') == 'projects' ? '/projects/' : '/story/';
            var image = (0, _index2.imageComposer)(a).mobileImage;

            return _react2.default.createElement(
              'div',
              { className: 'ui column', key: 'choice' + a.id, style: { marginBottom: '20px' } },
              _react2.default.createElement(
                'a',
                { href: linkStyle + a.slug + '/', onClick: _this2._handleClick },
                _react2.default.createElement(
                  'div',
                  { className: 'sectionBlock' },
                  _react2.default.createElement(
                    'div',
                    { className: 'section-cat' },
                    _lodash2.default.get(categories, [_lodash2.default.first(a.categories), 'title'])
                  ),
                  _react2.default.createElement('div', { className: 'sectionImg', style: { background: 'url(' + image + ') no-repeat center center', backgroundSize: 'cover', width: '300px', height: '250px' } }),
                  _react2.default.createElement(
                    'div',
                    { className: 'sectionTopic' },
                    a.title
                  )
                )
              )
            );
          }),
          _react2.default.createElement(
            'div',
            { className: 'ui column', style: { backgroundColor: 'rgba(0, 77, 162, 0.1)', marginTop: '-10px', marginBottom: '10px', height: '270px' } },
            _react2.default.createElement(
              'a',
              { href: 'https://goo.gl/yqJaVY', target: '_blank' },
              _react2.default.createElement(
                'div',
                { className: 'sectionBlock', style: { marginTop: '10px', marginBottom: '10px' } },
                _react2.default.createElement(_reactDfp.AdSlot, { sizes: [[300, 250]],
                  dfpNetworkId: _index.DFPID,
                  slotId: 'mm_pc_hp_300x250_1st',
                  adUnit: 'mm_pc_hp_300x250_1st',
                  sizeMapping: [{ viewport: [0, 0], sizes: [] }, { viewport: [970, 200], sizes: [[970, 90], [970, 250], [300, 250]] }]
                }),
                _react2.default.createElement(_reactDfp.AdSlot, { sizes: [[300, 250]],
                  dfpNetworkId: _index.DFPID,
                  slotId: 'mm_mobile_hp_300x250_1st',
                  adUnit: 'mm_mobile_hp_300x250_1st',
                  sizeMapping: [{ viewport: [1, 1], sizes: [[300, 250]] }, { viewport: [970, 200], sizes: [] }]
                })
              )
            )
          ),
          _lodash2.default.map(_lodash2.default.take(_lodash2.default.slice(choices, 2), 3), function (c) {
            var a = _lodash2.default.get(articles, c, {});
            var linkStyle = _lodash2.default.get(a, 'style', '') == 'projects' ? '/projects/' : '/story/';
            var image = (0, _index2.imageComposer)(a).mobileImage;

            return _react2.default.createElement(
              'div',
              { className: 'ui column', key: 'choice' + a.id },
              _react2.default.createElement(
                'a',
                { href: linkStyle + a.slug + '/', onClick: _this2._handleClick },
                _react2.default.createElement(
                  'div',
                  { className: 'sectionBlock' },
                  _react2.default.createElement(
                    'div',
                    { className: 'section-cat' },
                    _lodash2.default.get(categories, [_lodash2.default.first(a.categories), 'title'])
                  ),
                  _react2.default.createElement('div', { className: 'sectionImg', style: { background: 'url(' + image + ') no-repeat center center', backgroundSize: 'cover', width: '300px', height: '250px' } }),
                  _react2.default.createElement(
                    'div',
                    { className: 'sectionTopic' },
                    a.title
                  )
                )
              )
            );
          })
        )
      );
    }
  }]);

  return LatestChoices;
}(_react.Component);

exports.default = LatestChoices;
exports.LatestChoices = LatestChoices;