"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.Tab = void 0;
var _compat = _interopRequireWildcard(require("preact/compat"));
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); }
var Tab = (0, _compat.forwardRef)(function (props, ref) {
  var defaultProps = {
    selected: false
  };
  var href = props.href || "#".concat(props.panelId);
  var classes = (0, _classnames.default)('ds-c-tabs__item', props.className);
  var sharedTabProps = {
    role: 'tab',
    className: classes,
    id: props.id,
    ref: ref
  };
  var handleClick = function handleClick(evt) {
    var onClick = props.onClick,
      panelId = props.panelId,
      id = props.id;
    if (onClick) {
      onClick(evt, panelId, id, href);
    }
  };
  var handleKeyDown = function handleKeyDown(evt) {
    var onKeyDown = props.onKeyDown,
      panelId = props.panelId,
      id = props.id;
    if (onKeyDown) {
      onKeyDown(evt, panelId, id, href);
    }
  };
  return !props.disabled ? /*#__PURE__*/_compat.default.createElement("a", _extends({
    "aria-selected": props.selected || defaultProps.selected,
    "aria-controls": props.panelId,
    href: href,
    onClick: handleClick,
    onKeyDown: handleKeyDown
  }, sharedTabProps), props.children) : /*#__PURE__*/_compat.default.createElement("span", _extends({
    "aria-disabled": "true"
  }, sharedTabProps), props.children);
});
exports.Tab = Tab;
Tab.displayName = 'Tab';
var _default = Tab;
exports.default = _default;