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

import { h as helper } from '../../chunks/helper.js';
import isObject from 'lodash/isObject';
import { g as getIEVersion } from '../../chunks/helper2.js';
import { calcSize } from '../../utils/responsive.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { RowProps } from './props.js';
import '../../chunks/_commonjsHelpers.js';
import '../../chunks/defineProperty-838e4192.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("row");
var _Row = mixins(classPrefixMixins).extend({
  name: "LRow",
  props: {
    ...RowProps
  },
  data() {
    return {
      size: "md"
    };
  },
  provide() {
    return {
      rowContext: {
        gutter: this.gutter
      }
    };
  },
  computed: {
    classes() {
      const {
        justify,
        align
      } = this;
      return [this.componentName, {
        [`${this.componentName}--${justify}`]: justify,
        [`${this.componentName}--align-${align}`]: align
      }];
    }
  },
  mounted() {
    this.updateSize();
    this.handleIE();
    window.addEventListener("resize", this.updateSize);
  },
  watch: {
    gutter() {
      this.handleIE();
    },
    size() {
      this.handleIE();
    }
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.updateSize);
  },
  methods: {
    updateSize() {
      this.size = calcSize(window.innerWidth);
    },
    handleIE() {
      if (getIEVersion() <= 11) {
        const rowGap = this.rowGap(this.gutter, this.size);
        if (rowGap) this.$el.setAttribute("row-gap", `${rowGap}`);
      }
    },
    calcRowStyle(gutter, currentSize) {
      const rowStyle = {};
      if (typeof gutter === "number") {
        Object.assign(rowStyle, {
          marginLeft: `${gutter / -2}px`,
          marginRight: `${gutter / -2}px`
        });
      } else if (Array.isArray(gutter) && gutter.length) {
        if (typeof gutter[0] === "number") {
          Object.assign(rowStyle, {
            marginLeft: `${gutter[0] / -2}px`,
            marginRight: `${gutter[0] / -2}px`
          });
        }
        if (typeof gutter[1] === "number") Object.assign(rowStyle, {
          rowGap: `${gutter[1]}px`
        });
        if (isObject(gutter[0]) && gutter[0][currentSize] !== void 0) {
          Object.assign(rowStyle, {
            marginLeft: `${gutter[0][currentSize] / -2}px`,
            marginRight: `${gutter[0][currentSize] / -2}px`
          });
        }
        if (isObject(gutter[1]) && gutter[1][currentSize] !== void 0) Object.assign(rowStyle, {
          rowGap: `${gutter[1][currentSize]}px`
        });
      } else if (isObject(gutter) && gutter[currentSize]) {
        if (Array.isArray(gutter[currentSize]) && gutter[currentSize].length) {
          Object.assign(rowStyle, {
            marginLeft: `${gutter[currentSize][0] / -2}px`,
            marginRight: `${gutter[currentSize][0] / -2}px`
          });
          Object.assign(rowStyle, {
            rowGap: `${gutter[currentSize][1]}px`
          });
        } else {
          Object.assign(rowStyle, {
            marginLeft: `${gutter[currentSize] / -2}px`,
            marginRight: `${gutter[currentSize] / -2}px`
          });
        }
      }
      return rowStyle;
    },
    rowGap(gutter, currentSize) {
      let rowGap;
      if (Array.isArray(gutter) && gutter.length) {
        if (typeof gutter[1] === "number") [, rowGap] = gutter;
        if (isObject(gutter[1]) && gutter[1][currentSize] !== void 0) rowGap = gutter[1][currentSize];
      } else if (isObject(gutter) && gutter[currentSize]) {
        if (Array.isArray(gutter[currentSize]) && gutter[currentSize].length) [, rowGap] = gutter[currentSize];
      }
      return rowGap;
    }
  },
  render() {
    const h = arguments[0];
    const {
      tag,
      classes
    } = this;
    const rowStyle = this.calcRowStyle(this.gutter, this.size);
    const attributes = {
      class: classes,
      style: rowStyle,
      attrs: {}
    };
    return h(tag, helper([{}, attributes]), [this.$slots.default]);
  }
});

export { _Row as default };
//# sourceMappingURL=row.js.map
