import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{Et as t,c as n,xt as r}from"./vendor-vue-core-D3IvUUeM.js";import{U as i}from"./vendor-other-CrvBxfcV.js";const a=n(`dialog`,()=>{let e=t([]),n=t(null),genDialogKey=()=>`dialog-${Math.random().toString(36).slice(2,9)}`;function insertDialogByPriority(t){let n=e.value.findIndex(e=>e.priority<=t.priority);e.value.splice(n===-1?e.value.length:n,0,t)}function riseDialog(t){let r=t.key,i=e.value.findIndex(e=>e.key===r);if(i!==-1){let[t]=e.value.splice(i,1);insertDialogByPriority(t),n.value=r,updateCloseOnEscapeStates()}}function closeDialog(t){let r=t?e.value.find(e=>e.key===t.key):e.value.find(e=>e.key===n.value);if(!r)return;r.dialogComponentProps?.onClose?.();let i=e.value.indexOf(r);e.value.splice(i,1),n.value=e.value.length>0?e.value[e.value.length-1].key:null,updateCloseOnEscapeStates()}function createDialog(t){e.value.length>=10&&e.value.shift();let a={key:t.key,visible:!0,title:t.title,headerComponent:t.headerComponent?r(t.headerComponent):void 0,footerComponent:t.footerComponent?r(t.footerComponent):void 0,component:r(t.component),headerProps:{...t.headerProps},contentProps:{...t.props},footerProps:{...t.footerProps},priority:t.priority??1,dialogComponentProps:{maximizable:!1,modal:!0,closable:!0,closeOnEscape:!0,dismissableMask:!0,...t.dialogComponentProps,maximized:!1,onMaximize:()=>{a.dialogComponentProps.maximized=!0},onUnmaximize:()=>{a.dialogComponentProps.maximized=!1},onAfterHide:()=>{closeDialog(a)},pt:i(t.dialogComponentProps?.pt||{},{root:{onMousedown:()=>{riseDialog(a)}}})}};return insertDialogByPriority(a),n.value=t.key,updateCloseOnEscapeStates(),a}function updateCloseOnEscapeStates(){let t=e.value.find(e=>e.key===n.value),r=t?.dialogComponentProps.closable;e.value.forEach(e=>{e.dialogComponentProps={...e.dialogComponentProps,closeOnEscape:e===t&&!!r}})}function showDialog(t){let n=t.key||genDialogKey(),r=e.value.find(e=>e.key===n);return r?(r.visible=!0,riseDialog(r)):r=createDialog({...t,key:n}),r}function showExtensionDialog(t){let{key:n}=t;if(!n){console.error(`Extension dialog key is required`);return}let r=n.startsWith(`extension-`)?n:`extension-${n}`,i=e.value.find(e=>e.key===r);return i?(i.visible=!0,riseDialog(i),i):createDialog({...t,key:r})}function isDialogOpen(t){return e.value.some(e=>e.key===t)}return{dialogStack:e,riseDialog,showDialog,closeDialog,showExtensionDialog,isDialogOpen,activeKey:n}});export{a as t};
//# sourceMappingURL=dialogStore-BbHfkjRE.js.map