/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { defineComponent, computed } from '@vue/composition-api';
import { usePrefixClass } from '../../hooks/use-config.js';
import props from './props.js';
import '../config-provider/useConfig.js';
import '../config-provider/context.js';
import 'lodash';
import '../../_chunks/dep-def4c2ce.js';

var _Space = defineComponent({
  name: "LSpace",
  props: {
    ...props
  },
  setup(props2, _ref) {
    let {
      slots
    } = _ref;
    const COMPONENT_NAME = usePrefixClass("space");
    const renderStyle = computed(() => {
      const sizeMap = {
        small: "8px",
        medium: "16px",
        large: "24px"
      };
      let renderGap = "";
      if (Array.isArray(props2.size)) {
        renderGap = props2.size.map(s => {
          if (typeof s === "number") return `${s}px`;
          if (typeof s === "string") return sizeMap[s] || s;
          return s;
        }).join(" ");
      } else if (typeof props2.size === "string") {
        renderGap = sizeMap[props2.size] || props2.size;
      } else if (typeof props2.size === "number") {
        renderGap = `${props2.size}px`;
      }
      return {
        gap: renderGap,
        ...(props2.breakLine ? {
          "flex-wrap": "wrap"
        } : {})
      };
    });
    const spaceClassNames = computed(() => [`${COMPONENT_NAME.value}`, {
      [`${COMPONENT_NAME.value}-align-${props2.align}`]: props2.align,
      [`${COMPONENT_NAME.value}-${props2.direction}`]: props2.direction
    }]);
    return {
      COMPONENT_NAME,
      spaceClassNames,
      renderStyle,
      slots
    };
  },
  render(h) {
    var _slots$default;
    const {
      COMPONENT_NAME,
      spaceClassNames,
      renderStyle,
      slots,
      separator
    } = this;
    const children = ((_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots).filter(child => child.tag !== void 0)) || [];
    const childCount = children === null || children === void 0 ? void 0 : children.length;
    const renderChildren = () => children.map((child, index) => {
      let renderSeparator = separator;
      if (typeof separator === "function") renderSeparator = separator(h);
      if (slots.separator) renderSeparator = slots.separator();
      const showSeparator = index + 1 !== childCount && renderSeparator;
      return [h("div", {
        "class": `${COMPONENT_NAME}-item`
      }, [child]), showSeparator ? h("div", {
        "class": `${COMPONENT_NAME}-item-separator`
      }, [renderSeparator]) : null];
    });
    return h("div", {
      "class": spaceClassNames,
      "style": renderStyle
    }, [renderChildren()]);
  }
});

export { _Space as default };
//# sourceMappingURL=space.js.map
