import App from "./index.vue";
import "@/assets/js/common";
import { createApp } from "vue";
import { getPageParameters, environment } from "../../config/pageConfig";
import {
  isIpad,
  isIpod,
  isIphone,
  isWindows,
  isMac,
  isWechat,
} from "../../utils/isTerminal";
// 判断环境
environment();
window.$originData = getPageParameters();
document.title = window.$originData.orginParames.title || "";

const getUser = () => {
  window.$shanshipin = {};
  // 判断闪视频登录状态
  if (isWindows || isMac || isWechat) return createApp(App).mount("#app");
  // 获取登录信息
  if (isIpad || isIpod || isIphone) {
    if (!window.webkit || !window.webkit.messageHandlers)
      return createApp(App).mount("#app");
    window.setUser = user => {
      if (user == "{}")
        return window.webkit.messageHandlers.iosJumpLogin.postMessage([]);
      const u1 = JSON.parse(user || "{}");
      window.webkit.messageHandlers.getAppInfo.postMessage([]);
      window.setAppInfo = userJson => {
        const u2 = JSON.parse(userJson || "{}");
        window.$shanshipin = {
          ...u1,
          ...u2,
        };
        createApp(App).mount("#app");
      };
    };

    window.webkit.messageHandlers.tideGetUser.postMessage([]);
  } else {
    if (!window.TideApp) return createApp(App).mount("#app");
    const u1 = JSON.parse(window.TideApp.getUser() || "{}");
    console.log("u1", u1);
    if (!u1.UserId) window.TideApp.login();
    const u2 = JSON.parse(window.TideApp.getAppInfo() || "{}");
    console.log("u2", u2);
    window.$shanshipin = {
      ...u1,
      ...u2,
    };
    createApp(App).mount("#app");
  }
};
getUser();

window.setUserSession = () => {
  console.log("登录");
  getUser();
};

// 分享
window.weixin_Share_Init(
  "战马音浪 · 校园歌手大赛",
  "线上连麦PK报名通道已开通，火热报名中...",
  "https://cxzx.smcic.net/topic/highSpeed/img/logo3.png"
);

var SL = new window.SmcicLogger("shanshipin", "c6124d95");
SL.Util.SetUrl("https://collect.smcic.net:8443/");
SL.Systematic.Init({
  appid: "c6124d95",
  channel: "shanshipin",
  model: "",
  os: "",
  os_version: "",
  carrier: "",
  network_type: "",
  ip: "",
  app_name: "",
  app_version: "",
  build_version: "",
  platform_type: "",
});
SL.Content.CommodityDetail({
  commodity_detail_source: "活动",
  commodity_id: "",
  commodity_name: document.title,
  publisher_name: "",
  publisher_id: "",
  review_count: 0,
  comment_count: 0,
  collect_count: 0,
  share_count: 0,
  like_count: 0,
  tag: [],
});
