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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { ref } from 'vue';
import isUndefined from 'lodash/isUndefined';
import isNumber from 'lodash/isNumber';
import isObject from 'lodash/isObject';
import isArray from 'lodash/isArray';
import { calcSize } from '../utils/responsive.js';
import { useListener } from '../hooks/useListener.js';
import { isServer } from '../utils/dom.js';
import '../_chunks/dep-512eb181.js';
import 'lodash/isString';
import 'lodash/isFunction';
import '../utils/easing.js';

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; }
function useRowSize() {
  var size = ref(calcSize(isServer ? 0 : window.innerWidth));
  var updateSize = function updateSize() {
    size.value = calcSize(isServer ? 0 : window.innerWidth);
  };
  useListener("resize", updateSize);
  return size;
}
function getRowClasses(name, props) {
  var _ref;
  var justify = props.justify,
    align = props.align;
  return [name, (_ref = {}, _defineProperty(_ref, "".concat(name, "--").concat(justify), justify), _defineProperty(_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$1(gutter2) {
      if (isNumber(gutter2)) getMarginStyle(gutter2);
    },
    isArray: function isArray$1(gutter2) {
      if (isArray(gutter2) && gutter2.length) {
        strategyMap.isNumber(gutter2[0]);
        if (isNumber(gutter2[1])) getRowGapStyle(gutter2[1]);
        if (isObject(gutter2[0]) && !isUndefined(gutter2[0][currentSize])) getMarginStyle(gutter2[0][currentSize]);
        if (isObject(gutter2[1]) && !isUndefined(gutter2[1][currentSize])) getRowGapStyle(gutter2[1][currentSize]);
      }
    },
    isObject: function isObject$1(gutter2) {
      if (isObject(gutter2) && gutter2[currentSize]) {
        if (isArray(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(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$1(gutter2) {
      if (isNumber(gutter2)) getPaddingStyle(gutter2);
    },
    isArray: function isArray$1(gutter2) {
      if (isArray(gutter2) && gutter2.length) {
        if (isNumber(gutter2[0])) getPaddingStyle(gutter2[0]);
        if (isObject(gutter2[0]) && gutter2[0][currentSize]) getPaddingStyle(gutter2[0][currentSize]);
      }
    },
    isObject: function isObject$1(gutter2) {
      if (isObject(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(sizeProp)) sizeObject.span = sizeProp;else if (isObject(sizeProp)) sizeObject = sizeProp || {};
    return _objectSpread(_objectSpread({}, acc), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(name, "-").concat(currSize, "-").concat(sizeObject.span), !isUndefined(sizeObject.span)), _defineProperty(_objectSpread2, "".concat(name, "-").concat(currSize, "-order-").concat(sizeObject.order), parseInt(sizeObject.order, 10) >= 0), _defineProperty(_objectSpread2, "".concat(name, "-").concat(currSize, "-offset-").concat(sizeObject.offset), parseInt(sizeObject.offset, 10) >= 0), _defineProperty(_objectSpread2, "".concat(name, "-").concat(currSize, "-push-").concat(sizeObject.push), parseInt(sizeObject.push, 10) >= 0), _defineProperty(_objectSpread2, "".concat(name, "-").concat(currSize, "-pull-").concat(sizeObject.pull), parseInt(sizeObject.pull, 10) >= 0), _objectSpread2));
  }, {});
  return _objectSpread((_objectSpread3 = {}, _defineProperty(_objectSpread3, "".concat(name), true), _defineProperty(_objectSpread3, "".concat(name, "-").concat(span), !isUndefined(span)), _defineProperty(_objectSpread3, "".concat(name, "-order-").concat(order), order), _defineProperty(_objectSpread3, "".concat(name, "-offset-").concat(offset), offset), _defineProperty(_objectSpread3, "".concat(name, "-push-").concat(push), push), _defineProperty(_objectSpread3, "".concat(name, "-pull-").concat(pull), pull), _objectSpread3), ColSizeClasses);
}

export { calcColPadding, calcRowStyle, getColClasses, getRowClasses, parseFlex, useRowSize };
//# sourceMappingURL=common.js.map
