'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.cjs');
var props = require('../props.cjs');
var _class = require('../../../../utils/dom/class.cjs');
var KeyCode = require('../../../../utils/KeyCode.cjs');

var TabNode = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "TabNode",
  props: props.tabNodeProps(),
  emits: ["click", "resize", "remove", "focus"],
  setup(props, {
    expose,
    attrs
  }) {
    const domRef = vue.ref();
    function onInternalClick(e) {
      var _a;
      if ((_a = props.tab) == null ? void 0 : _a.disabled)
        return;
      props.onClick(e);
    }
    expose({
      domRef
    });
    function onRemoveTab(event) {
      var _a;
      event.preventDefault();
      event.stopPropagation();
      props.editable.onEdit("remove", {
        key: (_a = props.tab) == null ? void 0 : _a.key,
        event
      });
    }
    const removable = vue.computed(() => {
      var _a;
      return props.editable && props.closable !== false && !((_a = props.tab) == null ? void 0 : _a.disabled);
    });
    return () => {
      var _a;
      const {
        prefixCls,
        id,
        active,
        tab: {
          key,
          tab,
          disabled,
          closeIcon
        },
        renderWrapper,
        removeAriaLabel,
        editable,
        onFocus
      } = props;
      const tabPrefix = `${prefixCls}-tab`;
      const node = vue.createVNode("div", {
        "key": key,
        "ref": domRef,
        "class": _class.classNames(tabPrefix, {
          [`${tabPrefix}-with-remove`]: removable.value,
          [`${tabPrefix}-active`]: active,
          [`${tabPrefix}-disabled`]: disabled
        }),
        "style": attrs.style,
        "onClick": onInternalClick
      }, [vue.createVNode("div", {
        "role": "tab",
        "aria-selected": active,
        "id": id && `${id}-tab-${key}`,
        "class": `${tabPrefix}-btn`,
        "aria-controls": id && `${id}-panel-${key}`,
        "aria-disabled": disabled,
        "tabindex": disabled ? null : 0,
        "onClick": (e) => {
          e.stopPropagation();
          onInternalClick(e);
        },
        "onKeydown": (e) => {
          if ([KeyCode.KeyCode.SPACE, KeyCode.KeyCode.ENTER].includes(e.which)) {
            e.preventDefault();
            onInternalClick(e);
          }
        },
        "onFocus": onFocus
      }, [typeof tab === "function" ? tab() : tab]), removable.value && vue.createVNode("button", {
        "type": "button",
        "aria-label": removeAriaLabel || "remove",
        "tabindex": 0,
        "class": `${tabPrefix}-remove`,
        "onClick": (e) => {
          e.stopPropagation();
          onRemoveTab(e);
        }
      }, [(closeIcon == null ? void 0 : closeIcon()) || ((_a = editable.removeIcon) == null ? void 0 : _a.call(editable)) || "\xD7"])]);
      return renderWrapper ? renderWrapper(node) : node;
    };
  }
});

exports.default = TabNode;
//# sourceMappingURL=TabNode.cjs.map
