import { defineComponent, inject, ref, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { Col } from '../../grid/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { ListContextKey } from './contextKey.mjs';
import AListItemMeta from './ItemMeta.mjs';
import { listItemProps } from './props.mjs';
import { isStringElement, isEmptyElement } from '../../../utils/is.mjs';
import { flattenChildren } from '../../../utils/vue/props.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import { cloneElement } from '../../../utils/vue/vnode.mjs';

var AListItem = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AListItem",
  inheritAttrs: false,
  Meta: AListItemMeta,
  props: listItemProps(),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      itemLayout,
      grid
    } = inject(ListContextKey, {
      grid: ref(),
      itemLayout: ref()
    });
    const {
      prefixCls
    } = useConfigInject("list", props);
    const isItemContainsTextNodeAndNotSingular = () => {
      var _a;
      const children = ((_a = slots.default) == null ? void 0 : _a.call(slots)) || [];
      let result;
      children.forEach((element) => {
        if (isStringElement(element) && !isEmptyElement(element))
          result = true;
      });
      return result && children.length > 1;
    };
    const isFlexMode = () => {
      var _a, _b;
      const extra = (_b = props.extra) != null ? _b : (_a = slots.extra) == null ? void 0 : _a.call(slots);
      if (itemLayout.value === "vertical")
        return !!extra;
      return !isItemContainsTextNodeAndNotSingular();
    };
    return () => {
      var _a, _b, _c, _d, _e;
      const {
        class: className,
        ...restAttrs
      } = attrs;
      const pre = prefixCls.value;
      const extra = (_b = props.extra) != null ? _b : (_a = slots.extra) == null ? void 0 : _a.call(slots);
      const children = (_c = slots.default) == null ? void 0 : _c.call(slots);
      let actions = (_e = props.actions) != null ? _e : flattenChildren((_d = slots.actions) == null ? void 0 : _d.call(slots));
      actions = actions && !Array.isArray(actions) ? [actions] : actions;
      const actionsContent = actions && actions.length > 0 && createVNode("ul", {
        "class": `${pre}-item-action`,
        "key": "actions"
      }, [actions.map((action, i) => {
        return createVNode("li", {
          "key": `${pre}-item-action-${i}`
        }, [action, i !== actions.length - 1 && createVNode("em", {
          "class": `${pre}-item-action-split`
        }, null)]);
      })]);
      const Element = grid.value ? "div" : "li";
      const itemChildren = createVNode(Element, {
        ...restAttrs,
        "class": classNames(`${pre}-item`, {
          [`${pre}-item-no-flex`]: !isFlexMode()
        }, className)
      }, {
        default: () => [itemLayout.value === "vertical" && extra ? [createVNode("div", {
          "class": `${pre}-item-main`,
          "key": "content"
        }, [children, actionsContent]), createVNode("div", {
          "class": `${pre}-item-extra`,
          "key": "extra"
        }, [extra])] : [children, actionsContent, cloneElement(extra, {
          key: "extra"
        })]]
      });
      return grid.value ? createVNode(Col, {
        "flex": 1,
        "style": props.colStyle
      }, {
        default: () => [itemChildren]
      }) : itemChildren;
    };
  }
});

export { AListItem as default };
//# sourceMappingURL=Item.mjs.map
