'use strict';

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

var _react2 = _interopRequireDefault(_react);

var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _mxa = require('../../../../components/mxa');

var _components = require('../../../../components');

var _IconHelper = require('../../../utils/IconHelper');

var _SessionStorage = require('../../../service/SessionStorage');

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; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Created by baoyinghai on 4/20/17.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */


var TitleBar = function (_React$Component) {
  _inherits(TitleBar, _React$Component);

  function TitleBar() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, TitleBar);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TitleBar.__proto__ || Object.getPrototypeOf(TitleBar)).call.apply(_ref, [this].concat(args))), _this), _this._closeWin = function () {
      _mxa.Modal.confirm({
        title: '提示',
        content: '确定关闭当前页面吗?',
        onOk: window.close
      });
    }, _this._renderCloseBtn = function () {
      var queryStr = location.href.split('?p=', 2)[1];
      var query = queryStr && _qs2.default.parse(atob(queryStr));
      var ids = Object.assign({}, (0, _SessionStorage.getRecMenuId)(), query);
      if (ids && ids.processMenuId) return null;
      return _react2.default.createElement(
        'div',
        { className: 'title-close-btn' },
        (0, _IconHelper.iconWrapper)('icon-guanbifuzhi', undefined, undefined, { onClick: _this._closeWin })
      );
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(TitleBar, [{
    key: '_renderInfoCompleteGlobal',
    value: function _renderInfoCompleteGlobal(infoCompleteness) {
      var pre = parseInt(infoCompleteness / 100, 10);
      return _react2.default.createElement(
        'div',
        { className: 'info-completeness-global' },
        _react2.default.createElement(
          'div',
          { style: { display: 'flex', justifyContent: 'space-between' } },
          _react2.default.createElement(
            'span',
            null,
            '\u4FE1\u606F\u5B8C\u6574\u5EA6'
          ),
          _react2.default.createElement(
            'div',
            null,
            _react2.default.createElement(
              'span',
              { style: { color: pre > 99 ? '#26BF8C' : '#fa7252' } },
              pre
            ),
            _react2.default.createElement(
              'span',
              null,
              '%'
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { style: { marginTop: 9 } },
          _react2.default.createElement(_components.ProgressBar, { width: 85, pre: pre })
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          _props$prefixCls = _props.prefixCls,
          prefixCls = _props$prefixCls === undefined ? 'info-title-bar' : _props$prefixCls,
          getTitleDesc = _props.getTitleDesc,
          infoCompleteness = _props.infoCompleteness;

      return _react2.default.createElement(
        'div',
        { className: prefixCls + '-wrapper' },
        _react2.default.createElement(
          'div',
          { className: prefixCls },
          _react2.default.createElement(
            'span',
            { className: 'title-desc' },
            getTitleDesc && getTitleDesc()
          ),
          _react2.default.createElement(
            'div',
            { className: 'btn-list' },
            this.props.children,
            (infoCompleteness || infoCompleteness === 0) && this._renderInfoCompleteGlobal(infoCompleteness)
          ),
          this._renderCloseBtn()
        )
      );
    }
  }]);

  return TitleBar;
}(_react2.default.Component);

exports.default = TitleBar;