"use strict";
const React = require("react");
const index = require("../../../icon/react-icon/IconClose/index.js");
const classNames = require("../../_util/classNames.js");
const iconHover = require("../../_class/icon-hover.js");
const is = require("../../_util/is.js");
const utils = require("../utils.js");
const keycode = require("../../_util/keycode.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var TabHeaderTitle = function(_a, ref) {
  var _b;
  var prefixCls = _a.prefixCls, onDeleteTab = _a.onDeleteTab, tabKey = _a.tabKey, isActive = _a.isActive, onClickTab = _a.onClickTab, _c = _a.disabled, disabled = _c === void 0 ? false : _c, title = _a.title, editable = _a.editable, renderTitle = _a.renderTitle, deleteIcon = _a.deleteIcon, deleteButton = _a.deleteButton, getIdPrefix = _a.getIdPrefix, index$1 = _a.index;
  var render = is.isFunction(renderTitle) ? renderTitle : function(node) {
    return node;
  };
  var handleDeleteTab = function(e) {
    e.stopPropagation();
    if (disabled)
      return;
    onDeleteTab();
  };
  var handleTabClick = function(e) {
    if (disabled)
      return;
    onClickTab(e);
  };
  return render(/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
    ref,
    className: classNames(prefixCls + "-header-title", (_b = {}, _b[prefixCls + "-header-title-active"] = isActive, _b[prefixCls + "-header-title-editable"] = editable, _b[prefixCls + "-header-title-disabled"] = disabled, _b)),
    role: "tab",
    "aria-selected": isActive,
    tabIndex: disabled ? -1 : 0,
    "aria-disabled": disabled || void 0,
    id: getIdPrefix(index$1).tab,
    "aria-controls": getIdPrefix(index$1).tabpane,
    onClick: handleTabClick,
    onKeyDown: function(event) {
      var keyCode = event.keyCode || event.which;
      if (keyCode === keycode.Enter.code) {
        handleTabClick(event);
      }
    },
    children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      className: prefixCls + "-header-title-text",
      children: title
    }), editable && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      ...__assign({
        role: "button",
        "aria-label": "remove tab",
        "aria-disabled": disabled || void 0,
        tabIndex: disabled ? -1 : 0,
        className: prefixCls + "-close-icon"
      }, utils.getKeyDownEvent({
        onPressEnter: handleDeleteTab
      }), {
        onClick: handleDeleteTab
      }),
      children: deleteButton || /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(iconHover, {
        prefix: prefixCls,
        children: deleteIcon || /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index, {})
      })
    })]
  }, tabKey), {
    key: tabKey,
    isActive,
    disabled,
    editable
  });
};
const TabHeaderTitle$1 = React__default.default.forwardRef(TabHeaderTitle);
module.exports = TabHeaderTitle$1;
//# sourceMappingURL=tab-title.js.map
