/*
 * @Date: 2025-11-03 10:52:09
 * @LastEditors: shirlwang
 * @LastEditTime: 2025-11-04 11:14:21
 */
import App from '@/App'
import * as Pinia from 'pinia'
import globalFunction from '@/common/globalFunction'
import '@/lib/string-similarity.min.js'
import similarityJobs from '@/utils/similarity_Job.js';
import config from '@/config.js';
import shareMixin from './mixins/share.js';
// 组件
import AppLayout from './components/AppLayout/AppLayout.vue';
import Empty from './components/empty/empty.vue';
import NoBouncePage from '@/components/NoBouncePage/NoBouncePage.vue'
import MsgTips from '@/components/MsgTips/MsgTips.vue'
import SelectPopupPlugin from '@/components/selectPopup/selectPopupPlugin';
import storeRc from './utilsRc/store/index.js'
import {processFileUrl,} from '@/utilsRc/common.js'
// iconfont.css 已在 App.vue 中通过 @import 引入，无需在此处重复引入
// import Tabbar from '@/components/tabbar/midell-box.vue'
// 自动导入 directives 目录下所有指令
const directives = import.meta.glob('./directives/*.js', {
    eager: true
});

import {
    createSSRApp,
} from 'vue'

// const foldFeature = window.visualViewport && 'segments' in window.visualViewport
// console.log('是否支持多段屏幕：', foldFeature)

import { getDict } from '@/apiRc/system/dict.js';
// 全局组件
export function createApp() {
    const app = createSSRApp(App)

    // 注册全局分享混入
    app.mixin(shareMixin)

    app.component('AppLayout', AppLayout)
    app.component('Empty', Empty)
    app.component('NoBouncePage', NoBouncePage)
    app.component('MsgTips', MsgTips)


    app.config.globalProperties.$processFileUrl = processFileUrl;
    app.config.globalProperties.$getDict = getDict;
    app.config.globalProperties.$store = storeRc;
    app.config.globalProperties.$getDictSelectOption = async (dictType, isDigital = false, forceRefresh = false) => {
        const dictData = await getDict(dictType, forceRefresh);
        return dictData.map(item => ({
            value: isDigital ? Number(item.dictValue || item.dictvalue) : (item.dictValue || item.dictvalue),
            label: item.dictLabel || item.dictlabel,
            ...item
        }));
    };
    // app.component('tabbar-custom', Tabbar)

    for (const path in directives) {
        const directiveModule = directives[path];
        // 文件名作为指令名，./directives/fade.js => v-fade
        const name = path.match(/\.\/directives\/(.*)\.js$/)[1];
        app.directive(name, directiveModule.default);
    }

    app.provide('globalFunction', {
        ...globalFunction,
        similarityJobs,
        config
    });
    app.provide('deviceInfo', globalFunction.getdeviceInfo());

    app.use(SelectPopupPlugin);
    app.use(Pinia.createPinia());
    // 注册vuex
    app.use(storeRc);

    return {
        app,
        Pinia
    }
}
