function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React, { useContext } from 'react';
import { IconPerson, IconExitToApp } from '@defencedigital/icon-library';
import { Transition } from 'react-transition-group';
import { SidebarContext } from './context';
import { SidebarUserItem } from './SidebarUserItem';
import { TRANSITION_TIMEOUT } from './constants';
import { Sheet } from '../Sheet/Sheet';
import { StyledUserAvatar } from './partials/StyledUserAvatar';
import { StyledUserSheetButton } from './partials/StyledUserSheetButton';
import { StyledUser } from './partials/StyledUser';
import { StyledSheetList } from './partials/StyledSheetList';
import { StyledUserText } from './partials/StyledUserText';
var SidebarAvatarWithItems = function SidebarAvatarWithItems(_ref) {
  var initials = _ref.initials,
    initialIsOpen = _ref.initialIsOpen,
    userLink = _ref.userLink,
    exitLink = _ref.exitLink;
  return /*#__PURE__*/React.createElement(Sheet, {
    "aria-label": "User options",
    button: /*#__PURE__*/React.createElement(StyledUserSheetButton, {
      "aria-label": "Show user options",
      icon: /*#__PURE__*/React.createElement(StyledUserAvatar, null, initials)
    }),
    initialIsOpen: initialIsOpen,
    placement: "right"
  }, /*#__PURE__*/React.createElement(StyledSheetList, null, userLink && /*#__PURE__*/React.createElement(SidebarUserItem, {
    icon: /*#__PURE__*/React.createElement(IconPerson, null),
    link: userLink
  }), exitLink && /*#__PURE__*/React.createElement(SidebarUserItem, {
    icon: /*#__PURE__*/React.createElement(IconExitToApp, null),
    link: exitLink
  })));
};
export var SidebarUser = function SidebarUser(_ref2) {
  var initials = _ref2.initials,
    initialIsOpen = _ref2.initialIsOpen,
    userLink = _ref2.userLink,
    exitLink = _ref2.exitLink,
    name = _ref2.name;
  var _useContext = useContext(SidebarContext),
    isOpen = _useContext.isOpen;
  if (!isOpen) {
    return /*#__PURE__*/React.createElement(StyledUser, null, /*#__PURE__*/React.createElement(SidebarAvatarWithItems, {
      initials: initials,
      initialIsOpen: initialIsOpen,
      userLink: userLink,
      exitLink: exitLink
    }));
  }
  return /*#__PURE__*/React.createElement(StyledUser, null, /*#__PURE__*/React.createElement(StyledUserAvatar, null, initials), /*#__PURE__*/React.createElement(Transition, {
    in: isOpen,
    timeout: TRANSITION_TIMEOUT,
    unmountOnExit: true
  }, function (state) {
    return /*#__PURE__*/React.createElement(StyledUserText, {
      $transitionStatus: state
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, name), userLink && /*#__PURE__*/React.cloneElement(userLink, _objectSpread(_objectSpread({}, userLink.props), {}, {
      children: /*#__PURE__*/React.createElement("span", null, "View Profile")
    }))), exitLink && /*#__PURE__*/React.cloneElement(exitLink, {
      children: /*#__PURE__*/React.createElement(IconExitToApp, null)
    }));
  }));
};
SidebarUser.displayName = 'SidebarUser';