"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ProInfoGroupContext = void 0;
exports.getDataIndexValue = getDataIndexValue;
exports.isHidden = isHidden;
exports.useActionType = useActionType;
var _utils = require("@teamix/utils");
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function useActionType(ref, action) {
  // 合并自定义事件
  var userAction = _objectSpread({}, action);
  ref.current = userAction;
}
/** ProInfoGroupContext */
var ProInfoGroupContext = /*#__PURE__*/_react.default.createContext({});
/**
 * 获取 dataIndex 值
 * @param dataIndex
 * @param dataSource
 * @returns
 */
exports.ProInfoGroupContext = ProInfoGroupContext;
function getDataIndexValue(dataIndex, dataSource) {
  if (Array.isArray(dataIndex)) {
    return dataIndex.map(function (item) {
      return (0, _utils.getDeepValue)(item !== null && item !== void 0 ? item : '', dataSource);
    });
  }
  return (0, _utils.getDeepValue)(dataIndex !== null && dataIndex !== void 0 ? dataIndex : '', dataSource);
}
/**
 * 判断是否隐藏
 * @param hidden
 * @param value
 * @param record
 * @param context
 */
function isHidden(hidden, value, record, context) {
  if (typeof hidden === 'string') {
    return (0, _utils.getTargetValue)(hidden, _objectSpread(_objectSpread({}, record), {}, {
      record: record,
      value: value,
      context: context
    }));
  }
  if (typeof hidden === 'boolean') {
    return hidden;
  }
  if (typeof hidden === 'function') {
    return hidden === null || hidden === void 0 ? void 0 : hidden(value, record);
  }
  return false;
}