import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import { Header as Header$2, SkipToContent, HeaderMenuButton, HeaderName } from '@carbon/react';
import PropTypes from 'prop-types';
import React__default from 'react';
import { settings } from '../../constants/Settings.js';
import HeaderActionGroup from './HeaderActionGroup.js';
import { HeaderActionItemPropTypes, HeaderPanelPropTypes } from './HeaderPropTypes.js';
import { APP_SWITCHER } from './headerConstants.js';
import { Switcher } from '@carbon/icons-react';

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(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 carbonPrefix = settings.prefix,
  iotPrefix = settings.iotPrefix;
var propTypes = {
  /** Add a prefix other than IBM */
  prefix: PropTypes.string,
  /** Name to follow the IBM prefix up top, left */
  appName: PropTypes.string.isRequired,
  /** Short name to follow the IBM prefix at top, left on smaller breakpoints */
  // eslint-disable-next-line react/require-default-props, uses appName is none provided
  shortAppName: PropTypes.string,
  /** Optional prop that provides additional app information */
  subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
  /** Add a class name to Header */
  className: PropTypes.string,
  /** Provide ID for the skip to content functionality */
  skipto: PropTypes.string,
  /** href optional url to file if you click on title */
  url: PropTypes.string,
  /** Object of action items */
  actionItems: PropTypes.arrayOf(PropTypes.shape(HeaderActionItemPropTypes)).isRequired,
  /** Bit to flip that tells header to render the nav toggle button */
  hasSideNav: PropTypes.bool,
  onClickSideNavExpand: PropTypes.func,
  /** Main app switcher Header panel props */
  headerPanel: PropTypes.shape(HeaderPanelPropTypes),
  /** App switcher label */
  appSwitcherLabel: PropTypes.string,
  i18n: PropTypes.shape({
    mainHeader: PropTypes.string,
    openMenu: PropTypes.string,
    closeMenu: PropTypes.string
  }),
  testId: PropTypes.string,
  /** Returns true, if the icon should be shown. (actionItem) => {} */
  isActionItemVisible: PropTypes.func,
  /** allows setting aria-label on side-nav menu button correctly */
  isSideNavExpanded: PropTypes.bool,
  /** Make sure the Close icon is always displayed in the HeaderActionPanel action item when the panel is expanded */
  showCloseIconWhenPanelExpanded: PropTypes.bool,
  /** Optional callback when user clicks on header name */
  handleHeaderNameClick: PropTypes.func
};

// istanbul ignore next
var defaultProps = {
  onClickSideNavExpand: null,
  hasSideNav: true,
  prefix: 'IBM',
  className: 'main-header',
  skipto: '#main-content',
  headerPanel: null,
  subtitle: null,
  url: '#',
  appSwitcherLabel: APP_SWITCHER,
  i18n: {
    mainHeader: 'main header',
    openMenu: 'Open menu',
    closeMenu: 'Close menu'
  },
  testId: 'header',
  isActionItemVisible: function isActionItemVisible() {
    return true;
  },
  isSideNavExpanded: false,
  showCloseIconWhenPanelExpanded: false,
  handleHeaderNameClick: function handleHeaderNameClick() {
    return null;
  }
};

/**
 * UI header with multiple side panels functionality and dropdowns
 */
var Header = function Header(_ref) {
  var appName = _ref.appName,
    shortAppName = _ref.shortAppName,
    subtitle = _ref.subtitle,
    className = _ref.className,
    actionItemsProp = _ref.actionItems,
    prefix = _ref.prefix,
    skipto = _ref.skipto,
    hasSideNav = _ref.hasSideNav,
    onClickSideNavExpand = _ref.onClickSideNavExpand,
    headerPanel = _ref.headerPanel,
    url = _ref.url,
    appSwitcherLabel = _ref.appSwitcherLabel,
    i18n = _ref.i18n,
    testId = _ref.testId,
    isActionItemVisible = _ref.isActionItemVisible,
    isSideNavExpanded = _ref.isSideNavExpanded,
    showCloseIconWhenPanelExpanded = _ref.showCloseIconWhenPanelExpanded,
    handleHeaderNameClick = _ref.handleHeaderNameClick;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var theShortAppName = shortAppName || appName;
  var actionItems = !headerPanel ? actionItemsProp : [].concat(_toConsumableArray(actionItemsProp), [{
    id: 'app-switcher',
    label: appSwitcherLabel,
    hasHeaderPanel: true,
    btnContent: /*#__PURE__*/React__default.createElement(Switcher, {
      size: 20,
      fill: "white",
      className: "".concat(carbonPrefix, "--header__menu-item ").concat(carbonPrefix, "--header__menu-title")
    }),
    childContent: [{
      metaData: {
        className: "".concat(carbonPrefix, "--app-switcher ").concat(headerPanel.className),
        element: 'a'
      },
      content: /*#__PURE__*/React__default.createElement(headerPanel.content, null)
    }]
  }]);
  return /*#__PURE__*/React__default.createElement(Header$2, {
    "data-testid": testId,
    className: className,
    "aria-label": mergedI18n.mainHeader
  }, /*#__PURE__*/React__default.createElement(SkipToContent, {
    href: skipto
  }), hasSideNav && /*#__PURE__*/React__default.createElement(HeaderMenuButton, {
    "data-testid": "".concat(testId, "-menu-button"),
    "aria-label": isSideNavExpanded ? mergedI18n.closeMenu : mergedI18n.openMenu,
    onClick: onClickSideNavExpand,
    isActive: isSideNavExpanded
  }), /*#__PURE__*/React__default.createElement(HeaderName, {
    "data-testid": "".concat(testId, "-name"),
    href: url,
    onClick: handleHeaderNameClick,
    prefix: prefix
  }, /*#__PURE__*/React__default.createElement("span", null, appName), theShortAppName ? /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(iotPrefix, "--header__short-name")
  }, theShortAppName) : null, subtitle ? /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--header__subtitle")
  }, subtitle) : null), /*#__PURE__*/React__default.createElement(HeaderActionGroup, {
    actionItems: actionItems,
    i18n: mergedI18n,
    testId: "".concat(testId, "-action-group"),
    isActionItemVisible: isActionItemVisible,
    showCloseIconWhenPanelExpanded: showCloseIconWhenPanelExpanded
  }));
};
Header.propTypes = propTypes;
Header.defaultProps = defaultProps;
Header.__docgenInfo = {
  "description": "UI header with multiple side panels functionality and dropdowns",
  "methods": [],
  "displayName": "Header",
  "props": {
    "onClickSideNavExpand": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "hasSideNav": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "description": "Bit to flip that tells header to render the nav toggle button",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "prefix": {
      "defaultValue": {
        "value": "'IBM'",
        "computed": false
      },
      "description": "Add a prefix other than IBM",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "className": {
      "defaultValue": {
        "value": "'main-header'",
        "computed": false
      },
      "description": "Add a class name to Header",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "skipto": {
      "defaultValue": {
        "value": "'#main-content'",
        "computed": false
      },
      "description": "Provide ID for the skip to content functionality",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "headerPanel": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Main app switcher Header panel props",
      "type": {
        "name": "shape",
        "value": "import { HeaderActionItemPropTypes, HeaderPanelPropTypes } from './HeaderPropTypes';",
        "computed": true
      },
      "required": false
    },
    "subtitle": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Optional prop that provides additional app information",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "element"
        }]
      },
      "required": false
    },
    "url": {
      "defaultValue": {
        "value": "'#'",
        "computed": false
      },
      "description": "href optional url to file if you click on title",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "appSwitcherLabel": {
      "defaultValue": {
        "value": "APP_SWITCHER",
        "computed": true
      },
      "description": "App switcher label",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  mainHeader: 'main header',\n  openMenu: 'Open menu',\n  closeMenu: 'Close menu',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "mainHeader": {
            "name": "string",
            "required": false
          },
          "openMenu": {
            "name": "string",
            "required": false
          },
          "closeMenu": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'header'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isActionItemVisible": {
      "defaultValue": {
        "value": "() => true",
        "computed": false
      },
      "description": "Returns true, if the icon should be shown. (actionItem) => {}",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "isSideNavExpanded": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "allows setting aria-label on side-nav menu button correctly",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "showCloseIconWhenPanelExpanded": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Make sure the Close icon is always displayed in the HeaderActionPanel action item when the panel is expanded",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "handleHeaderNameClick": {
      "defaultValue": {
        "value": "() => null",
        "computed": false
      },
      "description": "Optional callback when user clicks on header name",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "appName": {
      "description": "Name to follow the IBM prefix up top, left",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "shortAppName": {
      "description": "Short name to follow the IBM prefix at top, left on smaller breakpoints",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "actionItems": {
      "description": "Object of action items",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import { HeaderActionItemPropTypes, HeaderPanelPropTypes } from './HeaderPropTypes';",
          "computed": true
        }
      },
      "required": true
    }
  }
};
var Header$1 = Header;

export { Header$1 as default };
