/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var hooks_useConfig = require('../../hooks/useConfig.js');
var components_space_props = require('./props.js');
require('../config-provider/useConfig.js');
require('../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../chunks/zh_CN.js');

var _Space = VueCompositionAPI.defineComponent({
  name: "LSpace",
  props: {
    ...components_space_props["default"]
  },
  setup(props2, _ref) {
    let {
      slots
    } = _ref;
    const COMPONENT_NAME = hooks_useConfig.usePrefixClass("space");
    const renderStyle = VueCompositionAPI.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 = VueCompositionAPI.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()]);
  }
});

exports["default"] = _Space;
//# sourceMappingURL=space.js.map
