/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

'use strict';

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

var tslib = require('tslib');
var React = require('react');
var ReactDOM = require('react-dom');
var amisCore = require('amis-core');

function _interopNamespace(e) {
    if (e && e.__esModule) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n["default"] = e;
    return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var AutoSizer = /** @class */ (function (_super) {
    tslib.__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 = ReactDOM.findDOMNode(this);
        this.unSensor = amisCore.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 (_J$X_(WrapperCmpt, { style: tslib.__assign({ display: 'block', position: 'relative', width: '100%', height: '100%' }, (minHeight ? { minHeight: minHeight } : {})) }, children({
            width: width,
            height: height
        })));
    };
    return AutoSizer;
}(React__namespace.PureComponent));

exports["default"] = AutoSizer;
