"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.VerticalNavItemLabel = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _Icons = require("../Icons");
var _jsxRuntime = require("preact/compat/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const DEFAULT_COMPONENT_TYPE = 'div';
const VerticalNavItemLabel = props => {
  /**
   * The type of element rendered ultimately depends on whether
   * this is meant to be a subnav toggle, link, or generic label
   * @return {String} The type of HTML tag
   */
  const componentType = () => {
    if (props.hasSubnav) {
      return 'button';
    } else if (props.component) {
      return props.component;
    } else if (props.url) {
      return 'a';
    }
    return DEFAULT_COMPONENT_TYPE;
  };
  const LabelComponent = componentType();
  const handleClick = evt => props.onClick(evt);
  const commonProps = {
    className: (0, _classnames.default)('ds-c-vertical-nav__label', {
      'ds-c-vertical-nav__label--current': props.selected,
      'ds-c-vertical-nav__label--parent': props.hasSubnav
    }),
    onClick: props.onClick ? handleClick : undefined
  };
  let otherProps;
  if (LabelComponent === 'button') {
    otherProps = {
      'aria-controls': props.subnavId,
      'aria-expanded': !props.collapsed
    };
  } else if (LabelComponent !== DEFAULT_COMPONENT_TYPE) {
    // Apply href if <a> or custom component type
    otherProps = {
      'aria-current': props.selected,
      href: props.url
    };
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(LabelComponent, {
    ...commonProps,
    ...otherProps,
    children: [props.label, props.hasSubnav && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icons.ArrowIcon, {
      direction: props.collapsed ? 'down' : 'up'
    })]
  });
};
exports.VerticalNavItemLabel = VerticalNavItemLabel;
var _default = exports.default = VerticalNavItemLabel;