"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dialog = exports.DialogBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const modal_1 = require("../modal");
const utils_1 = require("../utils");
const consts_1 = require("./consts");
const context_1 = require("./context");
const dialogBody_1 = __importDefault(require("./dialogBody"));
const dialogCancelButton_1 = __importDefault(require("./dialogCancelButton"));
const dialogCloseButton_1 = __importDefault(require("./dialogCloseButton"));
const dialogFooter_1 = __importDefault(require("./dialogFooter"));
const dialogHeader_1 = __importDefault(require("./dialogHeader"));
const dialogIcon_1 = __importDefault(require("./dialogIcon"));
const dialogSubmitButton_1 = __importDefault(require("./dialogSubmitButton"));
const dialogTitle_1 = __importDefault(require("./dialogTitle"));
exports.DialogBase = core_1.styled.divBox `
  background-color: white;
  border-radius: 1px;
  box-shadow: modal;
  display: flex;
  flex-direction: column;
  width: 100%;
`;
/**
 * Displays content in a Modal window. Includes required accessibility configuration.
 *
 * Dialog is built upon `Modal`.
 *
 * The content can include important information, like warnings or errors, simple forms or prompts for user's decision. It blocks interaction with the rest of the page, but often can be disabled by pressing Escape, clicking on the backdrop or close button.
 */
exports.Dialog = (0, core_1.vui)((props, ref) => {
    const { body: bodyProp, cancelButton, children, className, closeButton, disableBackdropClose, footer, header, icon, id, isOpen, modalProps: modalPropsProp, placement = 'center', onClose, size, status, submitButton, title, variant } = props, rest = __rest(props, ["body", "cancelButton", "children", "className", "closeButton", "disableBackdropClose", "footer", "header", "icon", "id", "isOpen", "modalProps", "placement", "onClose", "size", "status", "submitButton", "title", "variant"]);
    const styles = (0, core_1.useStyleConfig)('Dialog', props);
    const idRef = (0, react_1.useRef)(id !== null && id !== void 0 ? id : (0, utils_1.random)().toString());
    const [dialogId, bodyId, titleId] = (0, utils_1.useIds)(idRef.current, ['dialog', 'dialog-body', 'dialog-title']);
    const body = (0, utils_1.isReactText)(bodyProp) ? { children: bodyProp } : bodyProp;
    const showHeader = Boolean(header || closeButton || icon || title);
    const showFooter = Boolean(footer || cancelButton || submitButton);
    const ariaProps = {
        'aria-describedby': bodyId,
        'aria-labelledby': titleId,
    };
    const modalProps = Object.assign({ animation: consts_1.modalAnimation[placement], contentProps: Object.assign({ alignItems: placement === 'center' ? 'center' : 'auto', justifyContent: consts_1.modalJustifyContent[placement] }, modalPropsProp === null || modalPropsProp === void 0 ? void 0 : modalPropsProp.contentProps) }, modalPropsProp);
    const context = { bodyId, icon, isOpen, onClose, size, status, titleId, variant };
    return ((0, jsx_runtime_1.jsx)(context_1.DialogProvider, { value: context, children: (0, jsx_runtime_1.jsx)(modal_1.Modal, Object.assign({ isOpen, onClose }, modalProps, { disableBackdropClose, children: (0, jsx_runtime_1.jsx)(exports.DialogBase, Object.assign({ className: (0, utils_1.cs)('vui-dialog', className), id: dialogId, maxH: placement === 'center' ? 'calc(100vh - 32px)' : '100%', ref: ref, role: "dialog" }, ariaProps, styles.container, rest, { children: children !== null && children !== void 0 ? children : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, utils_1.isJsx)(header) ? header : showHeader && (0, jsx_runtime_1.jsx)(dialogHeader_1.default, Object.assign({ closeButton, icon, title }, header)), (0, utils_1.isJsx)(body) ? body : body && (0, jsx_runtime_1.jsx)(dialogBody_1.default, Object.assign({}, body)), (0, utils_1.isJsx)(footer) ? footer : showFooter && (0, jsx_runtime_1.jsx)(dialogFooter_1.default, Object.assign({ cancelButton, submitButton }, footer))] })) })) })) }));
});
exports.Dialog.Body = dialogBody_1.default;
exports.Dialog.CancelButton = dialogCancelButton_1.default;
exports.Dialog.CloseButton = dialogCloseButton_1.default;
exports.Dialog.Footer = dialogFooter_1.default;
exports.Dialog.Header = dialogHeader_1.default;
exports.Dialog.Icon = dialogIcon_1.default;
exports.Dialog.SubmitButton = dialogSubmitButton_1.default;
exports.Dialog.Title = dialogTitle_1.default;
exports.Dialog.displayName = 'Dialog';
exports.default = exports.Dialog;
//# sourceMappingURL=dialog.js.map