// loadingService.js
import { createApp } from 'vue';
import CrmLoading from '../components/CrmLoading';

let loadingInstance = null;

const LoadingService = {
  show(text) {
    if (!loadingInstance) {
      const app = createApp(CrmLoading, {
        isLoading: true,
        text: text
      });
      loadingInstance = app.mount(document.createElement('div'));
      document.body.appendChild(loadingInstance.$el);
    }
  },
  hide() {
    if (loadingInstance) {
      document.body.removeChild(loadingInstance.$el);
      loadingInstance = null;
    }
  }
};

export default LoadingService;