import { createApp } from 'vue';
import Confirm from '@/components/modals/Confirm.vue';
import { ResolveReject } from './types';
export default {
  show() {
    const mountEl = document.createElement('div');
    document.body.appendChild(mountEl);

    const cleanUp = () => {
      mountEl?.parentNode?.removeChild(mountEl);
      modal.unmount();
    };
    let _resolve: ResolveReject, _reject: ResolveReject;

    const promise = new Promise((resolve, reject) => {
      _resolve = resolve;
      _reject = reject;
    });

    const modal = createApp(Confirm, {
      title: 'Löschen bestätigen',
      message: 'Wollen Sie die Markierung wirklich löschen?',
      onConfirm: () => {
        cleanUp();
        _resolve();
      },
      onCancel: () => {
        cleanUp();
        _reject();
      },
    });

    modal.mount(mountEl);

    return promise;
  },
};
