'use client';
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{useRef as n,useCallback as t,useEffect as o}from"react";import{cls as p}from"@gem-sdk/core";import{ELEMENT_Z_INDEX as i}from"../../common/const.js";import{addBodyClass as r,getOrCreateRootDialog as a,removeBodyClass as g,removeElementReconfirm as s}from"../common/helpers.js";import{render as c}from"react-dom";let d=({title:r,content:a,willUnmount:c,closeOnEscape:d,onKeypressEscape:m,keyCodeForClose:u,closeOnClickOutside:f,onClickOutside:x,buttons:h,dialogId:C,overlayClassName:b,className:k})=>{let v=n(null),w=t(()=>{g(),s(C)},[C]),y=t(e=>{let l=e.code;u?.includes(l)&&w(),d&&"Escape"===l&&(m?.(e),w())},[w,d,u,m]);o(()=>(document.addEventListener("keydown",y,!1),()=>{document.removeEventListener("keydown",y,!1),c?.()}),[y,c]);let N=e=>{e.onClick&&e.onClick(),w()};return e("div",{className:"gp-fixed gp-inset-0 gp-z-100 gp-overflow-y-auto",style:{zIndex:i.CART_DRAWER_CONFIRM_MODAL},children:l("div",{className:"gp-min-h-screen gp-px-4 gp-text-center",children:[e("div",{ref:v,className:p("gp-fixed gp-inset-0 gp-bg-black/60 gp-backdrop-blur-sm",b),onClick:e=>{let l=e.target===v.current;f&&l&&(x?.(),w())},"aria-hidden":!0}),e("span",{className:"gp-inline-block gp-h-screen gp-align-middle"}),l("div",{className:p("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",k),children:[r,a,e("div",{className:"gp-flex gp-justify-center gp-gap-4 gp-pt-6",children:h?.map((l,n)=>e("button",{onClick:()=>N(l),className:p("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",l.className),children:l.label},n))})]})]})})};function m(l){r(),function(l){let n=a(l.dialogId);c(e(d,{...l}),n)}({...l,dialogId:`dialog-${Math.floor(1e5*Math.random())}`})}d.defaultProps={buttons:[{label:"Cancel",onClick:()=>null},{label:"Confirm",onClick:()=>null}],closeOnClickOutside:!0,closeOnEscape:!0,keyCodeForClose:[],willUnmount:()=>null,afterClose:()=>null,onClickOutside:()=>null,onKeypressEscape:()=>null};export{m as openConfirm};
