'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SidebarFull = 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 _reactRouter = require('react-router');

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

// import { SOCIAL_LINK } from '../constants/index'


if (process.env.BROWSER) {}

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

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

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

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

  _createClass(SidebarFull, [{
    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: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: this.props.pathName,
        action: 'click',
        label: 'sidebarFull'
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

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

      var currentSection = pathName.split('/')[2];
      var sidebarList = _lodash2.default.result(_lodash2.default.find(sectionList.sections, { 'name': currentSection }), 'categories');

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'section',
          { className: 'ui top sidebar sidebarFull' },
          _react2.default.createElement(
            'div',
            { className: 'ui transparent input searchbar' },
            _react2.default.createElement(
              'div',
              { className: 'close closeSearchSidebar' },
              _react2.default.createElement('img', { src: '/asset/icon/sidebar-close.png', className: 'sidebar-icon close' })
            ),
            _react2.default.createElement(
              'form',
              { style: { width: '100%', fontSize: '0 !important' } },
              _react2.default.createElement('input', { className: 'search', type: 'text', placeholder: '搜尋' })
            )
          )
        ),
        _react2.default.createElement(
          'section',
          { className: 'ui left sidebar sidebarFull' },
          _react2.default.createElement(
            'div',
            { className: 'closeSidebar' },
            _react2.default.createElement('img', { src: '/asset/icon/sidebar-close.png', className: 'sidebar-icon close' }),
            _react2.default.createElement(
              'span',
              null,
              'CLOSE THE MENU'
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'ui borderless vertical menu' },
            _react2.default.createElement(
              _reactRouter.Link,
              { to: pathName, key: pathName, className: 'item', onClick: this._handleClick },
              '主頁'
            ),
            _react2.default.createElement('div', { className: 'horizDivider' }),
            _lodash2.default.map(sidebarList, function (s) {
              return _react2.default.createElement(
                _reactRouter.Link,
                { to: '/category/' + s.name, key: s.id, className: 'item', onClick: _this2._handleClick },
                s.title
              );
            })
          )
        )
      );
    }
  }]);

  return SidebarFull;
}(_react.Component);

exports.default = SidebarFull;
exports.SidebarFull = SidebarFull;