'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var index = require('../../grid/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var contextKey = require('./contextKey.cjs');
var ItemMeta = require('./ItemMeta.cjs');
var props = require('./props.cjs');
var is = require('../../../utils/is.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var _class = require('../../../utils/dom/class.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');

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

exports.default = AListItem;
//# sourceMappingURL=Item.cjs.map
