'use strict';

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

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 $ */


if (process.env.BROWSER) {}

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

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

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

    _this._handleClick = _this._handleClick.bind(_this);
    _this._handleScroll = _this._handleScroll.bind(_this);
    _this._openSearchbar = _this._openSearchbar.bind(_this);
    _this._openSidebar = _this._openSidebar.bind(_this);
    return _this;
  }

  _createClass(HeaderFull, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      // detect sroll position
      window.addEventListener('scroll', this._handleScroll);
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      window.removeEventListener('scroll', this._handleScroll);
    }
  }, {
    key: '_handleClick',
    value: function _handleClick() {
      _reactGa2.default.event({
        category: this.props.pathName,
        action: 'click',
        label: 'header'
      });
    }
  }, {
    key: '_handleScroll',
    value: function _handleScroll() {
      // Navigation Animation
      $(window).bind('scroll', function () {
        $('#Header').css('opacity', 1 - window.scrollY / 60);
        $('#HeaderBlack').css('opacity', window.scrollY / 60);
        if ($('#Header').css('opacity') == 0) {
          $('#Header').hide();
        }
        if ($('#Header').css('opacity') != 0) {
          $('#Header').show();
        }
      });
    }
  }, {
    key: '_openSearchbar',
    value: function _openSearchbar() {
      $('.ui.top.sidebar').sidebar({
        exclusive: true,
        scrollLock: true,
        transition: 'overlay',
        mobileTransition: 'overlay'
      }).sidebar('toggle');
    }
  }, {
    key: '_openSidebar',
    value: function _openSidebar() {
      // console.log('open sidebar')
      $('.ui.left.sidebar').sidebar({
        exclusive: true,
        scrollLock: true,
        transition: 'overlay',
        mobileTransition: 'overlay'
      }).sidebar('toggle');
    }
  }, {
    key: 'render',
    value: function render() {
      var pathName = this.props.pathName;

      var currentSection = pathName.split('/')[2];

      return _react2.default.createElement(
        'header',
        null,
        _react2.default.createElement(
          'nav',
          { id: 'Header', className: 'HeaderFull ui menu borderless fixed top' },
          _react2.default.createElement(
            'div',
            { className: 'left item' },
            _react2.default.createElement(
              _reactRouter.Link,
              null,
              _react2.default.createElement('img', { src: '/asset/icon/hamburger_white.png', className: 'headerFull-icon hamburger', onClick: this._openSidebar })
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'item logo' },
            _react2.default.createElement(
              _reactRouter.Link,
              { to: '/section/' + currentSection },
              _react2.default.createElement('img', { src: '/asset/icon/section-' + 'watch' + '_b.png' })
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'right item' },
            _react2.default.createElement(
              _reactRouter.Link,
              { to: '/', className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/logo_black@2x.png', className: 'headerFull-icon logo' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.FACEBOOK, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/facebook_white.png', className: 'headerFull-icon facebook' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.LINE, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/line_white.png', className: 'headerFull-icon line' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.WEIBO, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/weibo_white.png', className: 'headerFull-icon weibo' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { onClick: this._openSearchbar, style: { paddingLeft: '1.2em' } },
              _react2.default.createElement('img', { src: '/asset/icon/search_white.png', className: 'headerFull-icon search' })
            )
          )
        ),
        _react2.default.createElement(
          'nav',
          { id: 'HeaderBlack', className: 'HeaderFull ui menu borderless fixed top black' },
          _react2.default.createElement(
            'div',
            { className: 'left item' },
            _react2.default.createElement(
              _reactRouter.Link,
              null,
              _react2.default.createElement('img', { src: '/asset/icon/hamburger_white.png', className: 'headerFull-icon hamburger', onClick: this._openSidebar })
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'item logo logo--s' },
            _react2.default.createElement(
              _reactRouter.Link,
              { to: '/section/' + currentSection },
              _react2.default.createElement('img', { src: '/asset/icon/section-' + 'watch' + '_s.png' })
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'right item' },
            _react2.default.createElement(
              _reactRouter.Link,
              { to: '/', className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/logo_black@2x.png', className: 'headerFull-icon logo' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.FACEBOOK, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/facebook_white.png', className: 'headerFull-icon facebook' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.LINE, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/line_white.png', className: 'headerFull-icon line' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { to: _index.SOCIAL_LINK.WEIBO, className: 'desktop-only' },
              _react2.default.createElement('img', { src: '/asset/icon/weibo_white.png', className: 'headerFull-icon weibo' })
            ),
            _react2.default.createElement(
              _reactRouter.Link,
              { onClick: this._openSearchbar, style: { paddingLeft: '1.2em' } },
              _react2.default.createElement('img', { src: '/asset/icon/search_white.png', className: 'headerFull-icon search' })
            )
          )
        )
      );
    }
  }]);

  return HeaderFull;
}(_react.Component);

exports.default = HeaderFull;
exports.HeaderFull = HeaderFull;