"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.Tab = void 0;
var _compat = require("preact/compat");
var _classnames = _interopRequireDefault(require("classnames"));
var _jsxRuntime = require("preact/compat/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Tab = exports.Tab = (0, _compat.forwardRef)((props, ref) => {
  const defaultProps = {
    selected: false
  };
  const href = props.href || `#${props.panelId}`;
  const classes = (0, _classnames.default)('ds-c-tabs__item', props.className);
  const sharedTabProps = {
    role: 'tab',
    className: classes,
    id: props.id,
    ref: ref
  };
  const handleClick = evt => {
    const {
      onClick,
      panelId,
      id
    } = props;
    if (onClick) {
      onClick(evt, panelId, id, href);
    }
  };
  const handleKeyDown = evt => {
    const {
      onKeyDown,
      panelId,
      id
    } = props;
    if (onKeyDown) {
      onKeyDown(evt, panelId, id, href);
    }
  };
  return !props.disabled ? /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
    "aria-selected": props.selected || defaultProps.selected,
    "aria-controls": props.panelId,
    href: href,
    onClick: handleClick,
    onKeyDown: handleKeyDown,
    ...sharedTabProps,
    children: props.children
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
    "aria-disabled": "true",
    ...sharedTabProps,
    children: props.children
  });
});
Tab.displayName = 'Tab';
var _default = exports.default = Tab;