'use strict';

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

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

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

var _reactGa2 = _interopRequireDefault(_reactGa);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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; } /* global $ */


if (process.env.BROWSER) {}

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

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

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

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

  _createClass(Sidebar, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      // console.log('componentDidMount')
      $.site('change setting', 'silent', true);

      $('.ui.left.sidebar').sidebar('hide');
      $('.closeSidebar').click(function () {
        $('.ui.left.sidebar').sidebar('hide');
      });

      $('input.search').parent().submit(function (event) {
        $(location).attr('href', '/search/' + $('input.search').val());
        event.preventDefault();
      });
      $('.closeSearchSidebar').click(function () {
        $('.ui.top.sidebar').sidebar('hide');
      });
    }
  }, {
    key: '_closeSidebar',
    value: function _closeSidebar() {
      // console.log('close sidebar')
      $('.ui.left.sidebar').sidebar('toggle');
    }
  }, {
    key: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: this.props.pathName,
        action: 'click',
        label: 'sidebar'
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var _props = this.props;
      var sectionList = _props.sectionList;
      var topics = _props.topics;


      var itemsForHeader = {};
      itemsForHeader.topics = [];
      itemsForHeader.sections = [];
      itemsForHeader.categories = [];

      GenerateNav();

      function GenerateNav() {
        _lodash2.default.each(topics.items, function (t) {
          if (t.isFeatured) {
            itemsForHeader.topics.push(t);
          }
        });
        _lodash2.default.each(sectionList.sections, function (s) {
          if (s.isFeatured) {
            itemsForHeader.sections.push(s);
          }
          _lodash2.default.each(s.categories, function (c) {
            if (c.isFeatured) {
              itemsForHeader.categories.push(c);
            }
          });
        });
      }

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'div',
          { className: 'ui top sidebar' },
          _react2.default.createElement(
            'div',
            { className: 'ui transparent input searchbar', style: { maxWidth: '100%', paddingRight: '60px', width: '100%' } },
            _react2.default.createElement(
              'div',
              { className: 'close closeSearchSidebar' },
              _react2.default.createElement('img', { src: '/asset/icon/blue@2x.png', className: 'sidebar-icon blue' })
            ),
            _react2.default.createElement(
              'form',
              { style: { width: '100%' } },
              _react2.default.createElement('input', { className: 'search', type: 'text', style: { textAlign: 'right' }, placeholder: '搜尋' })
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { className: 'ui gradient-transparent-vertical backdrop left sidebar', style: { width: '274px' } },
          _react2.default.createElement(
            'div',
            { className: 'ui left', style: { position: 'absolute', color: '#fff', fontSize: '3em', marginTop: '18px', marginLeft: '10px' } },
            _react2.default.createElement(
              'a',
              { className: 'item closeSidebar', onClick: this._closeSidebar },
              _react2.default.createElement('img', { src: '/asset/icon/white@2x.png', className: 'sidebar-icon white' })
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'ui borderless vertical menu', style: { marginLeft: '40px', marginTop: '70px !important', background: 'transparent', border: 'none', boxShadow: 'none' } },
            _lodash2.default.map(itemsForHeader.topics, function (i) {
              return _react2.default.createElement(
                'a',
                { href: '/topic/' + i.id, key: i.id, className: 'item', onClick: _this2._handleClick, style: { color: '#FFF', marginBottom: '30px', fontWeight: 'normal !important' } },
                i.name
              );
            }),
            _lodash2.default.map(itemsForHeader.sections, function (i) {
              return _react2.default.createElement(
                'a',
                { href: '/section/' + i.name, key: i.id, className: 'item', onClick: _this2._handleClick, style: { color: '#FFF', marginBottom: '30px', fontWeight: 'normal !important' } },
                i.title
              );
            }),
            _lodash2.default.map(itemsForHeader.categories, function (i) {
              return _react2.default.createElement(
                'a',
                { href: '/category/' + i.name, key: i.id, className: 'item', onClick: _this2._handleClick, style: { color: '#FFF', marginBottom: '30px', fontWeight: 'normal !important' } },
                i.title
              );
            })
          ),
          _react2.default.createElement(
            'div',
            { style: { marginLeft: '40px', marginTop: '90px' } },
            _react2.default.createElement(
              'div',
              { style: { fontFamily: 'Noto Sans TC', fontSize: '17px', letterSpacing: '1.1px', color: 'rgba(0, 0, 0, 0.5)' } },
              '訂閱鏡週刊'
            ),
            _react2.default.createElement('div', { style: { width: '195px', height: '2px', border: 'solid 1px rgba(0, 0, 0, 0.5)', margin: '10px 0' } }),
            _react2.default.createElement(
              'div',
              { className: 'ui', style: { lineHeight: '40px' } },
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.LINE, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/line@2x.png', className: 'sidebar-icon line' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.WEIBO, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/weibo@2x.png', className: 'sidebar-icon weibo' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.FACEBOOK, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/facebook@2x.png', className: 'sidebar-icon facebook' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.INSTAGRAM, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/instagram@2x.png', className: 'sidebar-icon instagram' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.FEED, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/feed@2x.png', className: 'sidebar-icon feed' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.EMAIL, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/mail@2x.png', className: 'sidebar-icon mail' })
              ),
              _react2.default.createElement(
                'a',
                { href: _index.SOCIAL_LINK.SUBSCRIBE, className: 'item', style: { marginRight: '25px' } },
                _react2.default.createElement('img', { src: '/asset/icon/book@2x.png', className: 'sidebar-icon book' })
              )
            )
          )
        )
      );
    }
  }]);

  return Sidebar;
}(_react.Component);

exports.default = Sidebar;
exports.Sidebar = Sidebar;