"use strict";

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

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

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

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

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

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

var stringOrNumber = _vueTypes.default.oneOfType([_vueTypes.default.string, _vueTypes.default.number]);

var ColSize = _vueTypes.default.shape({
  span: stringOrNumber,
  order: stringOrNumber,
  offset: stringOrNumber,
  push: stringOrNumber,
  pull: stringOrNumber
}).loose;

exports.ColSize = ColSize;

var objectOrNumber = _vueTypes.default.oneOfType([_vueTypes.default.string, _vueTypes.default.number, ColSize]);

var ColProps = {
  span: stringOrNumber,
  order: stringOrNumber,
  offset: stringOrNumber,
  push: stringOrNumber,
  pull: stringOrNumber,
  xs: objectOrNumber,
  sm: objectOrNumber,
  md: objectOrNumber,
  lg: objectOrNumber,
  xl: objectOrNumber,
  xxl: objectOrNumber,
  prefixCls: _vueTypes.default.string,
  flex: stringOrNumber
};
exports.ColProps = ColProps;
var _default = {
  name: 'ACol',
  props: ColProps,
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps),
      rowContext: (0, _vue.inject)('rowContext', null)
    };
  },
  methods: {
    parseFlex: function parseFlex(flex) {
      if (typeof flex === 'number') {
        return "".concat(flex, " ").concat(flex, " auto");
      }

      if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
        return "0 0 ".concat(flex);
      }

      return flex;
    }
  },
  render: function render() {
    var _this = this,
        _objectSpread3;

    var span = this.span,
        order = this.order,
        offset = this.offset,
        push = this.push,
        pull = this.pull,
        flex = this.flex,
        customizePrefixCls = this.prefixCls,
        rowContext = this.rowContext;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('col', customizePrefixCls);
    var sizeClassObj = {};
    ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(function (size) {
      var _objectSpread2;

      var sizeProps = {};
      var propSize = _this[size];

      if (typeof propSize === 'number') {
        sizeProps.span = propSize;
      } else if (_typeof(propSize) === 'object') {
        sizeProps = propSize || {};
      }

      sizeClassObj = _objectSpread(_objectSpread({}, sizeClassObj), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(prefixCls, "-").concat(size, "-").concat(sizeProps.span), sizeProps.span !== undefined), _defineProperty(_objectSpread2, "".concat(prefixCls, "-").concat(size, "-order-").concat(sizeProps.order), sizeProps.order || sizeProps.order === 0), _defineProperty(_objectSpread2, "".concat(prefixCls, "-").concat(size, "-offset-").concat(sizeProps.offset), sizeProps.offset || sizeProps.offset === 0), _defineProperty(_objectSpread2, "".concat(prefixCls, "-").concat(size, "-push-").concat(sizeProps.push), sizeProps.push || sizeProps.push === 0), _defineProperty(_objectSpread2, "".concat(prefixCls, "-").concat(size, "-pull-").concat(sizeProps.pull), sizeProps.pull || sizeProps.pull === 0), _objectSpread2));
    });

    var classes = _objectSpread((_objectSpread3 = {}, _defineProperty(_objectSpread3, "".concat(prefixCls), true), _defineProperty(_objectSpread3, "".concat(prefixCls, "-").concat(span), span !== undefined), _defineProperty(_objectSpread3, "".concat(prefixCls, "-order-").concat(order), order), _defineProperty(_objectSpread3, "".concat(prefixCls, "-offset-").concat(offset), offset), _defineProperty(_objectSpread3, "".concat(prefixCls, "-push-").concat(push), push), _defineProperty(_objectSpread3, "".concat(prefixCls, "-pull-").concat(pull), pull), _objectSpread3), sizeClassObj);

    var divProps = {
      class: classes,
      style: {}
    };

    if (rowContext) {
      var gutter = rowContext.getGutter();

      if (gutter) {
        divProps.style = _objectSpread(_objectSpread({}, gutter[0] > 0 ? {
          paddingLeft: "".concat(gutter[0] / 2, "px"),
          paddingRight: "".concat(gutter[0] / 2, "px")
        } : {}), gutter[1] > 0 ? {
          paddingTop: "".concat(gutter[1] / 2, "px"),
          paddingBottom: "".concat(gutter[1] / 2, "px")
        } : {});
      }
    }

    if (flex) {
      divProps.style.flex = this.parseFlex(flex);
    }

    return _vue.createVNode("div", divProps, [(0, _propsUtil.getSlot)(this)]);
  }
};
exports.default = _default;