/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isObject = require('lodash/isObject');
var utils_responsive = require('../../utils/responsive.js');
var components_grid_props = require('./props.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
require('@babel/runtime/helpers/typeof');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
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 classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("col");
var _Col = utils_mixins["default"](classPrefixMixins).extend({
  name: "LCol",
  props: _objectSpread({}, components_grid_props.ColProps),
  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__default["default"](sizeProp)) {
          sizeObject = sizeProp || {};
        }

        return _objectSpread(_objectSpread({}, acc), {}, (_objectSpread2 = {}, _defineProperty__default["default"](_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-").concat(sizeObject.span), sizeObject.span !== void 0), _defineProperty__default["default"](_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-order-").concat(sizeObject.order), parseInt(sizeObject.order, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-offset-").concat(sizeObject.offset), parseInt(sizeObject.offset, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-push-").concat(sizeObject.push), parseInt(sizeObject.push, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(_this.componentName, "-").concat(currSize, "-pull-").concat(sizeObject.pull), parseInt(sizeObject.pull, 10) >= 0), _objectSpread2));
      }, {});
      return _objectSpread((_objectSpread3 = {}, _defineProperty__default["default"](_objectSpread3, "".concat(this.componentName), true), _defineProperty__default["default"](_objectSpread3, "".concat(this.componentName, "-").concat(span), span !== void 0), _defineProperty__default["default"](_objectSpread3, "".concat(this.componentName, "-order-").concat(order), order), _defineProperty__default["default"](_objectSpread3, "".concat(this.componentName, "-offset-").concat(offset), offset), _defineProperty__default["default"](_objectSpread3, "".concat(this.componentName, "-push-").concat(push), push), _defineProperty__default["default"](_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 = utils_responsive.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__default["default"](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__default["default"](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
    }, [utils_renderNode.renderLNodeJSX(this, "default")]);
  }
});

exports["default"] = _Col;
//# sourceMappingURL=col.js.map
