"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DialogBody = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const box_1 = require("../box");
const core_1 = require("../core");
const utils_1 = require("../utils");
const context_1 = require("./context");
/**
 * Shows the main content between the Dialog Header and Footer.
 * It becomes scrollable when content does not fit vertically. Borders are shown automatically.
 * Receives more horizontal padding when Dialog has icon, so align text with title.
 * Receives id linked to aria-describedby on the Dialog for accessibility.
 */
exports.DialogBody = (0, core_1.vui)((props, ref) => {
    var _a;
    const { className } = props, rest = __rest(props, ["className"]);
    const { bodyId, icon, status } = (_a = (0, context_1.useDialogContext)()) !== null && _a !== void 0 ? _a : {};
    const styles = (0, core_1.useStyleConfig)('Dialog', (0, context_1.useDialogContext)());
    const [isScrolled, setIsScrolled] = (0, react_1.useState)(false);
    const bodyRef = (0, react_1.useRef)(null);
    // Observe size changes of the body to detect if it becomes vertically scrollable
    const observerRef = (0, react_1.useRef)(new ResizeObserver(() => {
        if (bodyRef.current) {
            const { clientHeight, scrollHeight } = bodyRef.current;
            setIsScrolled(scrollHeight > clientHeight);
        }
    }));
    (0, react_1.useEffect)(() => {
        var _a;
        bodyRef.current && ((_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.observe(bodyRef.current));
    }, []);
    // If body can be scrolled vertically, add dividing lines on top and bottom
    const borderProps = isScrolled ? { borderColor: 'grey.30' } : {};
    // Add more body padding when custom or status icon is displayed
    const paddingProps = (icon !== null && icon !== void 0 ? icon : status) !== undefined ? { px: 8 } : { px: 3 };
    return ((0, jsx_runtime_1.jsx)(box_1.Box, Object.assign({ borderBottom: "1px solid transparent", borderTop: "1px solid transparent", className: (0, utils_1.cs)('vui-dialogBody', className), column: true, id: bodyId, overflowY: "auto", pb: 2, pt: 1.5, ref: (0, utils_1.mergeRefs)(ref, bodyRef) }, borderProps, paddingProps, styles.body, rest)));
});
exports.DialogBody.displayName = 'DialogBody';
exports.default = exports.DialogBody;
//# sourceMappingURL=dialogBody.js.map