"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleModalSize = void 0;
exports.default = SimpleModal;
const contexts_1 = require("../../../contexts/index.js");
const hooks_1 = require("../../../hooks/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const Fade_1 = __importDefault(require("../../../animations/Fade"));
const Portal_1 = require("../Portal/Portal");
const Text_1 = __importDefault(require("../Text"));
const Color_1 = require("../../../util/Color");
const ScreenSize_1 = __importDefault(require("../../../util/ScreenSize"));
const Icon_1 = __importStar(require("../Icon/Icon"));
const SimpleModal_module_scss_1 = __importDefault(require("./SimpleModal.module.scss"));
var SimpleModalSize;
(function (SimpleModalSize) {
    SimpleModalSize["ExtraSmall"] = "--extra-small";
    SimpleModalSize["Small"] = "--small";
    SimpleModalSize["Normal"] = "--normal";
    SimpleModalSize["Large"] = "--large";
})(SimpleModalSize || (exports.SimpleModalSize = SimpleModalSize = {}));
function SimpleModal(props) {
    var _a;
    const context = (0, react_1.useContext)(contexts_1.BookingEngineContext);
    const [modalId, setModalId] = (0, react_1.useState)(null);
    const modalBody = (0, react_1.useRef)(null);
    const overlayRef = (0, react_1.useRef)(null);
    const { onBodyClickExcept } = (0, hooks_1.useBodyClick)();
    (0, react_1.useEffect)(() => {
        if (!(modalBody === null || modalBody === void 0 ? void 0 : modalBody.current)) {
            return;
        }
        const { remove } = onBodyClickExcept(() => {
            close();
        }, modalBody.current, overlayRef.current);
        return () => {
            remove();
        };
    }, [props.open, modalBody, props.onClose]);
    (0, react_1.useEffect)(() => {
        setModalId(Math.random());
    }, []);
    const close = () => {
        if (props.onClose) {
            props.onClose();
        }
    };
    const classes = (0, classnames_1.default)(SimpleModal_module_scss_1.default['roomstay-modal'], props.bodyClassName, {
        [SimpleModal_module_scss_1.default['--centered']]: props.alignCenter,
        [SimpleModal_module_scss_1.default['--overflow-visible']]: props.overflowVisible,
        [SimpleModal_module_scss_1.default[`${props.size}`]]: !!props.size,
    });
    return props.open ? ( // TODO: Need an actual isVisible state value instead of relying on the prop since we can't animate out.
    react_1.default.createElement(Portal_1.RoomstayPortal, { target: (_a = props.modalTarget) !== null && _a !== void 0 ? _a : document.body },
        react_1.default.createElement("div", { className: (0, classnames_1.default)(SimpleModal_module_scss_1.default['roomstay-overlay'], props.className), ref: overlayRef },
            react_1.default.createElement(Fade_1.default, { open: props.open },
                react_1.default.createElement("div", { ref: modalBody, className: classes, style: props.title ? {} : { paddingTop: 0 } },
                    props.title ? (react_1.default.createElement("div", { className: SimpleModal_module_scss_1.default['roomstay-modal--title'] },
                        react_1.default.createElement(Text_1.default, { color: Color_1.Color.White },
                            react_1.default.createElement("strong", null, props.title)),
                        react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Close, color: Color_1.Color.White, size: "24px", onClick: close }))) : (react_1.default.createElement("div", { className: `room-gallery-slider__icon-lightbox${props.size === SimpleModalSize.ExtraSmall ? '' : '-map'}` },
                        react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Close, size: "24px", onClick: close }))),
                    react_1.default.createElement("div", { className: "simple-modal--content" },
                        props.children,
                        props.desktopFooter &&
                            context.screenSize > ScreenSize_1.default.Medium && // TODO: refactor this to be variable
                            props.desktopFooter),
                    props.mobileFooter && context.screenSize <= ScreenSize_1.default.Medium && (react_1.default.createElement("div", { className: SimpleModal_module_scss_1.default['roomstay-modal--footer'] }, props.mobileFooter // TODO: refactor this to be variable
                    ))))))) : (react_1.default.createElement(react_1.default.Fragment, null));
}
//# sourceMappingURL=SimpleModal.js.map