function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */

/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// # Global Header Button Component
// ## Dependencies
// ### React
import React from 'react';
import PropTypes from 'prop-types';
import assign from 'lodash.assign';
import classnames from 'classnames';
import checkProps from './check-props';
import Button from '../button';
import Popover from '../popover'; // ## Constants

import { GLOBAL_HEADER_PROFILE } from '../../utilities/constants';
/**
 * This component is an `Avatar` component that opens a `Popover` component when clicked.
 */

var GlobalHeaderProfile = /*#__PURE__*/function (_React$Component) {
  _inherits(GlobalHeaderProfile, _React$Component);

  var _super = _createSuper(GlobalHeaderProfile);

  function GlobalHeaderProfile(props) {
    var _this;

    _classCallCheck(this, GlobalHeaderProfile);

    _this = _super.call(this, props);
    checkProps(GLOBAL_HEADER_PROFILE, props);
    return _this;
  }

  _createClass(GlobalHeaderProfile, [{
    key: "render",
    value: function render() {
      var buttonAriaProps = {
        'aria-haspopup': true
      };
      var popoverProps = assign({
        align: 'bottom right',
        body: /*#__PURE__*/React.createElement("span", null),
        className: this.props.className,
        heading: this.props.userName,
        id: this.props.id,
        triggerClassName: 'slds-dropdown-trigger slds-dropdown-trigger_click'
      }, this.props.popover ? this.props.popover.props : {}); // Note: the default avatar is done this way to prevent documentation from showing this giant string

      /* eslint-disable max-len */

      var avatar = 'data:image/jpeg;base64, ';
      /* eslint-enable max-len */
      // eslint-disable-next-line fp/no-delete

      delete popoverProps.children;
      avatar = this.props.avatar ? this.props.avatar : avatar;
      return /*#__PURE__*/React.createElement(Popover, popoverProps, /*#__PURE__*/React.createElement(Button, _extends({
        className: classnames('slds-global-actions__avatar slds-global-actions__item-action', this.props.buttonClassName),
        title: this.props.userName,
        variant: "icon"
      }, buttonAriaProps), typeof avatar === 'string' ? /*#__PURE__*/React.createElement("span", {
        className: "slds-avatar slds-avatar_circle slds-avatar_medium"
      }, /*#__PURE__*/React.createElement("img", {
        alt: this.props.userName,
        src: avatar,
        title: "User avatar"
      })) : avatar || null));
    }
  }]);

  return GlobalHeaderProfile;
}(React.Component); // ### Display Name


GlobalHeaderProfile.displayName = GLOBAL_HEADER_PROFILE; // ### Prop Types

GlobalHeaderProfile.propTypes = {
  /**
   * Extra classnames to apply to the popover.
   */
  className: PropTypes.string,

  /**
   * An image URL or avatar node to display for the user profile. Defaults to a base64 encoded generic user avatar image string
   */
  avatar: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),

  /**
   * CSS classes to be added to the `button` element.
   */
  buttonClassName: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),

  /**
   * A unique ID is needed in order to support keyboard navigation, ARIA support, and connect the popover to the triggering button. If an id is not provided, it will be automatically generated.
   */
  id: PropTypes.string,

  /**
   * A `Popover` component. The props from this popover will be merged and override any default props.
   */
  popover: PropTypes.node,

  /**
   * The user name of the profile. Defaults to "User Name"
   */
  userName: PropTypes.string
}; // ### Default Props

GlobalHeaderProfile.defaultProps = {
  userName: 'User Name'
};
export default GlobalHeaderProfile;
//# sourceMappingURL=profile.js.map