'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var context = require('./context.cjs');
var props = require('./props.cjs');
var _class = require('../../../utils/dom/class.cjs');

const sizes = ["xs", "sm", "md", "lg", "xl", "xxl"];
function parseFlex(flex) {
  if (typeof flex === "number")
    return `${flex} ${flex} auto`;
  if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex))
    return `0 0 ${flex}`;
  return flex;
}
var ACol = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACol",
  inheritAttrs: false,
  props: props.colProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const {
      gutter,
      supportFlexGap,
      wrap
    } = context.useInjectRow();
    const {
      prefixCls,
      direction
    } = useConfigInject.default("col", props);
    const [wrapSSR, hashId] = index.useColStyle(prefixCls);
    const classes = vue.computed(() => {
      const {
        span,
        order,
        offset,
        push,
        pull
      } = props;
      const pre = prefixCls.value;
      let sizeClassObj = {};
      sizes.forEach((size) => {
        let sizeProps = {};
        const propSize = props[size];
        if (typeof propSize === "number")
          sizeProps.span = propSize;
        else if (typeof propSize === "object")
          sizeProps = propSize || {};
        sizeClassObj = {
          ...sizeClassObj,
          [`${pre}-${size}-${sizeProps.span}`]: sizeProps.span !== void 0,
          [`${pre}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
          [`${pre}-${size}-offset-${sizeProps.offset}`]: sizeProps.offset || sizeProps.offset === 0,
          [`${pre}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
          [`${pre}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
          [`${pre}-rtl`]: direction.value === "rtl"
        };
      });
      return _class.classNames(pre, {
        [`${pre}-${span}`]: span !== void 0,
        [`${pre}-order-${order}`]: order,
        [`${pre}-offset-${offset}`]: offset,
        [`${pre}-push-${push}`]: push,
        [`${pre}-pull-${pull}`]: pull
      }, sizeClassObj, attrs.class, hashId.value);
    });
    const mergedStyle = vue.computed(() => {
      const {
        flex
      } = props;
      const gutterVal = gutter.value;
      const style = {};
      if (gutterVal && gutterVal[0] > 0) {
        const horizontalGutter = `${gutterVal[0] / 2}px`;
        style.paddingLeft = horizontalGutter;
        style.paddingRight = horizontalGutter;
      }
      if (gutterVal && gutterVal[1] > 0 && !supportFlexGap.value) {
        const verticalGutter = `${gutterVal[1] / 2}px`;
        style.paddingTop = verticalGutter;
        style.paddingBottom = verticalGutter;
      }
      if (flex) {
        style.flex = parseFlex(flex);
        if (wrap.value === false && !style.minWidth)
          style.minWidth = 0;
      }
      return style;
    });
    return () => {
      var _a;
      return wrapSSR(vue.createVNode("div", {
        ...attrs,
        "class": classes.value,
        "style": [mergedStyle.value, attrs.style]
      }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]));
    };
  }
});

exports.default = ACol;
//# sourceMappingURL=Col.cjs.map
