var _excluded = ["hasDefaultLogo", "hasUnreadNotification", "homeLink", "initialOpenSubcomponent", "Logo", "nav", "notifications", "onSearch", "title", "user"];
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 _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; }
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, { useRef } from 'react';
import { Logo as DefaultLogo } from './Logo';
import { MASTHEAD_SUBCOMPONENT } from './constants';
import { Sheet } from '../Sheet/Sheet';
import { SheetButton } from '../Sheet/SheetButton';
import { useMastheadSearch } from './useMastheadSearch';
import { StyledOption } from './partials/StyledOption';
import { StyledOptions } from './partials/StyledOptions';
import { StyledMain } from './partials/StyledMain';
import { StyledMastHead } from './partials/StyledMasthead';
import { StyledServiceName } from './partials/StyledServiceName';
import { StyledTitle } from './partials/StyledTitle';
import { StyledVerticalSeparator } from './partials/StyledVerticalSeparator';
import { StyledBanner } from './partials/StyledBanner';
import { SearchBar } from '../SearchBar/SearchBar';
import { StyledNotRead } from '../NotificationPanel/partials/StyledNotRead';
import { StyledIconNotifications } from './partials/StyledIconNotifications';
import { StyledIconSearch } from './partials/StyledIconSearch';
function getServiceName(homeLink, Logo, title) {
  var link = homeLink || /*#__PURE__*/React.createElement("span", null);
  return /*#__PURE__*/React.cloneElement(link, _objectSpread(_objectSpread({}, link.props), {}, {
    children: /*#__PURE__*/React.createElement(StyledServiceName, null, Logo && /*#__PURE__*/React.cloneElement( /*#__PURE__*/React.createElement(Logo, null), {
      role: 'presentation'
    }), /*#__PURE__*/React.createElement(StyledTitle, {
      $hasLogo: !!Logo
    }, title))
  }));
}
export var Masthead = function Masthead(_ref) {
  var _ref$hasDefaultLogo = _ref.hasDefaultLogo,
    hasDefaultLogo = _ref$hasDefaultLogo === void 0 ? true : _ref$hasDefaultLogo,
    hasUnreadNotification = _ref.hasUnreadNotification,
    _ref$homeLink = _ref.homeLink,
    homeLink = _ref$homeLink === void 0 ? null : _ref$homeLink,
    initialOpenSubcomponent = _ref.initialOpenSubcomponent,
    Logo = _ref.Logo,
    nav = _ref.nav,
    notifications = _ref.notifications,
    onSearch = _ref.onSearch,
    title = _ref.title,
    user = _ref.user,
    rest = _objectWithoutProperties(_ref, _excluded);
  var searchButtonRef = useRef(null);
  var _useMastheadSearch = useMastheadSearch(initialOpenSubcomponent === MASTHEAD_SUBCOMPONENT.SEARCH),
    containerWidth = _useMastheadSearch.containerWidth,
    mastheadRef = _useMastheadSearch.mastheadRef,
    setShowSearch = _useMastheadSearch.setShowSearch,
    showSearch = _useMastheadSearch.showSearch,
    toggleSearch = _useMastheadSearch.toggleSearch;
  var DisplayLogo = Logo !== null && Logo !== void 0 ? Logo : hasDefaultLogo ? DefaultLogo : null;
  var submitSearch = function submitSearch(e, term) {
    onSearch === null || onSearch === void 0 ? void 0 : onSearch(e, term);
    setShowSearch(false);
  };
  return /*#__PURE__*/React.createElement(StyledMastHead, _extends({
    ref: mastheadRef
  }, rest), /*#__PURE__*/React.createElement(StyledMain, null, /*#__PURE__*/React.createElement(StyledBanner, {
    role: "banner"
  }, getServiceName(homeLink, DisplayLogo, title)), /*#__PURE__*/React.createElement(StyledOptions, null, onSearch && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledOption, {
    $isActive: showSearch,
    "aria-expanded": showSearch,
    "aria-label": "Show search",
    as: "button",
    onClick: toggleSearch,
    ref: searchButtonRef
  }, /*#__PURE__*/React.createElement(StyledIconSearch, null)), user && /*#__PURE__*/React.createElement(StyledVerticalSeparator, null, /*#__PURE__*/React.createElement("line", {
    x1: "0",
    y1: "14",
    x2: "0",
    y2: "44"
  }))), notifications && /*#__PURE__*/React.createElement(Sheet, {
    "aria-label": "Notifications",
    button: /*#__PURE__*/React.createElement(StyledOption, {
      "aria-label": "Show notifications",
      as: SheetButton,
      icon: /*#__PURE__*/React.createElement(StyledIconNotifications, null)
    }, hasUnreadNotification && /*#__PURE__*/React.createElement(StyledNotRead, null)),
    initialIsOpen: initialOpenSubcomponent === MASTHEAD_SUBCOMPONENT.NOTIFICATIONS,
    placement: "bottom"
  }, notifications), (notifications || onSearch) && user && /*#__PURE__*/React.createElement(StyledVerticalSeparator, null, /*#__PURE__*/React.createElement("line", {
    x1: "0",
    y1: "14",
    x2: "0",
    y2: "44"
  })), user)), onSearch && showSearch && /*#__PURE__*/React.createElement(SearchBar, {
    onSearch: submitSearch,
    searchButtonRef: searchButtonRef,
    setShowSearch: setShowSearch,
    containerWidth: containerWidth
  }), nav);
};
Masthead.displayName = 'Masthead';