import App from './App'

import { createSSRApp } from 'vue'

import { setupStore } from '@/store'
import { setupLocales } from '@/locales'
import { setupRouterInterceptor } from '@/module/router/interceptor.js'

import { setupAdjust } from '@/module/third/adjust.js'
import { setupOpeninstall } from '@/module/third/openinstall'
import { setupFbSdk } from '@/module/third/fbsdk'
import { setupErrorHandler } from '@/module/utils/errorHandler'
import { setupOkSpin } from '@/module/third/okspin.js'

import CommonLayout from '@/components/layout/CommonLayout.vue'
import MobileHeader from '@/components/header/MobileHeader.vue'
import MobileLayout from '@/components/layout/MobileLayout'
import MobileSubLayout from '@/components/layout/MobileSubLayout'
import ThemeImage from '@/components/image/ThemeImage'
import CustomTabBar from '@/components/custom-tab-bar/CustomTabBar.vue'
import EmptyHold from './components/emptyHold/EmptyHold.vue'
import MobileCustomLayout from './components/layout/MobileCustomLayout.vue'
import MobileSubHeader from './components/header/MobileSubHeader.vue'

import { formatKMB, formatThousandDot, formatFloat } from '@/module/formatter/data-formatter.js'
// import fbPixiel from './plugins/fb-pixiel'

export function createApp() {
  const app = createSSRApp(App)
	
	setupErrorHandler(app)
	
	setupStore(app)
	setupLocales(app)
	setupRouterInterceptor()
	
	// setupAdjust()
	setupOpeninstall()
	// setupFbSdk(app)
	setupOkSpin()
	// app.use(fbPixiel)
	
	app.component("common-layout", CommonLayout)
	app.component('mobile-header', MobileHeader)
	app.component('mobile-layout', MobileLayout)
	app.component('mobile-sub-layout', MobileSubLayout)
	app.component('mobile-custom-layout', MobileCustomLayout)
	app.component('theme-image', ThemeImage)
	app.component('custom-tabbar', CustomTabBar)
	app.component('empty-hold', EmptyHold)
	app.component('mobile-sub-header', MobileSubHeader)
	
	app.config.globalProperties.$formatKMB = formatKMB
	app.config.globalProperties.$formatThousandDot = formatThousandDot
	app.config.globalProperties.$formatFloat = formatFloat
	app.config.errorHandler = (err, instance, info) => {
		console.log('error', err, instance, info)
	}
  return {
    app
  }
}
