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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var Button = require('./Button.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var MultilineText = /** @class */ (function (_super) {
    tslib.__extends(MultilineText, _super);
    function MultilineText(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            isExpend: false,
            showBtn: false
        };
        _this.ref = React__default["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 (amisCore.anyChanged([
            'text',
            'maxRows',
            'expendButtonText',
            'collapseButtonText',
            'className'
        ], this.props, nextProps) ||
            amisCore.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 (_J$X_("div", { className: cx('MultilineText', className), style: style },
            _J$X_("div", { ref: this.ref, className: cx('MultilineText-counter'), style: {
                    height: "".concat(maxRows * 20, "px")
                } }, text),
            _J$X_("div", { className: cx('MultilineText-display'), style: {
                    height: showBtn && !isExpend ? "".concat(maxRows * 20, "px") : 'auto'
                } }, text),
            showBtn && (_J$X_("div", { className: cx('MultilineText-button-wrapper') },
                _J$X_(Button["default"], { className: cx('MultilineText-button'), level: "link", onClick: this.toggleExpend }, !isExpend ? expendButtonText : collapseButtonText)))));
    };
    MultilineText.defaultProps = {
        maxRows: 5,
        expendButtonText: '展开',
        collapseButtonText: '收起'
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], MultilineText.prototype, "toggleExpend", null);
    return MultilineText;
}(React__default["default"].Component));
var MultilineText$1 = amisCore.themeable(amisCore.localeable(MultilineText));

exports.MultilineText = MultilineText;
exports["default"] = MultilineText$1;
