var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import React from 'react';
import { getDOMRect } from '../../lib/dom/getDOMRect.js';
import { TokenView } from '../Token/TokenView.js';
import { getStyles } from '../Token/Token.styles.js';
import { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';
// a thin character to preserve some space
// for the caret visibillity in the input
var THIN_SPACE = '\u2009';
/**
 * Херпер позволяет вычислить размеры блока с текстом
 * для последующего выставления размеров input
 */
var TextWidthHelper = /** @class */ (function (_super) {
    __extends(TextWidthHelper, _super);
    function TextWidthHelper() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.element = null;
        _this.elementRef = function (node) {
            _this.element = node;
        };
        return _this;
    }
    TextWidthHelper.prototype.getSizeClassName = function (size) {
        switch (size) {
            case 'large':
                return this.styles.helperContainerLarge(this.props.theme);
            case 'medium':
                return this.styles.helperContainerMedium(this.props.theme);
            case 'small':
            default:
                return this.styles.helperContainerSmall(this.props.theme);
        }
    };
    TextWidthHelper.prototype.render = function () {
        this.styles = getStyles(this.emotion);
        return (React.createElement(TokenView, { size: this.props.size, className: this.cx(this.styles.helperContainer(), this.getSizeClassName(this.props.size)) },
            React.createElement("div", { className: this.styles.helperText(), ref: this.elementRef }, this.props.text || THIN_SPACE)));
    };
    TextWidthHelper.prototype.getTextWidth = function () {
        return getDOMRect(this.element).width;
    };
    TextWidthHelper.prototype.getTextHeight = function () {
        return getDOMRect(this.element).height;
    };
    TextWidthHelper = __decorate([
        withRenderEnvironment
    ], TextWidthHelper);
    return TextWidthHelper;
}(React.Component));
export { TextWidthHelper };
//# sourceMappingURL=TextWidthHelper.js.map