import * as _vue from "vue";

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

import { inject, provide, reactive } from 'vue';
import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider';
import ResponsiveObserve from '../_util/responsiveObserve';
import { getSlot } from '../_util/props-util';
var RowProps = {
  gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
  type: PropTypes.oneOf(['flex']),
  align: PropTypes.oneOf(['top', 'middle', 'bottom', 'stretch']),
  justify: PropTypes.oneOf(['start', 'end', 'center', 'space-around', 'space-between']),
  prefixCls: PropTypes.string
};
var responsiveArray = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
export default {
  name: 'ARow',
  mixins: [BaseMixin],
  props: _objectSpread(_objectSpread({}, RowProps), {}, {
    gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]).def(0)
  }),
  setup: function setup() {
    var rowContext = reactive({
      getGutter: undefined
    });
    provide('rowContext', rowContext);
    return {
      configProvider: inject('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.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.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
    }, [getSlot(this)]);
  }
};