import { globalObject, isBrowser } from '@skbkontur/global-object';
export function getTextAreaHeight(params) {
  if (!isBrowser(globalObject)) {
    return null;
  }
  var node = params.node,
    minRows = params.minRows,
    maxRows = params.maxRows,
    extraRow = params.extraRow;
  var style = globalObject.getComputedStyle(node);
  var borderTop = style.borderTopWidth ? parseInt(style.borderTopWidth, 10) : 0;
  var borderBottom = style.borderBottomWidth ? parseInt(style.borderBottomWidth, 10) : 0;
  var lineHeight = style.lineHeight ? parseInt(style.lineHeight, 10) : 0;
  var paddingTop = style.paddingTop ? parseInt(style.paddingTop, 10) : 0;
  var paddingBottom = style.paddingBottom ? parseInt(style.paddingBottom, 10) : 0;
  var minHeight = borderTop + borderBottom + paddingTop + paddingBottom + lineHeight * minRows;
  var maxHeight = borderTop + borderBottom + paddingTop + paddingBottom + lineHeight * maxRows;
  var extraRowHeight = extraRow ? lineHeight : 0;
  var expectedHeight = node.scrollHeight + borderTop + borderBottom + extraRowHeight;
  return {
    height: Math.min(Math.max(expectedHeight, minHeight), maxHeight),
    exceededMaxHeight: expectedHeight > maxHeight + extraRowHeight
  };
}