var _excluded = ["icon", "title", "children", "user", "hasUnreadNotification", "notifications", "initialIsNotificationsOpen", "initialIsOpen"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useRef } from 'react';
import { Transition } from 'react-transition-group';
import { SidebarHandle } from './SidebarHandle';
import { SidebarNotifications } from './SidebarNotifications';
import { SidebarContext, SidebarProvider } from './context';
import { TRANSITION_TIMEOUT } from './constants';
import { StyledSidebar } from './partials/StyledSidebar';
import { StyledHead } from './partials/StyledHead';
import { StyledHeadIcon } from './partials/StyledHeadIcon';
import { StyledHeadTitle } from './partials/StyledHeadTitle';
export var Sidebar = function Sidebar(_ref) {
  var icon = _ref.icon,
    title = _ref.title,
    children = _ref.children,
    user = _ref.user,
    hasUnreadNotification = _ref.hasUnreadNotification,
    notifications = _ref.notifications,
    initialIsNotificationsOpen = _ref.initialIsNotificationsOpen,
    _ref$initialIsOpen = _ref.initialIsOpen,
    initialIsOpen = _ref$initialIsOpen === void 0 ? false : _ref$initialIsOpen,
    rest = _objectWithoutProperties(_ref, _excluded);
  var nodeRef = useRef(null);
  return /*#__PURE__*/React.createElement(SidebarProvider, {
    initialIsOpen: initialIsOpen
  }, /*#__PURE__*/React.createElement(SidebarContext.Consumer, null, function (_ref2) {
    var isOpen = _ref2.isOpen,
      hasMouseOver = _ref2.hasMouseOver,
      setHasMouseOver = _ref2.setHasMouseOver;
    return /*#__PURE__*/React.createElement(StyledSidebar, _extends({
      isOpen: isOpen,
      onMouseEnter: function onMouseEnter(_) {
        return setHasMouseOver(true);
      },
      onMouseLeave: function onMouseLeave(_) {
        return setHasMouseOver(false);
      }
    }, rest), /*#__PURE__*/React.createElement(Transition, {
      nodeRef: nodeRef,
      in: hasMouseOver,
      timeout: 0,
      unmountOnExit: true
    }, function (state) {
      return /*#__PURE__*/React.createElement(SidebarHandle, {
        ref: nodeRef,
        transitionStatus: state
      });
    }), title && /*#__PURE__*/React.createElement(StyledHead, null, icon && /*#__PURE__*/React.createElement(StyledHeadIcon, null, icon), /*#__PURE__*/React.createElement(Transition, {
      in: isOpen,
      timeout: TRANSITION_TIMEOUT,
      unmountOnExit: true
    }, function (state) {
      return /*#__PURE__*/React.createElement(StyledHeadTitle, {
        $transitionStatus: state
      }, title);
    })), children, notifications && /*#__PURE__*/React.createElement(SidebarNotifications, {
      initialIsOpen: initialIsNotificationsOpen,
      notifications: notifications,
      hasUnreadNotification: hasUnreadNotification
    }), user);
  }));
};
Sidebar.displayName = 'Sidebar';