import { isVNode, defineComponent, inject, ref, createVNode, mergeProps } from 'vue';
import PropTypes from '../_util/vue-types/index.mjs';
import classNames from '../_util/classNames.mjs';
import { isStringElement, isEmptyElement, flattenChildren } from '../_util/props-util/index.mjs';
import '../grid/index.mjs';
import { cloneElement } from '../_util/vnode.mjs';
import '../hooks/index.mjs';
import { ListContextKey } from './contextKey.mjs';
import ItemMeta from './ItemMeta.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';
import Col from '../grid/Col.mjs';

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
const listItemProps = () => ({
  prefixCls: String,
  extra: PropTypes.any,
  actions: Array,
  grid: Object,
  colStyle: {
    type: Object,
    default: void 0
  }
});
var Item = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AListItem",
  inheritAttrs: false,
  Meta: ItemMeta,
  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) => 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, mergeProps(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
      }, _isSlot(itemChildren) ? itemChildren : {
        default: () => [itemChildren]
      }) : itemChildren;
    };
  }
});

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