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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isUndefined = require('lodash/isUndefined');
var isNumber = require('lodash/isNumber');
var isObject = require('lodash/isObject');
var isArray = require('lodash/isArray');
var utils_responsive = require('../utils/responsive.js');
var hooks_useListener = require('../hooks/useListener.js');
var utils_dom = require('../utils/dom.js');
require('../_chunks/dep-7f0559c3.js');
require('lodash/isString');
require('lodash/isFunction');
require('../utils/easing.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isUndefined__default = /*#__PURE__*/_interopDefaultLegacy(isUndefined);
var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

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; }
function useRowSize() {
  var size = vue.ref(utils_responsive.calcSize(utils_dom.isServer ? 0 : window.innerWidth));
  var updateSize = function updateSize() {
    size.value = utils_responsive.calcSize(utils_dom.isServer ? 0 : window.innerWidth);
  };
  hooks_useListener.useListener("resize", updateSize);
  return size;
}
function getRowClasses(name, props) {
  var _ref;
  var justify = props.justify,
    align = props.align;
  return [name, (_ref = {}, _defineProperty__default["default"](_ref, "".concat(name, "--").concat(justify), justify), _defineProperty__default["default"](_ref, "".concat(name, "--align-").concat(align), align), _ref)];
}
function calcRowStyle(gutter, currentSize) {
  var rowStyle = {};
  var getMarginStyle = function getMarginStyle(gutter2) {
    return Object.assign(rowStyle, {
      marginLeft: "".concat(gutter2 / -2, "px"),
      marginRight: "".concat(gutter2 / -2, "px")
    });
  };
  var getRowGapStyle = function getRowGapStyle(gutter2) {
    return Object.assign(rowStyle, {
      rowGap: "".concat(gutter2, "px")
    });
  };
  var strategyMap = {
    isNumber: function isNumber(gutter2) {
      if (isNumber__default["default"](gutter2)) getMarginStyle(gutter2);
    },
    isArray: function isArray(gutter2) {
      if (isArray__default["default"](gutter2) && gutter2.length) {
        strategyMap.isNumber(gutter2[0]);
        if (isNumber__default["default"](gutter2[1])) getRowGapStyle(gutter2[1]);
        if (isObject__default["default"](gutter2[0]) && !isUndefined__default["default"](gutter2[0][currentSize])) getMarginStyle(gutter2[0][currentSize]);
        if (isObject__default["default"](gutter2[1]) && !isUndefined__default["default"](gutter2[1][currentSize])) getRowGapStyle(gutter2[1][currentSize]);
      }
    },
    isObject: function isObject(gutter2) {
      if (isObject__default["default"](gutter2) && gutter2[currentSize]) {
        if (isArray__default["default"](gutter2) && gutter2.length) {
          getMarginStyle(gutter2[currentSize][0]);
          getRowGapStyle(gutter2[currentSize][1]);
        } else {
          getMarginStyle(gutter2[currentSize]);
        }
      }
    }
  };
  Object.keys(strategyMap).forEach(function (item) {
    strategyMap[item](gutter);
  });
  return rowStyle;
}
function parseFlex(flex) {
  if (isNumber__default["default"](flex)) return "".concat(flex, " ").concat(flex, " 0");
  if (/^\d+(\.\d+)?(px|r?em|%)$/.test(flex)) return "0 0 ".concat(flex);
  return flex;
}
function calcColPadding(gutter, currentSize) {
  var paddingObj = {};
  var getPaddingStyle = function getPaddingStyle(gutter2) {
    return Object.assign(paddingObj, {
      paddingLeft: "".concat(gutter2 / 2, "px"),
      paddingRight: "".concat(gutter2 / 2, "px")
    });
  };
  var strategyMap = {
    isNumber: function isNumber(gutter2) {
      if (isNumber__default["default"](gutter2)) getPaddingStyle(gutter2);
    },
    isArray: function isArray(gutter2) {
      if (isArray__default["default"](gutter2) && gutter2.length) {
        if (isNumber__default["default"](gutter2[0])) getPaddingStyle(gutter2[0]);
        if (isObject__default["default"](gutter2[0]) && gutter2[0][currentSize]) getPaddingStyle(gutter2[0][currentSize]);
      }
    },
    isObject: function isObject(gutter2) {
      if (isObject__default["default"](gutter2) && gutter2[currentSize]) getPaddingStyle(gutter2[currentSize]);
    }
  };
  Object.keys(strategyMap).forEach(function (item) {
    strategyMap[item](gutter);
  });
  return paddingObj;
}
function getColClasses(name, props) {
  var _objectSpread3;
  var span = props.span,
    order = props.order,
    offset = props.offset,
    push = props.push,
    pull = props.pull;
  var allSizes = ["xs", "sm", "md", "lg", "xl", "xxl"];
  var ColSizeClasses = allSizes.reduce(function (acc, currSize) {
    var _objectSpread2;
    var sizeProp = props[currSize];
    var sizeObject = {};
    if (isNumber__default["default"](sizeProp)) sizeObject.span = sizeProp;else if (isObject__default["default"](sizeProp)) sizeObject = sizeProp || {};
    return _objectSpread(_objectSpread({}, acc), {}, (_objectSpread2 = {}, _defineProperty__default["default"](_objectSpread2, "".concat(name, "-").concat(currSize, "-").concat(sizeObject.span), !isUndefined__default["default"](sizeObject.span)), _defineProperty__default["default"](_objectSpread2, "".concat(name, "-").concat(currSize, "-order-").concat(sizeObject.order), parseInt(sizeObject.order, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(name, "-").concat(currSize, "-offset-").concat(sizeObject.offset), parseInt(sizeObject.offset, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(name, "-").concat(currSize, "-push-").concat(sizeObject.push), parseInt(sizeObject.push, 10) >= 0), _defineProperty__default["default"](_objectSpread2, "".concat(name, "-").concat(currSize, "-pull-").concat(sizeObject.pull), parseInt(sizeObject.pull, 10) >= 0), _objectSpread2));
  }, {});
  return _objectSpread((_objectSpread3 = {}, _defineProperty__default["default"](_objectSpread3, "".concat(name), true), _defineProperty__default["default"](_objectSpread3, "".concat(name, "-").concat(span), !isUndefined__default["default"](span)), _defineProperty__default["default"](_objectSpread3, "".concat(name, "-order-").concat(order), order), _defineProperty__default["default"](_objectSpread3, "".concat(name, "-offset-").concat(offset), offset), _defineProperty__default["default"](_objectSpread3, "".concat(name, "-push-").concat(push), push), _defineProperty__default["default"](_objectSpread3, "".concat(name, "-pull-").concat(pull), pull), _objectSpread3), ColSizeClasses);
}

exports.calcColPadding = calcColPadding;
exports.calcRowStyle = calcRowStyle;
exports.getColClasses = getColClasses;
exports.getRowClasses = getRowClasses;
exports.parseFlex = parseFlex;
exports.useRowSize = useRowSize;
//# sourceMappingURL=common.js.map
