"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));

var _configProvider = require("../config-provider");

var _responsiveObserve = _interopRequireDefault(require("../_util/responsiveObserve"));

var _propsUtil = require("../_util/props-util");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var RowProps = {
  gutter: _vueTypes.default.oneOfType([_vueTypes.default.object, _vueTypes.default.number, _vueTypes.default.array]),
  type: _vueTypes.default.oneOf(['flex']),
  align: _vueTypes.default.oneOf(['top', 'middle', 'bottom', 'stretch']),
  justify: _vueTypes.default.oneOf(['start', 'end', 'center', 'space-around', 'space-between']),
  prefixCls: _vueTypes.default.string
};
var responsiveArray = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
var _default = {
  name: 'ARow',
  mixins: [_BaseMixin.default],
  props: _objectSpread(_objectSpread({}, RowProps), {}, {
    gutter: _vueTypes.default.oneOfType([_vueTypes.default.object, _vueTypes.default.number, _vueTypes.default.array]).def(0)
  }),
  setup: function setup() {
    var rowContext = (0, _vue.reactive)({
      getGutter: undefined
    });
    (0, _vue.provide)('rowContext', rowContext);
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps),
      rowContext: rowContext
    };
  },
  data: function data() {
    return {
      screens: {}
    };
  },
  created: function created() {
    this.rowContext.getGutter = this.getGutter;
  },
  mounted: function mounted() {
    var _this = this;

    this.$nextTick(function () {
      _this.token = _responsiveObserve.default.subscribe(function (screens) {
        var gutter = _this.gutter;

        if (_typeof(gutter) === 'object' || Array.isArray(gutter) && (_typeof(gutter[0]) === 'object' || _typeof(gutter[1]) === 'object')) {
          _this.screens = screens;
        }
      });
    });
  },
  beforeUnmount: function beforeUnmount() {
    _responsiveObserve.default.unsubscribe(this.token);
  },
  methods: {
    getGutter: function getGutter() {
      var results = [0, 0];
      var gutter = this.gutter,
          screens = this.screens;
      var normalizedGutter = Array.isArray(gutter) ? gutter : [gutter, 0];
      normalizedGutter.forEach(function (g, index) {
        if (_typeof(g) === 'object') {
          for (var i = 0; i < responsiveArray.length; i++) {
            var breakpoint = responsiveArray[i];

            if (screens[breakpoint] && g[breakpoint] !== undefined) {
              results[index] = g[breakpoint];
              break;
            }
          }
        } else {
          results[index] = g || 0;
        }
      });
      return results;
    }
  },
  render: function render() {
    var _classes;

    var type = this.type,
        justify = this.justify,
        align = this.align,
        customizePrefixCls = this.prefixCls;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('row', customizePrefixCls);
    var gutter = this.getGutter();
    var classes = (_classes = {}, _defineProperty(_classes, prefixCls, !type), _defineProperty(_classes, "".concat(prefixCls, "-").concat(type), type), _defineProperty(_classes, "".concat(prefixCls, "-").concat(type, "-").concat(justify), type && justify), _defineProperty(_classes, "".concat(prefixCls, "-").concat(type, "-").concat(align), type && align), _classes);

    var rowStyle = _objectSpread(_objectSpread({}, gutter[0] > 0 ? {
      marginLeft: "".concat(gutter[0] / -2, "px"),
      marginRight: "".concat(gutter[0] / -2, "px")
    } : {}), gutter[1] > 0 ? {
      marginTop: "".concat(gutter[1] / -2, "px"),
      marginBottom: "".concat(gutter[1] / -2, "px")
    } : {});

    return _vue.createVNode("div", {
      "class": classes,
      "style": rowStyle
    }, [(0, _propsUtil.getSlot)(this)]);
  }
};
exports.default = _default;