import {
	createSSRApp
} from 'vue'
import App from './App'
import store from './store'
import uviewPlus from 'uview-plus'

/* #ifdef H5 */
import httpInterceptor from '@/servers/http.interceptor.js'
/* #endif */

/** nvue 内置标签，在 Vue3 + H5 中需声明为自定义元素，否则会按组件解析报错 */
const NVUE_NATIVE_TAGS = new Set(['list', 'cell', 'refresh'])

export function createApp() {
	const app = createSSRApp(App)
	const prevIsCustom = app.config.compilerOptions && app.config.compilerOptions.isCustomElement
	app.config.compilerOptions = {
		...app.config.compilerOptions,
		isCustomElement: (tag) => {
			if (NVUE_NATIVE_TAGS.has(tag)) return true
			return typeof prevIsCustom === 'function' ? prevIsCustom(tag) : false
		}
	}
	app.use(store)
	app.use(uviewPlus)
	/* #ifdef H5 */
	app.use(httpInterceptor)
	/* #endif */
	return {
		app
	}
}
