import {
    createVNode,
    render
} from "vue"

import Loading from './src/loading.vue';
// import Loading2 from './src/loading2.vue';
import Loading3 from './src/loading3.vue';
import Loading4 from './src/loading4.vue';


class Vsload {
    constructor(el) {
        this.el = el
    }
    clear() {
        document.body.removeChild(this.el)
    }
}

let uuid = 0;

export default function VSloading(options = {}) {
    let div = document.createElement("div");
    div.className = `vs-loading-zindex-${uuid}`;
    uuid++;

    let instance = null;
    switch (options.type) {
        case 0:
            instance = createVNode(Loading, options);
            break
        case 1:
            // instance = createVNode(Loading2, options);
            break
        case 2:
            instance = createVNode(Loading3, options);
            break
        case 3:
            instance = createVNode(Loading4, options);
            break
        default:
            instance = createVNode(Loading, options);
    }

    instance.appContext = app._context
    const body = document.body;

    body.appendChild(div);
    render(instance, div);

    const vsload = new Vsload(div)
    return vsload
}