'use strict';

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

var vue = require('vue');
var index = require('../_util/vue-types/index.js');
var classNames = require('../_util/classNames.js');
var index$1 = require('../_util/props-util/index.js');
require('../grid/index.js');
var vnode = require('../_util/vnode.js');
require('../hooks/index.js');
var contextKey = require('./contextKey.js');
var ItemMeta = require('./ItemMeta.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Col = require('../grid/Col.js');

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

exports.default = Item;
exports.listItemProps = listItemProps;
//# sourceMappingURL=Item.js.map
