/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

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';

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: calcSize(window.innerWidth)
    };
  },
  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() {
    window.addEventListener("resize", this.updateSize);
  },
  beforeDestroy: function beforeDestroy() {
    window.removeEventListener("resize", this.updateSize);
  },
  methods: {
    updateSize: function updateSize() {
      this.size = calcSize(window.innerWidth);
    },
    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;
    }
  },
  render: function render() {
    var h = arguments[0];
    var tag = this.tag,
        classes = this.classes;
    var rowStyle = this.calcRowStyle(this.gutter, this.size);
    return h(tag, {
      "class": classes,
      "style": rowStyle
    }, [this.$slots["default"]]);
  }
});

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