import App from '@/App'
import * as Pinia from 'pinia'
import {
    createUnistorage
} from "./uni_modules/pinia-plugin-unistorage";
import globalFunction from '@/common/globalFunction'
import '@/lib/string-similarity.min.js'
import similarityJobs from '@/utils/similarity_Job.js';
import useScreenStore from './stores/useScreenStore'

// 组件
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 SelectPopup from '@/components/selectPopup/selectPopup.vue'
import SelectPopupPlugin from '@/components/selectPopup/selectPopupPlugin';
import RenderJobs from '@/components/renderJobs/renderJobs.vue';
import RenderCompanys from '@/components/renderCompanys/renderCompanys.vue';
import RenderJobsOutData from '@/components/renderJobsOutData/renderJobsOutData.vue';
import RenderCompanysOutData from '@/components/renderCompanysOutData/renderCompanysOutData.vue';
import renderDeliveryRecord from '@/components/renderDeliveryRecord/renderDeliveryRecord.vue';
import renderJobCollectionRecord from '@/components/renderJobCollectionRecord/renderJobCollectionRecord.vue';
import renderCompanyCollectionRecord from '@/components/renderCompanyCollectionRecord/renderCompanyCollectionRecord.vue';
import renderJobViewRecord from '@/components/renderJobViewRecord/renderJobViewRecord.vue';
import MyIcons from '@/components/My-icons/my-icons.vue';
// import Tabbar from '@/components/tabbar/midell-box.vue'
// 自动导入 directives 目录下所有指令
console.log(lightAppJssdk)
const directives = import.meta.glob('./directives/*.js', {
    eager: true
});

import {
    createSSRApp,
} from 'vue'



// 全局组件
export function createApp() {
    const app = createSSRApp(App)

    app.component('AppLayout', AppLayout)
    app.component('Empty', Empty)
    app.component('NoBouncePage', NoBouncePage)
    app.component('MsgTips', MsgTips)
    app.component('SelectPopup', SelectPopup)
    app.component('RenderJobs', RenderJobs)
    app.component('RenderCompanys', RenderCompanys)
    app.component('RenderJobsOutData', RenderJobsOutData) //渲染外部岗位数据列表
    app.component('RenderCompanysOutData', RenderCompanysOutData) //渲染外部公司数据列表
    app.component('renderDeliveryRecord', renderDeliveryRecord) //渲染岗位投递记录
    app.component('renderJobCollectionRecord', renderJobCollectionRecord) //渲染岗位收藏记录
    app.component('renderCompanyCollectionRecord', renderCompanyCollectionRecord) //渲染公司收藏记录
    app.component('renderJobViewRecord', renderJobViewRecord) //渲染岗位浏览记录
    app.component('MyIcons', MyIcons) 
    // 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
    });
    app.provide('deviceInfo', globalFunction.getdeviceInfo());

    app.use(SelectPopupPlugin);

    const store = Pinia.createPinia();
    store.use(createUnistorage());
    app.use(store);

    // 初始化屏幕检测
    const screenStore = useScreenStore()
    screenStore.initScreenDetection()
    return {
        app,
        Pinia
    }
}