// main.js
import {createSSRApp} from 'vue'
import App from './App'
import {install} from './plugins' // 自定义插件
import './permission' // 路由权限
import {useDict} from '@/utils/dict'
// import { createPinia } from 'pinia'
import * as Pinia from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

export function createApp() {
    const app = createSSRApp(App)
    // const pinia = createPinia()
    const pinia = Pinia.createPinia()
    // ✅ 安全注册持久化插件
    if (piniaPluginPersistedstate) {
        pinia.use(piniaPluginPersistedstate)
    } else {
        console.warn('pinia-plugin-persistedstate not found, persistence may not work')
    }

    app.use(pinia)
    // app.use(store) // 如果你还在用 Vuex，否则可删除

    // 挂载全局方法
    app.config.globalProperties.useDict = useDict

    // 安装其他插件
    install(app)

    return {
        app,
        Pinia
    }
}