import { createApp } from 'vue';
import App from './App.vue';
import { createPinia } from 'pinia';
import router from './router';
import { directive } from '@/utils/directive';
import { i18n } from '@/i18n/index';
import other from '@/utils/other';
import { addDateRange, parseTime, handleTree, selectDictLabel, download } from '@/utils';
import { getDicts } from '@/api/system/dict/data';
import { dateStrFormat } from '@/utils/formatTime';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import '@/theme/index.scss';
import mitt from 'mitt';
import 'element-plus/theme-chalk/dark/css-vars.css'
import 'element-plus/dist/index.css'



// @ts-ignore

import { install } from '@icon-park/vue-next/es/all';
import '@icon-park/vue-next/styles/index.css';
import './style/index.scss';
import contextmenu from 'vue3-contextmenu';
import 'vue3-contextmenu/dist/vue3-contextmenu.css';
import { registerIcon } from './utils/elIcon';
// import 'virtual:svg-icons-register';
// import xForm from '@/xForm/pc/index.es.js';
// import imageBox from '@/views/develop/page/components/imageBox/imageBox.vue';

// 天地图API配置
declare global {
  interface Window {
    T: any;
  }
}

// 动态加载天地图API
const loadTiandituAPI = () => {
  return new Promise((resolve, reject) => {
    if (window.T) {
      resolve(window.T);
      return;
    }
    
    const script = document.createElement('script');
    script.type = 'text/javascript';
    // 请替换为您的天地图API密钥
	  script.src = 'https://api.tianditu.gov.cn/api?v=4.0&tk=15b72cbf46b07ee54b6e0ef159aa2329';
    script.onload = () => resolve(window.T);
    script.onerror = reject;
    document.head.appendChild(script);
  });
};

// 初始化天地图API
loadTiandituAPI().catch(console.error);

const app = createApp(App);
// @ts-ignore
window.WApp = app;
const pinia = createPinia();

install(app, 'byte');

directive(app);
other.elSvg(app);
app.use(contextmenu);
// app.use(xForm);
// app.use(xForm.formCreate);

app.use(ElementPlus).use(i18n).use(pinia).use(router).mount('#app');
//app.use(ElementPlus).use(i18n).use(router).mount('#app');
registerIcon(app);
// 全局方法挂载
app.config.globalProperties.getDicts = getDicts;
app.config.globalProperties.mittBus = mitt();
app.config.globalProperties.addDateRange = addDateRange;
app.config.globalProperties.parseTime = parseTime;
app.config.globalProperties.handleTree = handleTree;
app.config.globalProperties.selectDictLabel = selectDictLabel;
app.config.globalProperties.download = download;
app.config.globalProperties.dateStrFormat = dateStrFormat;

