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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var isObject = require('lodash/isObject');
var config = require('../config.js');
var grid_rowProps = require('./row-props.js');
var utils_responsive = require('../utils/responsive.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

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__default["default"](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(config.prefix, "-row");
var _Row = Vue__default["default"].extend({
  name: "TRow",
  props: _objectSpread({}, grid_rowProps["default"]),
  data: function data() {
    return {
      size: utils_responsive.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__default["default"](_ref, "".concat(name, "--").concat(justify), justify), _defineProperty__default["default"](_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 = utils_responsive.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__default["default"](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__default["default"](gutter[1]) && gutter[1][currentSize] !== void 0) {
          Object.assign(rowStyle, {
            rowGap: "".concat(gutter[1][currentSize], "px")
          });
        }
      } else if (isObject__default["default"](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"]]);
  }
});

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