import { __assign } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import cx from 'classnames';
import LoadingMask from './components/LoadingMask';
import useDelayed from './hooks/useDelayed';
import { hasOwnProperty } from '../utils/hasOwn';
export function BlockLoading(props) {
    var height = getHeight(props);
    var _a = props.loading, loading = _a === void 0 ? false : _a, _b = props.delay, delay = _b === void 0 ? 0 : _b, className = props.className, children = props.children, _c = props.icon, icon = _c === void 0 ? 'circle' : _c, iconSize = props.iconSize, iconText = props.iconText, _d = props.textPosition, textPosition = _d === void 0 ? 'bottom' : _d, _e = props.colorPreset, colorPreset = _e === void 0 ? 'primary' : _e;
    var hasChildren = !!children;
    var delayed = useDelayed({ loading: loading, delay: delay });
    var showMask = !delayed && loading;
    if (!showMask && !hasChildren) {
        return null;
    }
    return (_jsxs("div", __assign({ className: cx('zent-loading', 'zent-loading--block', className, {
            'zent-loading--has-children': hasChildren,
        }), style: { height: height }, "data-zv": 'v10.0.12' }, { children: [children, showMask && (_jsx(LoadingMask, { icon: icon, size: iconSize, text: iconText, textPosition: textPosition, colorPreset: colorPreset }, void 0))] }), void 0));
}
function getHeight(props) {
    var hasHeightProp = hasOwnProperty(props, 'height');
    var children = props.children;
    if (!children && !hasHeightProp) {
        return 160;
    }
    if (children && !hasHeightProp) {
        return 'initial';
    }
    return props.height;
}
export default BlockLoading;
