import '@core/scss/index.scss'
import { Messager } from '../../core/src/component/msgDistribute'
import { editorRootContainer } from './const/htmlElementId'
import { fetch } from '../../core/src/component/httpClient'
import INTERFACE from './const/INTERFACE'
import layout from './layout'
import LeftMenu from './leftMenu'
import RightMenu from './rightMenu'
import TopMenu from './topMenu'
import MiddlePreview from './middlePreview'
import Toolbar from './toolbar'
window.page_data = window.page_data || {}
window.page_data.clientType = 'M'
document.domain = "jd.com";
Messager.on('editToolMountIdReady', (data) => {
	const iframeUrl = data?.iframeUrl
	const layouParts = ['left', 'right', 'top', 'bottom', 'middle', 'toolbar']
	const rootEl = document.getElementById(editorRootContainer)
	rootEl.innerHTML = layout
	const rootMap = layouParts.reduce((acc, cur) => {
		acc[cur] = rootEl.querySelector('.editor-layout-' + cur)
		return acc
	}, {})
	new TopMenu(rootMap.top)
	const leftMenu = new LeftMenu(rootMap.left)
	new RightMenu(rootMap.right)
	new MiddlePreview(rootMap.middle, iframeUrl)
	new Toolbar(rootMap.toolbar)
	Messager.on('updateModuleList', (data) => {
		fetch({url: INTERFACE.moduleList}).then((data)=>{
			if(data && data.code == 200 && data.data){
			  leftMenu.setModuleList(data.data)
			}
		  }).catch(e=>{
			console.log(e)
			return null
		  })
	})
})