"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ColumnDefaultProps = void 0;
exports.columnWidth = columnWidth;
exports["default"] = void 0;
exports.defaultAggregationRenderer = defaultAggregationRenderer;
exports.minColumnWidth = minColumnWidth;

var _mobx = require("mobx");

var _enum = require("../field/enum");

function defaultAggregationRenderer(_ref) {
  var text = _ref.text;
  return text;
}

var ColumnDefaultProps = {
  hidden: false,
  lock: false,
  resizable: true,
  sortable: false,
  hideable: true,
  aggregationLimit: 4,
  showHelp: _enum.ShowHelp.tooltip
};
exports.ColumnDefaultProps = ColumnDefaultProps;

var Column = function Column() {
  return null;
};

Column.__PRO_TABLE_COLUMN = true;
Column.defaultProps = ColumnDefaultProps;
var _default = Column;
exports["default"] = _default;

function minColumnWidth(col, store) {
  var hidden = (0, _mobx.get)(col, 'hidden');

  if (hidden) {
    return 0;
  }

  var width = (0, _mobx.get)(col, 'width');
  var min = (0, _mobx.get)(col, 'minWidth');
  var aggregation = (0, _mobx.get)(col, 'aggregation');
  var minWidth = min === undefined ? store.getConfig(aggregation ? 'tableAggregationColumnDefaultMinWidth' : 'tableColumnDefaultMinWidth') : min;

  if (width === undefined) {
    return minWidth;
  }

  return Math.min(width, minWidth);
}

function getDefaultWidth(col, store, aggregation) {
  var defaultWidth = (0, _mobx.get)(col, 'defaultWidth');

  if (defaultWidth === undefined) {
    return store.getConfig(aggregation ? 'tableAggregationColumnDefaultWidth' : 'tableColumnDefaultWidth');
  }

  return defaultWidth;
}

function getMinWidth(col, store, aggregation) {
  var minWidth = (0, _mobx.get)(col, 'minWidth');

  if (minWidth === undefined) {
    return store.getConfig(aggregation ? 'tableAggregationColumnDefaultMinWidth' : 'tableColumnDefaultMinWidth');
  }

  return minWidth;
}

function columnWidth(col, store) {
  var hidden = (0, _mobx.get)(col, 'hidden');

  if (hidden) {
    return 0;
  }

  var width = (0, _mobx.get)(col, 'width');

  if (width === undefined) {
    var aggregation = (0, _mobx.get)(col, 'aggregation');
    var defaultWidth = getDefaultWidth(col, store, aggregation);
    var minWidth = getMinWidth(col, store, aggregation);
    return Math.max(minWidth, defaultWidth);
  }

  return width;
}
//# sourceMappingURL=Column.js.map
