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

import { _ as _typeof } from '../_chunks/dep-b4041200.mjs';
import { i as isFunction_1 } from '../_chunks/dep-6b22dd27.mjs';
import { g as get_1 } from '../_chunks/dep-4c3e8dd5.mjs';
import { i as isObject_1 } from '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-7acc11cb.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-37ba476d.mjs';

function toString(obj) {
  return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
}
function debounce(fn) {
  var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
  var timer;
  return function newFn() {
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    var context = this;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
}
function formatRowAttributes(attributes, params) {
  if (!attributes) return void 0;
  var attrList = Array.isArray(attributes) ? attributes : [attributes];
  var result = {};
  for (var i = 0; i < attrList.length; i++) {
    var attrItem = attrList[i];
    if (!attrItem) continue;
    var attrProperty = isFunction_1(attrItem) ? attrItem(params) : attrItem;
    result = Array.isArray(attrProperty) ? formatRowAttributes(attrProperty, params) : Object.assign(result, attrProperty);
  }
  return result;
}
function formatRowClassNames(rowClassNames, params, rowKey) {
  var rowClassList = Array.isArray(rowClassNames) ? rowClassNames : [rowClassNames];
  var row = params.row,
    rowIndex = params.rowIndex;
  var customClasses = [];
  for (var i = 0, len = rowClassList.length; i < len; i++) {
    var rName = rowClassList[i];
    var tClass = isFunction_1(rName) ? rName(params) : rName;
    if (isObject_1(tClass) && !Array.isArray(tClass)) {
      tClass[rowIndex] && (tClass = tClass[rowIndex]);
      var rowId = get_1(row, rowKey || "id");
      tClass[rowId] && (tClass = tClass[rowId]);
    } else if (Array.isArray(tClass)) {
      tClass = formatRowClassNames(tClass, params, rowKey);
    }
    customClasses = customClasses.concat(tClass);
  }
  return customClasses;
}
function formatClassNames(classNames, params) {
  var classes = Array.isArray(classNames) ? classNames : [classNames];
  var arr = [];
  for (var i = 0, len = classes.length; i < len; i++) {
    var cls = classes[i];
    if (isFunction_1(cls)) arr.push(cls(params));else arr.push(cls);
  }
  return arr;
}
var INNER_PRE_NAME = "@@inner-";
var SCROLL_DIRECTION = /* @__PURE__ */function (SCROLL_DIRECTION2) {
  SCROLL_DIRECTION2["X"] = "x";
  SCROLL_DIRECTION2["Y"] = "y";
  SCROLL_DIRECTION2["UNKNOWN"] = "unknown";
  return SCROLL_DIRECTION2;
}(SCROLL_DIRECTION || {});
var preScrollLeft;
var preScrollTop;
var getScrollDirection = function getScrollDirection(scrollLeft, scrollTop) {
  var direction = "unknown" /* UNKNOWN */;
  if (preScrollTop !== scrollTop) direction = "y" /* Y */;else if (preScrollLeft !== scrollLeft) direction = "x" /* X */;
  preScrollTop = scrollTop;
  preScrollLeft = scrollLeft;
  return direction;
};
var getRecord = function getRecord(record) {
  if (!record) return record;
  var result = {};
  Object.keys(record).forEach(function (key) {
    var descriptor = Object.getOwnPropertyDescriptor(record, key);
    descriptor && Reflect.defineProperty(result, key, {
      set: function set(val) {
        descriptor.set(val);
      },
      get: function get() {
        console.warn("The parameter `record` will be deprecated, please use `row` instead");
        return descriptor.get();
      }
    });
  });
  return result;
};
function getCurrentRowByKey(columns, key) {
  if (!columns || !key) return;
  var col = columns === null || columns === void 0 ? void 0 : columns.find(function (t) {
    return t.colKey === key;
  });
  if (col) return col;
  for (var i = 0, len = columns.length; i < len; i++) {
    var _columns$i, _columns$i$children, _columns$i2;
    if ((_columns$i = columns[i]) !== null && _columns$i !== void 0 && (_columns$i$children = _columns$i.children) !== null && _columns$i$children !== void 0 && _columns$i$children.length) return getCurrentRowByKey((_columns$i2 = columns[i]) === null || _columns$i2 === void 0 ? void 0 : _columns$i2.children, key);
  }
}
function getAffixProps(mainAffixProps, subAffixProps) {
  if (_typeof(mainAffixProps) === "object") return mainAffixProps;
  if (_typeof(subAffixProps) === "object") return subAffixProps;
  return {};
}
function getEditableKeysMap(keys, list, rowKey) {
  var map = {};
  for (var i = 0, len = list.length; i < len; i++) {
    var rowValue = get_1(list[i], rowKey);
    if (keys.includes(rowValue)) map[rowValue] = true;
  }
  return map;
}
function getColumnDataByKey(columns, colKey) {
  for (var i = 0, len = columns.length; i < len; i++) {
    var _columns$i$children2;
    if (columns[i].colKey === colKey) return columns[i];
    if ((_columns$i$children2 = columns[i].children) !== null && _columns$i$children2 !== void 0 && _columns$i$children2.length) {
      var t = getColumnDataByKey(columns[i].children, colKey);
      if (t) return t;
    }
  }
  return null;
}
function getColumnIndexByKey(columns, colKey) {
  for (var i = 0, len = columns.length; i < len; i++) {
    var _columns$i$children3;
    if (columns[i].colKey === colKey) return i;
    if ((_columns$i$children3 = columns[i].children) !== null && _columns$i$children3 !== void 0 && _columns$i$children3.length) {
      var t = getColumnDataByKey(columns[i].children, colKey);
      if (t) return i;
    }
  }
  return -1;
}

export { INNER_PRE_NAME, SCROLL_DIRECTION, debounce, formatClassNames, formatRowAttributes, formatRowClassNames, getAffixProps, getColumnDataByKey, getColumnIndexByKey, getCurrentRowByKey, getEditableKeysMap, getRecord, getScrollDirection, toString };
//# sourceMappingURL=utils.mjs.map
