'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.array.join.js');
require('core-js/modules/es.array.map.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var Button = require('../../Button/Button.js');
var Settings = require('../../../constants/Settings.js');
var componentUtilityFunctions = require('../../../utils/componentUtilityFunctions.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var defaultProps = {
  username: '',
  displayName: '',
  profileLink: 'javascript:void(0)',
  onRequestLogout: null,
  i18n: {
    profileTitle: 'Profile',
    profileButton: 'Manage profile',
    logoutButton: 'Log out'
  },
  testId: 'suite-header-profile'
};
var propTypes = {
  username: PropTypes__default.default.string,
  displayName: PropTypes__default.default.string,
  profileLink: PropTypes__default.default.string,
  onProfileClick: PropTypes__default.default.func.isRequired,
  onRequestLogout: PropTypes__default.default.func,
  i18n: PropTypes__default.default.shape({
    profileTitle: PropTypes__default.default.string,
    profileButton: PropTypes__default.default.string,
    logoutButton: PropTypes__default.default.string
  }),
  testId: PropTypes__default.default.string
};
var SuiteHeaderProfile = function SuiteHeaderProfile(_ref) {
  var username = _ref.username,
    displayName = _ref.displayName,
    profileLink = _ref.profileLink,
    onProfileClick = _ref.onProfileClick,
    onRequestLogout = _ref.onRequestLogout,
    i18n = _ref.i18n,
    testId = _ref.testId;
  var mergedI18N = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var baseClassName = "".concat(Settings.settings.iotPrefix, "--suite-header-profile");
  var chipText = (displayName || '').split(' ').map(function (i) {
    return i.charAt(0);
  }).join('');
  return /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": testId,
    className: baseClassName
  }, /*#__PURE__*/React__default.default.createElement("h5", null, mergedI18N.profileTitle), username ? /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--user")
  }, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--user--chip")
  }, chipText), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--user--detail")
  }, /*#__PURE__*/React__default.default.createElement("div", null, /*#__PURE__*/React__default.default.createElement("strong", null, displayName)), /*#__PURE__*/React__default.default.createElement("div", null, username))), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--manage-button").concat(onRequestLogout ? '' : " ".concat(baseClassName, "--manage-button--no-logout"))
  }, /*#__PURE__*/React__default.default.createElement(Button, {
    kind: "secondary",
    size: "sm",
    testId: "".concat(testId, "--profile"),
    onClick: onProfileClick,
    onKeyDown: componentUtilityFunctions.handleSpecificKeyDown(['Enter', ' '], onProfileClick),
    href: profileLink,
    rel: "noopener noreferrer"
  }, mergedI18N.profileButton)), onRequestLogout && /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--logout")
  }, /*#__PURE__*/React__default.default.createElement(Button, {
    kind: "secondary",
    testId: "".concat(testId, "--logout"),
    onClick: onRequestLogout
  }, mergedI18N.logoutButton))) : /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--loading").concat(onRequestLogout ? '' : " ".concat(baseClassName, "--loading--no-logout")),
    "data-testid": "suite-header-profile--loading"
  }, /*#__PURE__*/React__default.default.createElement(react.SkeletonText, {
    paragraph: true,
    lineCount: 3,
    width: "80%"
  })), onRequestLogout && /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--logout ").concat(baseClassName, "--logout--loading")
  }, /*#__PURE__*/React__default.default.createElement(react.ButtonSkeleton, null))));
};
SuiteHeaderProfile.propTypes = propTypes;
SuiteHeaderProfile.defaultProps = defaultProps;
SuiteHeaderProfile.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "SuiteHeaderProfile",
  "props": {
    "username": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "displayName": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "profileLink": {
      "defaultValue": {
        "value": "'javascript:void(0)'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onRequestLogout": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  profileTitle: 'Profile',\n  profileButton: 'Manage profile',\n  logoutButton: 'Log out',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "profileTitle": {
            "name": "string",
            "required": false
          },
          "profileButton": {
            "name": "string",
            "required": false
          },
          "logoutButton": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'suite-header-profile'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onProfileClick": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var SuiteHeaderProfile$1 = SuiteHeaderProfile;

module.exports = SuiteHeaderProfile$1;
