'use strict';

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

var vue = require('vue');
var lodashEs = require('lodash-es');
require('../hooks/index.js');
var classNames = require('../_util/classNames.js');
var type = require('../_util/type.js');
var index$1 = require('../_util/props-util/index.js');
var index = require('./style/index.js');
var createContext = require('../hooks/createContext.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const spaceCompactItemProps = () => ({
  compactSize: String,
  compactDirection: {
    type: String,
    validator: (s) => ["horizontal", "vertical"].includes(s),
    default: "horizontal"
  },
  isFirstItem: type.booleanType(),
  isLastItem: type.booleanType()
});
const SpaceCompactItemContext = createContext.createContext(null);
const useCompactItemContext = (prefixCls, direction) => {
  const compactItemContext = SpaceCompactItemContext.useInject();
  const compactItemClassnames = vue.computed(() => {
    if (!compactItemContext || lodashEs.isEmpty(compactItemContext))
      return "";
    const {
      compactDirection,
      isFirstItem,
      isLastItem
    } = compactItemContext;
    const separator = compactDirection === "vertical" ? "-vertical-" : "-";
    return classNames.default({
      [`${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: vue.computed(() => compactItemContext == null ? void 0 : compactItemContext.compactSize),
    compactDirection: vue.computed(() => compactItemContext == null ? void 0 : compactItemContext.compactDirection),
    compactItemClassnames
  };
};
const NoCompactStyle = /* @__PURE__ */ vue.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__ */ vue.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__ */ vue.defineComponent({
  name: "ASpaceCompact",
  inheritAttrs: false,
  props: spaceCompactProps(),
  setup(props, {
    attrs,
    slots
  }) {
    const {
      prefixCls,
      direction: directionConfig
    } = useConfigInject.default("space-compact", props);
    const compactItemContext = SpaceCompactItemContext.useInject();
    const [wrapSSR, hashId] = index.default(prefixCls);
    const clx = vue.computed(() => {
      return classNames.default(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 = index$1.flattenChildren(((_a = slots.default) == null ? void 0 : _a.call(slots)) || []);
      if (childNodes.length === 0)
        return null;
      return wrapSSR(vue.createVNode("div", vue.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 || lodashEs.isEmpty(compactItemContext);
        return vue.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]
        });
      })]));
    };
  }
});

exports.NoCompactStyle = NoCompactStyle;
exports.SpaceCompactItemContext = SpaceCompactItemContext;
exports.default = Compact;
exports.spaceCompactItemProps = spaceCompactItemProps;
exports.spaceCompactProps = spaceCompactProps;
exports.useCompactItemContext = useCompactItemContext;
//# sourceMappingURL=Compact.js.map
