import { Ref, ref } from "vue"; export enum NotificationSize { sm = "sm", md = "md", lg = "lg", } export type NotificationOptions = { size?: NotificationSize | string; }; export type NotificationProps = { [param: string]: any; }; export interface INotification { component: any; options?: NotificationOptions; props?: NotificationProps; } export class NotificationService { private notification: Ref = ref(null); private resolve!: (value: any | PromiseLike) => void; public open(modal: INotification): Promise { this.notification = ref(modal); return new Promise((resolve) => { this.resolve = resolve; }); } public getNotification(): INotification { return this.notification as unknown as INotification; } public close(result: any): void { if (this.resolve) { this.resolve(result); } this.notification = ref(null); } } export class NotificationGod { constructor(private service: NotificationService) {} public open( notificationService: NotificationService | undefined | null, component: any, props?: NotificationProps, options?: NotificationOptions ): Promise { if (!this.service) { return Promise.reject(); } return this.service.open({ component, props, options, }); } }