'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; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var UserMenu = function () {
  function UserMenu() {
    _classCallCheck(this, UserMenu);

    this.selector = '.cspace-ui-UserMenu--common';
  }

  _createClass(UserMenu, [{
    key: 'getUserScreenName',
    value: function getUserScreenName() {
      var element = browser.$(this.selector);

      if (!element) {
        return undefined;
      }

      var text = element.getText();

      if (text && typeof text === 'string' && text.indexOf('|') >= 0) {
        return text.split('|', 1)[0].trim();
      }

      return undefined;
    }
  }, {
    key: 'getLogoutLink',
    value: function getLogoutLink() {
      return browser.$(this.selector).$('a');
    }
  }, {
    key: 'isVisible',
    value: function isVisible() {
      return browser.isVisible(this.selector);
    }
  }, {
    key: 'isLoggedInAs',
    value: function isLoggedInAs(username) {
      return this.isVisible() && this.getUserScreenName() === username;
    }
  }, {
    key: 'logout',
    value: function logout() {
      this.getLogoutLink().click();

      return this;
    }
  }]);

  return UserMenu;
}();

exports.default = UserMenu;