import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import { cx } from "../../../lib/theming/Emotion";
import { getDOMRect } from "../../../lib/dom/getDOMRect";
import { TokenView } from "../../Token/TokenView";
import { styles } from "../../Token/Token.styles";

// a thin character to preserve some space
// for the caret visibillity in the input
var THIN_SPACE = "\u2009";

/**
 * Херпер позволяет вычислить размеры блока с текстом
 * для последующего выставления размеров input
 */
export var TextWidthHelper = /*#__PURE__*/function (_React$Component) {
  function TextWidthHelper() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.element = null;
    _this.elementRef = function (node) {
      return _this.element = node;
    };
    return _this;
  }
  _inheritsLoose(TextWidthHelper, _React$Component);
  var _proto = TextWidthHelper.prototype;
  _proto.getSizeClassName = function getSizeClassName(size) {
    switch (size) {
      case 'large':
        return styles.helperContainerLarge(this.props.theme);
      case 'medium':
        return styles.helperContainerMedium(this.props.theme);
      case 'small':
      default:
        return styles.helperContainerSmall(this.props.theme);
    }
  };
  _proto.render = function render() {
    return /*#__PURE__*/React.createElement(TokenView, {
      size: this.props.size,
      className: cx(styles.helperContainer(), this.getSizeClassName(this.props.size))
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.helperText(),
      ref: this.elementRef
    }, this.props.text || THIN_SPACE));
  };
  _proto.getTextWidth = function getTextWidth() {
    return getDOMRect(this.element).width;
  };
  _proto.getTextHeight = function getTextHeight() {
    return getDOMRect(this.element).height;
  };
  return TextWidthHelper;
}(React.Component);