'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),React=require("react"),core=require("@gem-sdk/core"),_const=require("../../common/const.js"),helpers=require("../common/helpers.js"),reactDom=require("react-dom");function createElementReconfirm(e){let l=helpers.getOrCreateRootDialog(e.dialogId);reactDom.render(jsxRuntime.jsx(Dialog,{...e}),l)}const Dialog=({title:e,content:l,willUnmount:n,closeOnEscape:t,onKeypressEscape:s,keyCodeForClose:o,closeOnClickOutside:r,onClickOutside:i,buttons:a,dialogId:c,overlayClassName:p,className:g})=>{let d=React.useRef(null),m=React.useCallback(()=>{helpers.removeBodyClass(),helpers.removeElementReconfirm(c)},[c]),u=React.useCallback(e=>{let l=e.code,n="Escape"===l;o?.includes(l)&&m(),t&&n&&(s?.(e),m())},[m,t,o,s]);React.useEffect(()=>(document.addEventListener("keydown",u,!1),()=>{document.removeEventListener("keydown",u,!1),n?.()}),[u,n]);let x=e=>{e.onClick&&e.onClick(),m()},f=e=>{let l=e.target===d.current;r&&l&&(i?.(),m())};return jsxRuntime.jsx("div",{className:"gp-fixed gp-inset-0 gp-z-100 gp-overflow-y-auto",style:{zIndex:_const.ELEMENT_Z_INDEX.CART_DRAWER_CONFIRM_MODAL},children:jsxRuntime.jsxs("div",{className:"gp-min-h-screen gp-px-4 gp-text-center",children:[jsxRuntime.jsx("div",{ref:d,className:core.cls("gp-fixed gp-inset-0 gp-bg-black/60 gp-backdrop-blur-sm",p),onClick:f,"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-flex gp-min-w-[320px] gp-flex-col gp-overflow-hidden gp-bg-white gp-p-6 gp-text-left gp-align-middle gp-shadow-xl gp-transition-all",g),children:[e,l,jsxRuntime.jsx("div",{className:"gp-flex gp-justify-center gp-gap-4 gp-pt-6",children:a?.map((e,l)=>jsxRuntime.jsx("button",{onClick:()=>x(e),className:core.cls("gp-inline-flex gp-select-none gp-items-center gp-justify-center gp-rounded-md gp-border gp-border-transparent gp-bg-slate-400 gp-py-2 gp-px-5 gp-text-base gp-font-medium gp-text-white gp-shadow-sm gp-transition-all gp-duration-300 gp-ease-in-out",e.className),children:e.label},l))})]})]})})};function openConfirm(e){helpers.addBodyClass(),createElementReconfirm({...e,dialogId:`dialog-${Math.floor(1e5*Math.random())}`})}Dialog.defaultProps={buttons:[{label:"Cancel",onClick:()=>null},{label:"Confirm",onClick:()=>null}],closeOnClickOutside:!0,closeOnEscape:!0,keyCodeForClose:[],willUnmount:()=>null,afterClose:()=>null,onClickOutside:()=>null,onKeypressEscape:()=>null},exports.default=Dialog,exports.openConfirm=openConfirm;
