import { createApp, type App as VueApp } from 'vue'

import App from '../App.vue'
import '../assets/main.css'
import { createPinia } from 'pinia';
import { ConfigureLibOutput, type LibOutputConfig } from './libOutputConfig';
import { useEvent } from '../stores/eventStore';

let app: VueApp<Element> = undefined;

/**
 * 挂载材质编辑器到指定元素
*  @param element 要挂载的HTML元素
 * @param options 程序配置
 */
export function Mount(element: Element, options: Partial<LibOutputConfig>) {
    ConfigureLibOutput(options);

    const pinia = createPinia();
    app = createApp(App);
    app.use(pinia)
        .mount(element);
}

/** 对程序配置进行更改 */
export function Configure(options: Partial<LibOutputConfig>) {
    ConfigureLibOutput(options);
}

/** 卸载已经挂载的DOM */
export function Unmount() {
    app.unmount();
}

/** 手动进行材质提交 */
export function Submit() {
    useEvent().Publish('submit');
}

/** 更新材质贴图 */
export function UpdateTexture() {
    useEvent().Publish('update-texture');
}