/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

import { defineComponent, computed } from '@vue/composition-api';
import props from './props.js';
import { usePrefixClass } from '../../hooks/use-config.js';
import '../config-provider/useConfig.js';
import '../config-provider/context.js';
import 'lodash';
import '../../chunks/zh_CN.js';
import '../config-provider/type.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) {
    const {
      COMPONENT_NAME,
      spaceClassNames,
      renderStyle,
      slots,
      separator
    } = this;
    const children = slots.default().filter(child => child.tag !== void 0);
    const childCount = 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
