/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import isObject from 'lodash/isObject';
import { prefix } from '../config.js';
import props from './row-props.js';
import { calcSize } from '../utils/responsive.js';
import { getIEVersion } from '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var name = "".concat(prefix, "-row");
var _Row = Vue.extend({
  name: "TRow",
  props: _objectSpread({}, props),
  data: function data() {
    return {
      size: "md"
    };
  },
  provide: function provide() {
    return {
      rowContext: {
        gutter: this.gutter
      }
    };
  },
  computed: {
    classes: function classes() {
      var _ref;

      var justify = this.justify,
          align = this.align;
      return [name, (_ref = {}, _defineProperty(_ref, "".concat(name, "--").concat(justify), justify), _defineProperty(_ref, "".concat(name, "--").concat(align), align), _ref)];
    }
  },
  mounted: function mounted() {
    this.updateSize();
    this.handleIE();
    window.addEventListener("resize", this.updateSize);
  },
  watch: {
    gutter: function gutter() {
      this.handleIE();
    },
    size: function size() {
      this.handleIE();
    }
  },
  beforeDestroy: function beforeDestroy() {
    window.removeEventListener("resize", this.updateSize);
  },
  methods: {
    updateSize: function updateSize() {
      this.size = calcSize(window.innerWidth);
    },
    handleIE: function handleIE() {
      if (getIEVersion() <= 11) {
        var rowGap = this.rowGap(this.gutter, this.size);

        if (rowGap) {
          this.$el.setAttribute("row-gap", "".concat(rowGap));
        }
      }
    },
    calcRowStyle: function calcRowStyle(gutter, currentSize) {
      var rowStyle = {};

      if (typeof gutter === "number") {
        Object.assign(rowStyle, {
          marginLeft: "".concat(gutter / -2, "px"),
          marginRight: "".concat(gutter / -2, "px")
        });
      } else if (Array.isArray(gutter) && gutter.length) {
        if (typeof gutter[0] === "number") {
          Object.assign(rowStyle, {
            marginLeft: "".concat(gutter[0] / -2, "px"),
            marginRight: "".concat(gutter[0] / -2, "px")
          });
        }

        if (typeof gutter[1] === "number") {
          Object.assign(rowStyle, {
            rowGap: "".concat(gutter[1], "px")
          });
        }

        if (isObject(gutter[0]) && gutter[0][currentSize] !== void 0) {
          Object.assign(rowStyle, {
            marginLeft: "".concat(gutter[0][currentSize] / -2, "px"),
            marginRight: "".concat(gutter[0][currentSize] / -2, "px")
          });
        }

        if (isObject(gutter[1]) && gutter[1][currentSize] !== void 0) {
          Object.assign(rowStyle, {
            rowGap: "".concat(gutter[1][currentSize], "px")
          });
        }
      } else if (isObject(gutter) && gutter[currentSize]) {
        if (Array.isArray(gutter[currentSize]) && gutter[currentSize].length) {
          Object.assign(rowStyle, {
            marginLeft: "".concat(gutter[currentSize][0] / -2, "px"),
            marginRight: "".concat(gutter[currentSize][0] / -2, "px")
          });
          Object.assign(rowStyle, {
            rowGap: "".concat(gutter[currentSize][1], "px")
          });
        } else {
          Object.assign(rowStyle, {
            marginLeft: "".concat(gutter[currentSize] / -2, "px"),
            marginRight: "".concat(gutter[currentSize] / -2, "px")
          });
        }
      }

      return rowStyle;
    },
    rowGap: function rowGap(gutter, currentSize) {
      var rowGap;

      if (Array.isArray(gutter) && gutter.length) {
        if (typeof gutter[1] === "number") {
          var _gutter = _slicedToArray(gutter, 2);

          rowGap = _gutter[1];
        }

        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) {
          var _gutter$currentSize = _slicedToArray(gutter[currentSize], 2);

          rowGap = _gutter$currentSize[1];
        }
      }

      return rowGap;
    }
  },
  render: function render() {
    var h = arguments[0];
    var tag = this.tag,
        classes = this.classes;
    var rowStyle = this.calcRowStyle(this.gutter, this.size);
    var attributes = {
      "class": classes,
      style: rowStyle,
      attrs: {}
    };
    return h(tag, helper([{}, attributes]), [this.$slots["default"]]);
  }
});

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