import { isVNode, computed, defineComponent, createVNode, mergeProps } from 'vue';
import { isEmpty } from 'lodash-es';
import '../hooks/index.mjs';
import classNames from '../_util/classNames.mjs';
import { booleanType } from '../_util/type.mjs';
import { flattenChildren } from '../_util/props-util/index.mjs';
import useStyle from './style/index.mjs';
import { createContext } from '../hooks/createContext.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
const spaceCompactItemProps = () => ({
  compactSize: String,
  compactDirection: {
    type: String,
    validator: (s) => ["horizontal", "vertical"].includes(s),
    default: "horizontal"
  },
  isFirstItem: booleanType(),
  isLastItem: booleanType()
});
const SpaceCompactItemContext = createContext(null);
const useCompactItemContext = (prefixCls, direction) => {
  const compactItemContext = SpaceCompactItemContext.useInject();
  const compactItemClassnames = computed(() => {
    if (!compactItemContext || isEmpty(compactItemContext))
      return "";
    const {
      compactDirection,
      isFirstItem,
      isLastItem
    } = compactItemContext;
    const separator = compactDirection === "vertical" ? "-vertical-" : "-";
    return classNames({
      [`${prefixCls.value}-compact${separator}item`]: true,
      [`${prefixCls.value}-compact${separator}first-item`]: isFirstItem,
      [`${prefixCls.value}-compact${separator}last-item`]: isLastItem,
      [`${prefixCls.value}-compact${separator}item-rtl`]: direction.value === "rtl"
    });
  });
  return {
    compactSize: computed(() => compactItemContext == null ? void 0 : compactItemContext.compactSize),
    compactDirection: computed(() => compactItemContext == null ? void 0 : compactItemContext.compactDirection),
    compactItemClassnames
  };
};
const NoCompactStyle = /* @__PURE__ */ defineComponent({
  name: "NoCompactStyle",
  setup(_, {
    slots
  }) {
    SpaceCompactItemContext.useProvide(null);
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});
const spaceCompactProps = () => ({
  prefixCls: String,
  size: {
    type: String
  },
  direction: {
    type: String,
    validator: (s) => ["horizontal", "vertical"].includes(s),
    default: "horizontal"
  },
  align: {
    type: String,
    validator: (s) => ["start", "end", "center", "baseline"].includes(s)
  },
  block: {
    type: Boolean,
    default: void 0
  }
});
const CompactItem = /* @__PURE__ */ defineComponent({
  name: "CompactItem",
  props: spaceCompactItemProps(),
  setup(props, {
    slots
  }) {
    SpaceCompactItemContext.useProvide(props);
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});
const Compact = /* @__PURE__ */ defineComponent({
  name: "ASpaceCompact",
  inheritAttrs: false,
  props: spaceCompactProps(),
  setup(props, {
    attrs,
    slots
  }) {
    const {
      prefixCls,
      direction: directionConfig
    } = useConfigInject("space-compact", props);
    const compactItemContext = SpaceCompactItemContext.useInject();
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const clx = computed(() => {
      return classNames(prefixCls.value, hashId.value, {
        [`${prefixCls.value}-rtl`]: directionConfig.value === "rtl",
        [`${prefixCls.value}-block`]: props.block,
        [`${prefixCls.value}-vertical`]: props.direction === "vertical"
      });
    });
    return () => {
      var _a;
      const childNodes = flattenChildren(((_a = slots.default) == null ? void 0 : _a.call(slots)) || []);
      if (childNodes.length === 0)
        return null;
      return wrapSSR(createVNode("div", mergeProps(attrs, {
        "class": [clx.value, attrs.class]
      }), [childNodes.map((child, i) => {
        var _a2;
        const key = child && child.key || `${prefixCls.value}-item-${i}`;
        const noCompactItemContext = !compactItemContext || isEmpty(compactItemContext);
        return createVNode(CompactItem, {
          "key": key,
          "compactSize": (_a2 = props.size) != null ? _a2 : "middle",
          "compactDirection": props.direction,
          "isFirstItem": i === 0 && (noCompactItemContext || (compactItemContext == null ? void 0 : compactItemContext.isFirstItem)),
          "isLastItem": i === childNodes.length - 1 && (noCompactItemContext || (compactItemContext == null ? void 0 : compactItemContext.isLastItem))
        }, _isSlot(child) ? child : {
          default: () => [child]
        });
      })]));
    };
  }
});

export { NoCompactStyle, SpaceCompactItemContext, Compact as default, spaceCompactItemProps, spaceCompactProps, useCompactItemContext };
//# sourceMappingURL=Compact.mjs.map
