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

'use strict';

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

var helper$1 = require('../../chunks/helper.js');
var isObject = require('lodash/isObject');
var helper = require('../../chunks/helper2.js');
var utils_responsive = require('../../utils/responsive.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_grid_props = require('./props.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("row");
var _Row = utils_mixins["default"](classPrefixMixins).extend({
  name: "LRow",
  props: {
    ...components_grid_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 = utils_responsive.calcSize(window.innerWidth);
    },
    handleIE() {
      if (helper.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__default["default"](gutter[0]) && gutter[0][currentSize] !== void 0) {
          Object.assign(rowStyle, {
            marginLeft: `${gutter[0][currentSize] / -2}px`,
            marginRight: `${gutter[0][currentSize] / -2}px`
          });
        }
        if (isObject__default["default"](gutter[1]) && gutter[1][currentSize] !== void 0) Object.assign(rowStyle, {
          rowGap: `${gutter[1][currentSize]}px`
        });
      } else if (isObject__default["default"](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__default["default"](gutter[1]) && gutter[1][currentSize] !== void 0) rowGap = gutter[1][currentSize];
      } else if (isObject__default["default"](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$1.helper([{}, attributes]), [this.$slots.default]);
  }
});

exports["default"] = _Row;
//# sourceMappingURL=row.js.map
