'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),React=require("react"),core=require("@gem-sdk/core"),reactDom=require("react-dom"),useModalContainer=require("../hooks/useModalContainer.js"),ChildrenDroppable=require("../../grid/components/ChildrenDroppable.js");const Modal=({setting:e,styles:t,children:i,willUnmount:a,closeOnEscape:s,onKeypressEscape:r,keyCodeForClose:l,closeOnClickOutside:n,onClose:p,contentClass:c,disableIframeClickEvent:o})=>{let{open:d}=e??{},g=useModalContainer.default(),u=React.useRef(null),m=React.useRef(null),x=React.useCallback(e=>{let t=e.code,i="Escape"===t;l?.includes(t),s&&i&&r?.(e)},[s,l,r]);React.useEffect(()=>(document.addEventListener("keydown",x,!1),()=>{document.removeEventListener("keydown",x,!1),a?.()}),[x,a]);let h=React.useCallback(e=>{let t=e.target===u.current,i=e.target===m.current;(n&&t||i)&&(window?.parent?.postMessage?.(JSON.stringify({type:"active-modal",value:!1}),"*"),p?.())},[n,p]);return(React.useEffect(()=>{window?.parent?.postMessage?.(JSON.stringify({type:"active-modal",value:d}),"*")},[d]),g&&d)?reactDom.createPortal(jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("div",{className:"gp-fixed gp-inset-0 gp-z-50 gp-overflow-y-auto","data-disable-iframe-click-event":o||!1,children:jsxRuntime.jsxs("div",{className:"gp-min-h-screen gp-px-4 gp-text-center",children:[jsxRuntime.jsx("div",{ref:u,className:core.cls("gp-fixed gp-inset-0 gp-bg-black/60 gp-backdrop-blur-sm gp-transition-all gp-duration-100",{"gp-opacity-100":d,"gp-opacity-0":!d}),onClick:h,"aria-hidden":!0}),jsxRuntime.jsx("span",{className:"gp-inline-block gp-h-screen gp-align-middle"}),jsxRuntime.jsxs("div",{className:core.cls("gp-relative gp-my-8 gp-inline-block gp-w-full gp-overflow-hidden gp-rounded gp-bg-white gp-p-6 gp-text-left gp-align-middle gp-shadow-xl gp-transition-all gp-duration-100",{"gp-max-w-2xl":!t?.width,"gp-scale-100 gp-opacity-100":d,"gp-scale-0 gp-opacity-0":!d},c),style:{width:t?.width},children:[jsxRuntime.jsx("div",{className:"gp-absolute gp-right-[16px] gp-top-[16px] gp-z-10 gp-cursor-pointer",onClick:h,"aria-hidden":"true",children:jsxRuntime.jsx("svg",{ref:m,width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M11.1758 12.0241C11.4101 12.2584 11.79 12.2584 12.0243 12.0241C12.2586 11.7898 12.2586 11.4099 12.0243 11.1755L8.84858 7.9998L12.0243 4.82407C12.2586 4.58975 12.2586 4.20986 12.0243 3.97554C11.79 3.74123 11.4101 3.74123 11.1758 3.97554L8.00005 7.15128L4.82431 3.97554C4.59 3.74123 4.2101 3.74123 3.97578 3.97554C3.74147 4.20986 3.74147 4.58975 3.97578 4.82407L7.15152 7.9998L3.97579 11.1755C3.74147 11.4099 3.74147 11.7898 3.97579 12.0241C4.2101 12.2584 4.59 12.2584 4.82431 12.0241L8.00005 8.84833L11.1758 12.0241Z",fill:"#676767"})})}),jsxRuntime.jsx("div",{children:core.isEmptyChildren(i)?jsxRuntime.jsx(ChildrenDroppable.default,{}):i})]})]})})}),g):null};exports.default=Modal;
