import Vue from "vue";
import Preview from "./index.vue";

const PreviewConstructor = Vue.extend(Preview);

const preview = options => {
    const { path, type, title, isLocal = false } = options;
    if (!path) throw `path is requred.but ${path}`
    const id = `Preview_${new Date().getTime()}`;
    const instance = new PreviewConstructor();
    instance.id = id;
    instance.vm = instance.$mount();
    if (instance.vm.visible) return;
    document.body.appendChild(instance.vm.$el);
    instance.vm.open(path, type, title, isLocal);
    instance.vm.$on("closed", () => {
        document.body.removeChild(instance.vm.$el);
        instance.vm.$destroy();
    });
    return instance.vm;
}
export default preview;