var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { forwardRef } from 'react';
import { useAsyncMount } from '../../hooks/useAsyncMount';
export var withAsyncMount = function (Component, PlaceholderComponent) {
    if (PlaceholderComponent === void 0) { PlaceholderComponent = null; }
    var WithAsyncMount = forwardRef(function (componentProps, ref) {
        var shouldMount = useAsyncMount();
        return shouldMount ? (React.createElement(Component, __assign({}, componentProps, { ref: ref }))) : (PlaceholderComponent && React.createElement(PlaceholderComponent, __assign({}, componentProps, { ref: ref })));
    });
    WithAsyncMount.displayName = 'WithAsyncMount';
    return WithAsyncMount;
};
