import App from './App'
import uvUI from '@/uni_modules/uv-ui-tools'
import {
	Request
} from '@/util/request/index'
import $mUtil from '@/util/index.js';
import config from '@/config/global.config.js'
import throttle from '@/uni_modules/uv-ui-tools/libs/function/throttle.js';
import initialize from "@/util/initialize.ts";
import { handleImageUrl } from "@/util/index.js"
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false;
App.mpType = 'app'
try {
	function isPromise(obj) {
		return (!!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function");
	}
	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) {}
const app = new Vue({
	...App
})
// #ifndef VUE3
Vue.use(uvUI);
Vue.use(initialize)
// #endif
// #ifdef VUE3
app.use(uvUI);
// #endif
app.$mount()
// 引入请求封装
Request(app)
// #endif
// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	// 注册全局工具函数
	app.config.globalProperties.$mUtil = $mUtil;
	app.config.globalProperties.$mConfig = config;
	app.config.globalProperties.$throttle = throttle;
	app.config.globalProperties.$defaultAvatar = config.staticUrl + '/czd/default-avatar.jpg';
	app.config.globalProperties.$handleImageUrl = handleImageUrl;
	app.use(initialize)
	// 引入请求封装
	Request(app)
	return {
		app
	}
}
// #endif