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

import { __extends, __assign } from 'tslib';
import * as React from 'react';
import { findDOMNode } from 'react-dom';
import { resizeSensor } from 'amis-core';

var AutoSizer = /** @class */ (function (_super) {
    __extends(AutoSizer, _super);
    function AutoSizer(props) {
        var _this = _super.call(this, props) || this;
        _this.state = { width: 0, height: 0 };
        return _this;
    }
    AutoSizer.prototype.componentDidMount = function () {
        var _this = this;
        var dom = findDOMNode(this);
        this.unSensor = resizeSensor(dom, function () { return _this.sizer(dom); });
        this.sizer(dom);
    };
    AutoSizer.prototype.componentWillUnmount = function () {
        this.unSensor && this.unSensor();
    };
    AutoSizer.prototype.sizer = function (dom) {
        var _a, _b;
        var width = dom.offsetWidth;
        var height = dom.offsetHeight;
        (_b = (_a = this.props) === null || _a === void 0 ? void 0 : _a.onResize) === null || _b === void 0 ? void 0 : _b.call(_a, { width: width, height: height });
        this.setState({
            width: width,
            height: height
        });
    };
    AutoSizer.prototype.render = function () {
        var _a = this.props, children = _a.children, WrapperComponent = _a.WrapperComponent, minHeight = _a.minHeight;
        var _b = this.state, width = _b.width, height = _b.height;
        var WrapperCmpt = WrapperComponent !== null && WrapperComponent !== void 0 ? WrapperComponent : 'div';
        return (React.createElement(WrapperCmpt, { style: __assign({ display: 'block', position: 'relative', width: '100%', height: '100%' }, (minHeight ? { minHeight: minHeight } : {})) }, children({
            width: width,
            height: height
        })));
    };
    return AutoSizer;
}(React.PureComponent));

export { AutoSizer as default };
