import { defineComponent, createVNode, withDirectives, vShow, Transition } from 'vue';
import '../../../utils/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { collapsePanelProps } from './props.mjs';
import PanelContent from './PanelContent.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { classNames } from '../../../utils/dom/class.mjs';

var ACollapsePanel = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACollapsePanel",
  inheritAttrs: false,
  props: initDefaultProps(collapsePanelProps(), {
    showArrow: true,
    isActive: false,
    onItemClick() {
    },
    headerClass: "",
    forceRender: false
  }),
  slots: Object,
  // emits: ['itemClick'],
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    devWarning(props.disabled === void 0, "Collapse.Panel", '`disabled` is deprecated. Please use `collapsible="disabled"` instead.');
    const {
      prefixCls
    } = useConfigInject("collapse", props);
    const handleItemClick = () => {
      emit("itemClick", props.panelKey);
    };
    const handleKeyPress = (e) => {
      if (e.key === "Enter" || e.keyCode === 13 || e.which === 13)
        handleItemClick();
    };
    return () => {
      var _a, _b;
      const {
        header = (_a = slots.header) == null ? void 0 : _a.call(slots),
        headerClass,
        isActive,
        showArrow,
        destroyInactivePanel,
        accordion,
        forceRender,
        openAnimation,
        expandIcon = slots.expandIcon,
        extra = (_b = slots.extra) == null ? void 0 : _b.call(slots),
        collapsible
      } = props;
      const disabled = collapsible === "disabled";
      const prefixClsValue = prefixCls.value;
      const headerCls = classNames(`${prefixClsValue}-header`, {
        [headerClass]: headerClass,
        [`${prefixClsValue}-header-collapsible-only`]: collapsible === "header",
        [`${prefixClsValue}-icon-collapsible-only`]: collapsible === "icon"
      });
      const itemCls = classNames({
        [`${prefixClsValue}-item`]: true,
        [`${prefixClsValue}-item-active`]: isActive,
        [`${prefixClsValue}-item-disabled`]: disabled,
        [`${prefixClsValue}-no-arrow`]: !showArrow,
        [`${attrs.class}`]: !!attrs.class
      });
      let icon = createVNode("i", {
        "class": "arrow"
      }, null);
      if (showArrow && typeof expandIcon === "function")
        icon = expandIcon(props);
      const panelContent = withDirectives(createVNode(PanelContent, {
        "prefixCls": prefixClsValue,
        "isActive": isActive,
        "forceRender": forceRender,
        "role": accordion ? "tabpanel" : null
      }, {
        default: slots.default
      }), [[vShow, isActive]]);
      const transitionProps = {
        appear: false,
        css: false,
        ...openAnimation
      };
      return createVNode("div", {
        ...attrs,
        "class": itemCls
      }, [createVNode("div", {
        "class": headerCls,
        "onClick": () => !["header", "icon"].includes(collapsible) && handleItemClick(),
        "role": accordion ? "tab" : "button",
        "tabindex": disabled ? -1 : 0,
        "aria-expanded": isActive,
        "onKeypress": handleKeyPress
      }, [showArrow && icon, createVNode("span", {
        "onClick": () => collapsible === "header" && handleItemClick(),
        "class": `${prefixClsValue}-header-text`
      }, [header]), extra && createVNode("div", {
        "class": `${prefixClsValue}-extra`
      }, [extra])]), createVNode(Transition, transitionProps, {
        default: () => [!destroyInactivePanel || isActive ? panelContent : null]
      })]);
    };
  }
});

export { ACollapsePanel as default };
//# sourceMappingURL=CollapsePanel.mjs.map
