import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";

import store from "./storex";

import {
  // create naive ui
  create,
  // component
  NButton,
  NTabPane,
  NTabs,
  NInput,
  NEmpty,
  NImage,
} from "naive-ui";

// n-tab-pane
const naive = create({
  components: [NButton, NTabs, NTabPane, NInput, NEmpty, NImage],
});

import qs from "query-string";
const parseSearch: any = qs.parse(location.search);
const hashSearch = qs.parse(location.hash.split("?")[1]);
const Authorization: string = parseSearch.Authorization || hashSearch.Authorization || "";
// 授权
sessionStorage.setItem("Authorization", Authorization);
/**
 * 平台
 * classroom 课堂乐器
 * orchestra 管乐团
 */
sessionStorage.setItem("platform", parseSearch.platform || hashSearch.platform || "");

import { TUIComponents, TUICore, genTestUserSig } from "./TUIKit";
// import TUICallKit
// import { TUICallKit } from "@tencentcloud/call-uikit-vue";

console.log(import.meta.env.DEV, "import.meta.env.DEV");

// 判断是否是测试环境的
const SDKAppID = parseSearch.appId || hashSearch.appId || 1400799837; // import.meta.env.DEV ? 1400805079 : 1400799837; // 1400805079; // Your SDKAppID
const secretKey = parseSearch.secretKey || hashSearch.secretKey || "37bfb220843e25e78768cadd0dc06756e460e55bd631354930a4149565a1d0c9"; //import.meta.env.DEV ? "c5f4ea6140128a36c842990446a2c89249ab886b5e1ea6893555aa635a0b3c30" : "37bfb220843e25e78768cadd0dc06756e460e55bd631354930a4149565a1d0c9"; //"c5f4ea6140128a36c842990446a2c89249ab886b5e1ea6893555aa635a0b3c30"; // Your secretKey
const userID = parseSearch.userID; //|| "KT:140:TEACHER"; // User ID

// init TUIKit
const TUIKit = TUICore.init({
  SDKAppID,
});
// TUIKit add TUIComponents
TUIKit.use(TUIComponents);
// TUIKit add TUICallKit
// TUIKit.use(TUICallKit);

// login TUIKit
TUIKit.login({
  userID: userID,
  userSig: genTestUserSig({
    SDKAppID,
    secretKey,
    userID,
  }).userSig, // The password with which the user logs in to IM. It is the ciphertext generated by encrypting information such as userID.For the detailed generation method, see Generating UserSig
});

createApp(App).use(naive).use(store).use(TUIKit).mount("#app");

export { SDKAppID, secretKey, userID };
