'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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 _reactIntl = require('react-intl');

var _reactRedux = require('react-redux');

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _reactDocumentTitle = require('react-document-title');

var _reactDocumentTitle2 = _interopRequireDefault(_reactDocumentTitle);

var _NavBar = require('../containers/NavBar');

var _NavBar2 = _interopRequireDefault(_NavBar);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _en = require('react-intl/locale-data/en');

var _en2 = _interopRequireDefault(_en);

var _zh = require('react-intl/locale-data/zh');

var _zh2 = _interopRequireDefault(_zh);

var _App = {
  "app": "App__app___2MRkl",
  "photography": "App__photography___2dDCk"
};

var _App2 = _interopRequireDefault(_App);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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; }
// import locale data


(0, _reactIntl.addLocaleData)(_en2.default);
(0, _reactIntl.addLocaleData)(_zh2.default);
var currentLocale = 'zh-Hant';

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

  function App() {
    _classCallCheck(this, App);

    return _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).apply(this, arguments));
  }

  _createClass(App, [{
    key: 'getChildContext',
    value: function getChildContext() {
      return { location: this.props.location };
    }
  }, {
    key: 'componentWillMount',
    value: function componentWillMount() {
      // set current locale
      if (process.env.BROWSER) {
        currentLocale = navigator.language;
        (0, _reactIntl.addLocaleData)({
          locale: navigator.language,
          parentLocale: navigator.language.split('-')[0]
        });
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var pathname = this.props.location.pathname;
      var pageType = _lodash2.default.get(this.props, ['header', 'pageType']);
      return _react2.default.createElement(
        _reactDocumentTitle2.default,
        { title: _index.SITE_NAME.FULL },
        _react2.default.createElement(
          _reactIntl.IntlProvider,
          { locale: currentLocale, defaultLocale: 'zh-Hant' },
          _react2.default.createElement(
            'div',
            { className: (0, _classnames2.default)(_App2.default.app, _defineProperty({}, _App2.default.photography, pageType === _index.PHOTOGRAPHY_ARTICLE || pageType === _index.PHOTOGRAPHY)) },
            _react2.default.createElement(_NavBar2.default, {
              bgStyle: pathname === '/photography' ? 'dark' : 'light',
              path: pathname }),
            this.props.children
          )
        )
      );
    }
  }]);

  return App;
}(_react.Component);

App.childContextTypes = {
  location: _react2.default.PropTypes.object
};

function mapStateToProps(state) {
  return {
    header: state.header
  };
}

exports.default = (0, _reactRedux.connect)(mapStateToProps)(App);