'use strict';

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

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var SetTitle = function (_Component) {
	(0, _inherits3.default)(SetTitle, _Component);

	function SetTitle(props) {
		(0, _classCallCheck3.default)(this, SetTitle);
		return (0, _possibleConstructorReturn3.default)(this, (SetTitle.__proto__ || Object.getPrototypeOf(SetTitle)).call(this, props));
	}

	(0, _createClass3.default)(SetTitle, [{
		key: 'componentDidMount',
		value: function componentDidMount() {
			this.setTitle();
		}
	}, {
		key: 'componentDidUpdate',
		value: function componentDidUpdate() {
			this.setTitle();
		}
	}, {
		key: 'componentWillUnmount',
		value: function componentWillUnmount() {}
	}, {
		key: 'setTitle',
		value: function setTitle() {
			var title = this.props.title;

			var _title = document.title;
			title != _title && (document.title = title || '系统');
		}
	}, {
		key: 'hackForSetTitle',
		value: function hackForSetTitle() {}
	}, {
		key: 'render',
		value: function render() {
			var _props = this.props,
			    className = _props.className,
			    style = _props.style,
			    isShow = _props.isShow;

			var styleShow = isShow ? {} : { display: "none" };
			return _react2.default.createElement(
				'div',
				{ className: className, style: (0, _extends3.default)({}, style, { overflowX: 'auto' }, styleShow) },
				this.props.children
			);
		}
	}]);
	return SetTitle;
}(_react.Component);

SetTitle.propTypes = {
	/**
  * document.title
  */
	title: _propTypes2.default.string,
	/**
  * 初始化class与style
  */
	className: _propTypes2.default.string,
	style: _propTypes2.default.object,
	/**
  * 首次加载隐藏不显示
  */
	isShow: _propTypes2.default.number,
	/**
  * 监听的节点
  */
	wrapper: _propTypes2.default.string
};
/**
 *实现三个功能，标题（需要额外传入参数，使componentDidUpdate不触发），分享，滚动监听
 */
SetTitle.defaultProps = {
	wrapper: "window",
	isShow: 1
};
exports.default = SetTitle;