'use client';
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __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 });
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = __importDefault(require("react"));
var stores_1 = require("../../hooks/stores");
var styles_1 = require("../../hooks/styles");
var styles_2 = __importStar(require("../../utils/styles"));
var Background = styles_2.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  position: fixed;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  background-color: ", ";\n  z-index: ", ";\n  opacity: ", ";\n  pointer-events: ", ";\n  transition: opacity ", ";\n  display: flex;\n  justify-content: center;\n  align-items: center;\n"], ["\n  position: fixed;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  background-color: ", ";\n  z-index: ", ";\n  opacity: ", ";\n  pointer-events: ", ";\n  transition: opacity ", ";\n  display: flex;\n  justify-content: center;\n  align-items: center;\n"])), styles_2.theme.color.extra.dimmed, styles_2.theme.zIndex.modal, function (_a) {
    var $isDisplay = _a.$isDisplay;
    return ($isDisplay ? 1 : 0);
}, function (_a) {
    var $isDisplay = _a.$isDisplay;
    return ($isDisplay ? 'auto' : 'none');
}, styles_2.theme.duration);
var Container = styles_2.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  flex-shrink: 0;\n"], ["\n  flex-shrink: 0;\n"])));
exports.default = react_1.default.memo(function () {
    var ref = react_1.default.useRef(null);
    var modals = (0, stores_1.useModalStore)().modals;
    var _a = modals.filter(function (_a) {
        var isOpen = _a.isOpen;
        return isOpen;
    }).pop() || {}, content = _a.content, onChangeIsOpen = _a.onChangeIsOpen;
    var isDisplayModal = !!content;
    (0, styles_1.useDisableScrollEffect)(isDisplayModal);
    var onClickBackground = react_1.default.useCallback(function () { return onChangeIsOpen === null || onChangeIsOpen === void 0 ? void 0 : onChangeIsOpen(false); }, [onChangeIsOpen]);
    var onClickModal = react_1.default.useCallback(function (event) { return event.stopPropagation(); }, []);
    return ((0, jsx_runtime_1.jsx)(Background, { "$isDisplay": isDisplayModal, onClick: onClickBackground, children: (0, jsx_runtime_1.jsx)(Container, { ref: ref, onClick: onClickModal, children: content }) }));
});
var templateObject_1, templateObject_2;
//# sourceMappingURL=ModalProvider.js.map