/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';

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 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 filterDataByIds() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var ids = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var byId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "id";
  return data.filter(function () {
    var d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return ids.includes(d[byId]);
  });
}
var INNER_PRE_NAME = "@@inner-";
var SCROLL_DIRECTION;

(function (SCROLL_DIRECTION2) {
  SCROLL_DIRECTION2["X"] = "x";
  SCROLL_DIRECTION2["Y"] = "y";
  SCROLL_DIRECTION2["UNKNOWN"] = "unknown";
})(SCROLL_DIRECTION || (SCROLL_DIRECTION = {}));

var preScrollLeft;
var preScrollTop;
var getScrollDirection = function getScrollDirection(scrollLeft, scrollTop) {
  var direction = SCROLL_DIRECTION.UNKNOWN;

  if (preScrollTop !== scrollTop) {
    direction = SCROLL_DIRECTION.Y;
  } else if (preScrollLeft !== scrollLeft) {
    direction = SCROLL_DIRECTION.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 getTitle(vm, column, colIndex) {
  var result = null;

  if (isFunction(column.title)) {
    result = column.title(vm.$createElement, {
      col: column,
      colIndex: colIndex
    });
  } else if (isString(column.title)) {
    result = vm.$scopedSlots[column.title] ? vm.$scopedSlots[column.title](null) : column.title;
  } else if (isFunction(column.render)) {
    result = column.render(vm.$createElement, {
      type: "title",
      col: column,
      colIndex: colIndex,
      row: void 0,
      rowIndex: void 0
    });
  }

  return result;
}
function getCell(vm, p) {
  var col = p.col,
      row = p.row;
  var result = null;

  if (isFunction(col.cell)) {
    result = col.cell(vm.$createElement, _objectSpread({}, p));
  } else if (isString(col.cell)) {
    result = vm.$scopedSlots[col.cell] ? vm.$scopedSlots[col.cell](p) : row[col.colKey];
  } else if (isFunction(col.render)) {
    result = col.render(vm.$createElement, _objectSpread({
      type: "cell"
    }, p));
  }

  return result || row[col.colKey];
}
function isRowSelectedDisabled(selectColumn, row, rowIndex) {
  var disabled = isFunction(selectColumn.disabled) ? selectColumn.disabled({
    row: row,
    rowIndex: rowIndex
  }) : selectColumn.disabled;

  if (selectColumn.checkProps) {
    if (isFunction(selectColumn.checkProps)) {
      disabled = disabled || selectColumn.checkProps({
        row: row,
        rowIndex: rowIndex
      }).disabled;
    } else if (selectColumn.checkProps === "object") {
      disabled = disabled || selectColumn.checkProps.disabled;
    }
  }

  return !!disabled;
}

export { INNER_PRE_NAME, SCROLL_DIRECTION, debounce, filterDataByIds, getCell, getRecord, getScrollDirection, getTitle, isRowSelectedDisabled, toString };
//# sourceMappingURL=common.js.map
