/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

import { __extends, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { anyChanged, autobind, themeable, localeable } from 'amis-core';
import Button from './Button.js';

var MultilineText = /** @class */ (function (_super) {
    __extends(MultilineText, _super);
    function MultilineText(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            isExpend: false,
            showBtn: false
        };
        _this.ref = React__default.createRef();
        return _this;
    }
    MultilineText.prototype.componentDidMount = function () {
        if (this.ref && this.ref.current) {
            if (this.ref.current.scrollHeight > this.ref.current.clientHeight) {
                this.setState({
                    showBtn: true
                });
            }
        }
    };
    MultilineText.prototype.shouldComponentUpdate = function (nextProps, nextState, nextContext) {
        if (anyChanged([
            'text',
            'maxRows',
            'expendButtonText',
            'collapseButtonText',
            'className'
        ], this.props, nextProps) ||
            anyChanged(['isExpend', 'showBtn'], this.state, nextState)) {
            return true;
        }
        return false;
    };
    MultilineText.prototype.componentDidUpdate = function (oldProps, oldState) {
        var _a = this.props, text = _a.text, maxRows = _a.maxRows;
        if (text !== oldProps.text || maxRows !== oldProps.maxRows) {
            if (this.ref && this.ref.current) {
                this.setState({
                    showBtn: this.ref.current.scrollHeight > this.ref.current.clientHeight
                });
            }
        }
    };
    MultilineText.prototype.toggleExpend = function () {
        this.setState({
            isExpend: !this.state.isExpend
        });
    };
    MultilineText.prototype.render = function () {
        var _a = this.props, className = _a.className, style = _a.style, text = _a.text, cx = _a.classnames, _b = _a.maxRows, maxRows = _b === void 0 ? 5 : _b, expendButtonText = _a.expendButtonText, collapseButtonText = _a.collapseButtonText;
        if (!text) {
            return null;
        }
        var _c = this.state, showBtn = _c.showBtn, isExpend = _c.isExpend;
        return (React__default.createElement("div", { className: cx('MultilineText', className), style: style },
            React__default.createElement("div", { ref: this.ref, className: cx('MultilineText-counter'), style: {
                    height: "".concat(maxRows * 20, "px")
                } }, text),
            React__default.createElement("div", { className: cx('MultilineText-display'), style: {
                    height: showBtn && !isExpend ? "".concat(maxRows * 20, "px") : 'auto'
                } }, text),
            showBtn && (React__default.createElement("div", { className: cx('MultilineText-button-wrapper') },
                React__default.createElement(Button, { className: cx('MultilineText-button'), level: "link", onClick: this.toggleExpend }, !isExpend ? expendButtonText : collapseButtonText)))));
    };
    MultilineText.defaultProps = {
        maxRows: 5,
        expendButtonText: '展开',
        collapseButtonText: '收起'
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], MultilineText.prototype, "toggleExpend", null);
    return MultilineText;
}(React__default.Component));
var MultilineText$1 = themeable(localeable(MultilineText));

export { MultilineText, MultilineText$1 as default };
