import { NumberUtils, ObjectUtils, StringUtils } from "@sankhyalabs/core";
export default class RmPrecisionCustomValueFormatter {
  setGrid(grid) {
    if (this._grid) {
      return;
    }
    this._grid = grid;
    this.refreshSelectedRows();
  }
  setDataState(dataState) {
    if (this._dataState && ObjectUtils.equals(dataState === null || dataState === void 0 ? void 0 : dataState.metadataByRow, this._dataState.metadataByRow)) {
      return;
    }
    this._dataState = dataState;
    this.refreshSelectedRows();
  }
  format(currentValue, column, recordId) {
    var _a;
    if (StringUtils.isEmpty(currentValue)) {
      return currentValue;
    }
    const rowMetadata = (_a = this._dataState) === null || _a === void 0 ? void 0 : _a.metadataByRow.get(recordId);
    const rmPrecision = rowMetadata === null || rowMetadata === void 0 ? void 0 : rowMetadata.getProp('rm_precision', column.name);
    if (rmPrecision || rmPrecision === 0) {
      return NumberUtils.format(currentValue, rmPrecision, rmPrecision);
    }
    const columnProps = column === null || column === void 0 ? void 0 : column.props;
    if (columnProps) {
      const precision = column === null || column === void 0 ? void 0 : column.props.get('precision');
      const prettyPrecision = column === null || column === void 0 ? void 0 : column.props.get('prettyPrecision');
      if (precision !== undefined && prettyPrecision !== undefined) {
        return NumberUtils.format(currentValue, precision, prettyPrecision);
      }
    }
    return currentValue;
  }
  refreshSelectedRows() {
    var _a;
    (_a = this._grid) === null || _a === void 0 ? void 0 : _a.refreshSelectedRows();
  }
}
