/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isObject from 'lodash/isObject';
import { calcSize } from '../utils/responsive.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import props from './col-props.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import '@vue/composition-api';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';

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 classPrefixMixins = getClassPrefixMixins("col");
var _Col = mixins(classPrefixMixins).extend({
  name: "TCol",
  props: _objectSpread({}, props),
  inject: ["rowContext"],
  data: function data() {
    return {
      size: "md"
    };
  },
  computed: {
    classes: function classes() {
      var _this = this,
        _objectSpread3;
      var span = this.span,
        order = this.order,
        offset = this.offset,
        push = this.push,
        pull = this.pull;
      var allSizes = ["xs", "sm", "md", "lg", "xl", "xxl"];
      var sizeClasses = allSizes.reduce(function (acc, currSize) {
        var _objectSpread2;
        var sizeProp = _this[currSize];
        var sizeObject = {};
        if (typeof sizeProp === "number") sizeObject.span = sizeProp;else if (isObject(sizeProp)) sizeObject = sizeProp || {};
        return _objectSpread(_objectSpread({}, acc), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-").concat(sizeObject.span), sizeObject.span !== void 0), _defineProperty(_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-order-").concat(sizeObject.order), parseInt(sizeObject.order, 10) >= 0), _defineProperty(_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-offset-").concat(sizeObject.offset), parseInt(sizeObject.offset, 10) >= 0), _defineProperty(_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-push-").concat(sizeObject.push), parseInt(sizeObject.push, 10) >= 0), _defineProperty(_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-pull-").concat(sizeObject.pull), parseInt(sizeObject.pull, 10) >= 0), _objectSpread2));
      }, {});
      return _objectSpread((_objectSpread3 = {}, _defineProperty(_objectSpread3, "".concat(this.componentName), true), _defineProperty(_objectSpread3, "".concat(this.componentName, "-").concat(span), span !== void 0), _defineProperty(_objectSpread3, "".concat(this.componentName, "-order-").concat(order), order), _defineProperty(_objectSpread3, "".concat(this.componentName, "-offset-").concat(offset), offset), _defineProperty(_objectSpread3, "".concat(this.componentName, "-push-").concat(push), push), _defineProperty(_objectSpread3, "".concat(this.componentName, "-pull-").concat(pull), pull), _objectSpread3), sizeClasses);
    }
  },
  mounted: function mounted() {
    this.updateSize();
    window.addEventListener("resize", this.updateSize);
  },
  beforeDestroy: function beforeDestroy() {
    window.removeEventListener("resize", this.updateSize);
  },
  methods: {
    updateSize: function updateSize() {
      this.size = calcSize(window.innerWidth);
    },
    parseFlex: function parseFlex(flex) {
      if (typeof flex === "number") return "".concat(flex, " ").concat(flex, " 0");
      if (/^\d+(\.\d+)?(px|r?em|%)$/.test(flex)) return "0 0 ".concat(flex);
      return flex;
    },
    calcColPadding: function calcColPadding(gutter, currentSize) {
      var paddingObj = {};
      if (typeof gutter === "number") {
        Object.assign(paddingObj, {
          paddingLeft: "".concat(gutter / 2, "px"),
          paddingRight: "".concat(gutter / 2, "px")
        });
      } else if (Array.isArray(gutter) && gutter.length) {
        if (typeof gutter[0] === "number") {
          Object.assign(paddingObj, {
            paddingLeft: "".concat(gutter[0] / 2, "px"),
            paddingRight: "".concat(gutter[0] / 2, "px")
          });
        }
        if (isObject(gutter[0]) && gutter[0][currentSize]) {
          Object.assign(paddingObj, {
            paddingLeft: "".concat(gutter[0][currentSize] / 2, "px"),
            paddingRight: "".concat(gutter[0][currentSize] / 2, "px")
          });
        }
      } else if (isObject(gutter) && gutter[currentSize]) {
        Object.assign(paddingObj, {
          paddingLeft: "".concat(gutter[currentSize] / 2, "px"),
          paddingRight: "".concat(gutter[currentSize] / 2, "px")
        });
      }
      return paddingObj;
    }
  },
  render: function render() {
    var h = arguments[0];
    var flex = this.flex,
      tag = this.tag,
      classes = this.classes;
    var colStyle = {};
    flex && (colStyle.flex = this.parseFlex(flex));
    var rowContext = this.rowContext;
    if (rowContext) {
      var rowGutter = rowContext.gutter;
      Object.assign(colStyle, this.calcColPadding(rowGutter, this.size));
    }
    return h(tag, {
      "class": classes,
      "style": colStyle
    }, [renderTNodeJSX(this, "default")]);
  }
});

export { _Col as default };
//# sourceMappingURL=col.js.map
